Do Payment

The Do Payment API is for allow merchant app submit and execute the user selected payment to PGW backend. PGW backend will process these submit payment information.

Below are steps to retrieve payment options.

Step 1 : Generate Payment Token

Step 2 : Construct Payment Request

Step 3 : Construct Transaction Request

Step 4 : Execute Payment Request

Full Sample Code

Β 

πŸ“˜

API Method

PGW SDK API Interface

🚧

References

SDK Payment Classes
SDK Payment Enums

Β 

Step 1 :Generate Payment Token

Β 
1.1 Generate payment token ID.

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

Β 
1.2 Get payment token ID from response and pass it to merchant mobile 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"

πŸ“˜

Payment Token API

Please refer: Payment Token API

Β 

Step 2 : Construct Payment Request

Below code show how to construct payment request.

πŸ“˜

Request API Parameter

Please refer: Do Payment Request API Parameter

PaymentCode paymentCode = new PaymentCode(PaymentChannelCode.Group.CreditCard);
 
PaymentRequest paymentRequest = new UniversalPaymentBuilder(paymentCode)
                                .setCardNo("4111111111111111")
                                .setExpiryMonth(12)
                                .setExpiryYear(2020)
                                .setSecurityCode("123")
                                .build();
PaymentCode *paymentCode2 = [[PaymentCode alloc] initWithChannelCode: PaymentChannelCodeGroup.CreditCard];
 
PaymentRequest *paymentRequest3 = [[[[[[[UniversalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                         cardNo: @"card no"]
                                         expiryMonth: 12]
                                         expiryYear: 2020]
                                         securityCode: @"123"]
                                         build];
let paymentCode: PaymentCode = PaymentCode(channelCode: PaymentChannelCode.Group.CreditCard)
 
let paymentRequest: PaymentRequest = UniversalPaymentBuilder(paymentCode: paymentCode)
                                     .cardNo("4111111111111111")
                                     .expiryMonth(12)
                                     .expiryYear(2022)
                                     .securityCode("123")
                                     .build()

Β 

Step 3 : Construct Transaction Request

Below code show how to construct transaction request.

TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
                                                    .with(paymentRequest)
                                                    .build();
TransactionResultRequest * transactionResultRequest2 = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                           withPaymentRequest: paymentRequest2]
                                                           build];
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                         .with(paymentRequest)
                                                         .build()

Β 

Step 4 : Execute Payment Request

Below code show how to execute payment request and receive API response code.

πŸ“˜

Response API Parameter

Please refer: Do Payment Response API Parameter

🚧

Response Code

Please refer : Payment Flow Response Code for payment process flow by response code

PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
 
     @Override
     public void onResponse(TransactionResultResponse response) {
 
          if(response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
 
                String redirectUrl = response.getData(); //Open WebView
          } else if(response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
               //Inquiry payment result by using invoice no.
          } else {
               //Get error response and display error.
          }
     }
 
     @Override
     public void onFailure(Throwable error) { 
          //Get error response and display error.
     }
});
[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest2 response: ^(TransactionResultResponse * _Nonnull response) {
            
     if([response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateRedirect] || [response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateFullRedirect]) {
                
          NSString *redirectUrl = response.data; //Open WebView
     } else if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {    
          //Inquiry payment result by using invoice no.
     } else {      
          //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) {       
     //Get error response and display error.
}];
PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in
    
     if response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect {
                 
           guard let redirectUrl: String = response.data else { return } //Open WebView
     } else if response.responseCode == APIResponseCode.TransactionCompleted {        
           //Inquiry payment result by using invoice no.
     } else {              
           //Get error response and display error.
     }
}) { (error: NSError) in       
     //Get error response and display error.
}

Β 

Full Sample Code

Full Sample Code Show below.

String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct payment request.
PaymentCode paymentCode = new PaymentCode(PaymentChannelCode.Group.CreditCard);
 
PaymentRequest paymentRequest = new UniversalPaymentBuilder(paymentCode)
                                .setCardNo("4111111111111111")
                                .setExpiryMonth(12)
                                .setExpiryYear(2020)
                                .setSecurityCode("123")
                                .build();
 
//Step 3: Construct transaction request.
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
                                                    .with(paymentRequest)
                                                    .build();
 
//Step 4: Execute payment request.
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
 
     @Override
     public void onResponse(TransactionResultResponse response) {
 
          if(response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateRedirect) || response.getResponseCode().equals(APIResponseCode.TransactionAuthenticateFullRedirect)) {
 
                String redirectUrl = response.getData(); //Open WebView
          } else if(response.getResponseCode().equals(APIResponseCode.TransactionCompleted)) {
               //Inquiry payment result by using invoice no.
          } else {
               //Get error response and display error.
          }
     }
 
     @Override
     public void onFailure(Throwable error) {
          //Get error response and display error.
     }
});
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct payment request.
PaymentCode *paymentCode2 = [[PaymentCode alloc] initWithChannelCode: PaymentChannelCodeGroup.CreditCard];
 
PaymentRequest *paymentRequest3 = [[[[[[[UniversalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                         cardNo: @"card no"]
                                         expiryMonth: 12]
                                         expiryYear: 2020]
                                         securityCode: @"123"]
                                         build];
 
//Step 3: Construct transaction request.   
TransactionResultRequest * transactionResultRequest2 = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                           withPaymentRequest: paymentRequest2]
                                                           build];
     
//Step 4: Execute payment request.
[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest2 response: ^(TransactionResultResponse * _Nonnull response) {
            
     if([response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateRedirect] || [response.responseCode isEqualToString: APIResponseCode.TransactionAuthenticateFullRedirect]) {
                
          NSString *redirectUrl = response.data; //Open WebView
     } else if([response.responseCode isEqualToString: APIResponseCode.TransactionCompleted]) {     
          //Inquiry payment result by using invoice no.
     } else {  
          //Get error response and display error.
     }
} failure: ^(NSError * _Nonnull error) {  
     //Get error response and display error.
}];
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
    
//Step 2: Construct credit card request.
let paymentCode: PaymentCode = PaymentCode(channelCode: PaymentChannelCode.Group.CreditCard)
 
let paymentRequest: PaymentRequest = UniversalPaymentBuilder(paymentCode: paymentCode)
                                     .cardNo("4111111111111111")
                                     .expiryMonth(12)
                                     .expiryYear(2022)
                                     .securityCode("123")
                                     .build()
         
//Step 3: Construct transaction request.
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                         .with(paymentRequest)
                                                         .build()
         
//Step 4: Execute payment request.
PGWSDK.shared.proceedTransaction(transactionResultRequest: transactionResultRequest, { (response: TransactionResultResponse) in
    
     if response.responseCode == APIResponseCode.TransactionAuthenticateRedirect || response.responseCode == APIResponseCode.TransactionAuthenticateFullRedirect {
                 
           guard let redirectUrl: String = response.data else { return } //Open WebView
     } else if response.responseCode == APIResponseCode.TransactionCompleted {           
           //Inquiry payment result by using invoice no.
     } else {      
           //Get error response and display error.
     }
}) { (error: NSError) in   
     //Get error response and display error.
}