Cancel Transaction

The Cancel Transaction API allows merchants to offer customers the option to cancel ongoing or pending transactions.

Refer to the links below for parameters and code samples for each step:

 

📘

API Method

PGW SDK API Interface

🚧

References

SDK Payment Classes
SDK Payment Enums

 

1. Generate Payment Token

To prepare a payment token request, refer to the required parameters below.

{
    "merchantID": "JT04",
    "invoiceNo": "1595219400",
    "description": "2 days 1 night hotel room",
    "amount": 10.0,
    "currencyCode": "THB",
    "nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
    "paymentChannel": ["ALL"]
}

 

2. Receive Payment Token Response

To receive a payment token response, refer to the sample payment token response below. The response will contain the payment token ID which must be passed to the merchant application.

String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';

📘

Payment Token API

Refer to: Payment Token API

 

3. Prepare Cancel Transaction Request

To prepare a cancel transaction request, refer to the parameters below.

📘

Request API Parameters

Refer to: Cancel Transaction Request API Parameters

CancelTransactionRequest cancelTransactionRequest = new CancelTransactionRequest(paymentToken);
CancelTransactionRequest *cancelTransactionRequest = [[CancelTransactionRequest alloc] initWithPaymentToken: paymentToken];
let cancelTransactionRequest: CancelTransactionRequest = CancelTransactionRequest(paymentToken: paymentToken)
Map<String, dynamic> cancelTransactionRequest = {
   'paymentToken': paymentToken
};

 

4. Retrieve Cancel Transaction Response

To retrieve a cancel transaction response, refer to the parameters below.

📘

Response API Parameters

Refer to: Cancel Transaction Response API Parameters

PGWSDK.getInstance().cancelTransaction(cancelTransactionRequest, new APIResponseCallback<CancelTransactionResponse>() {
 
     @Override
     public void onResponse(CancelTransactionResponse response) {
         if(response.getResponseCode().equals(APIResponseCode.APISuccess)) {
             //Read cancel transaction response. 
         } else {
             //Get error response and display error.
         }
     }
 
     @Override
     public void onFailure(Throwable error) {
         //Get error response and display error.
     }
});
[[PGWSDK shared] cancelTransactionWithCancelTransactionRequest: cancelTransactionRequest response: ^(CancelTransactionResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
          //Read cancel transaction response.
     } else { 
         //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) { 
     //Get error response and display error.
}];
PGWSDK.shared.cancelTransaction(cancelTransactionRequest: cancelTransactionRequest, { (response: CancelTransactionResponse) in
 
     if response.responseCode == APIResponseCode.APISuccess {
          //Read cancel transaction response.
     } else {
          //Get error response and display error.
     }
}) { (error: NSError) in 
     //Get error response and display error.
}
PGWSDK().cancelTransaction(cancelTransactionRequest, (response) {
 
   if (response['responseCode'] == APIResponseCode.apiSuccess) {
 
      //Read cancel transaction response.
   } else {
 
      //Get error response and display error.
   }
}, (error) {
 
   //Get error response and display error.
});

 

Full Sample Code

The following sample code demonstrates requests and parameters for each step of the process.

//Step 1 : Generate payment token
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct cancel transaction request.
CancelTransactionRequest cancelTransactionRequest = new CancelTransactionRequest(paymentToken);
 
//Step 3: Retrieve cancel transaction response.
PGWSDK.getInstance().cancelTransaction(cancelTransactionRequest, new APIResponseCallback<CancelTransactionResponse>() {
 
     @Override
     public void onResponse(CancelTransactionResponse response) {
         if(response.getResponseCode().equals(APIResponseCode.APISuccess)) {
             //Read cancel transaction response. 
         } else {
             //Get error response and display error.
         }
     }
 
     @Override
     public void onFailure(Throwable error) {
         //Get error response and display error.
     }
});
//Step 1 : Generate payment token
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct cancel transaction request.
CancelTransactionRequest *cancelTransactionRequest = [[CancelTransactionRequest alloc] initWithPaymentToken: paymentToken];
     
//Step 3: Retrieve cancel transaction response.
[[PGWSDK shared] cancelTransactionWithCancelTransactionRequest: cancelTransactionRequest response: ^(CancelTransactionResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
          //Read cancel transaction response.
     } else {
         //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) { 
     //Get error response and display error.
}];
//Step 1 : Generate payment token
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct cancel transaction request.
CancelTransactionRequest *cancelTransactionRequest = [[CancelTransactionRequest alloc] initWithPaymentToken: paymentToken];
     
//Step 3: Retrieve cancel transaction response.
[[PGWSDK shared] cancelTransactionWithCancelTransactionRequest: cancelTransactionRequest response: ^(CancelTransactionResponse * _Nonnull response) {
         
     if([response.responseCode isEqualToString: APIResponseCode.APISuccess]) {
          //Read cancel transaction response.
     } else {
         //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) { 
     //Get error response and display error.
}];
//Step 1 : Generate payment token
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
 
//Step 2: Construct cancel transaction request.
Map<String, dynamic> cancelTransactionRequest = {
   'paymentToken': paymentToken
};
 
//Step 3: Retrieve cancel transaction response.
PGWSDK().cancelTransaction(cancelTransactionRequest, (response) {
 
   if (response['responseCode'] == APIResponseCode.apiSuccess) {
 
      //Read cancel transaction response.
   } else {
 
      //Get error response and display error.
   }
}, (error) {
 
   //Get error response and display error.
});