Customer Token Payments

Following a successful customer tokenization process, the resulting card token can be used in place of card details in subsequent payment requests. Card tokens can be stored in merchant systems in place of the customer's original card information, eliminating the need for merchants to obtain PCI-DSS certification.

Customer token payments allow merchants to offer streamlined shopping experiences, as customers can make payments without entering their card information with every transaction.

šŸ“˜

API Method

Refer to: 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.

šŸ“˜

Payment Token API

Refer to: Payment Token API

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

2. Receive Payment Token Response

To receive a payment token response, refer to the sample payment token response below.

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"

3. Set Customer Token

String customerToken = "20052010380915759367";
NSString *customerToken = @"20052010380915759367";
let customerToken: String = "20052010380915759367"

4. Construct Credit Card Request

PaymentCode paymentCode = new PaymentCode("CC");
 
PaymentRequest paymentRequest = new CustomerTokenPaymentBuilder(paymentCode, customerToken)
                                .setSecurityCode("123")
                                .build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
      
PaymentRequest *paymentRequest = [[[[CustomerTokenPaymentBuilder alloc] initWithPaymentCode: paymentCode token: customerToken]
                                     securityCode: @"123"]
                                     build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
   
let paymentRequest: PaymentRequest = CustomerTokenPaymentBuilder(paymentCode: paymentCode, customerToken)
                                     .securityCode("123")
                                     .build()

šŸ“˜

Payment Request Parameters

Refer to: Payment Request API Parameters

šŸš§

Payment Channel

To see individual card tokenization options, refer to the following sections in the payment channel matrix:
ā€¢ Global Cards
ā€¢ Local Cards

5. Construct Transaction Request

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

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

6. Execute Payment Request

To receive a payment transaction request response, refer to the parameters below.

šŸ“˜

Payment Transaction Response API Parameters

Refer to: Do Payment Response API Parameters

šŸš§

References

Response Code
To view payment process flows based on response code, refer to: Payment Flow Response Codes

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: transactionResultRequest 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.
}];

šŸ‘

Callback for PGW Payment Authentication

Refer to: Handle PGW Payment Authentication

Full Sample Code

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

//Step 2: Generate payment token id.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
    
//Step 3: Set customer token
String customerToken = "20052010380915759367";
 
//Step 4: Construct credit card request.
PaymentCode paymentCode = new PaymentCode("CC");
 
PaymentRequest paymentRequest = new CustomerTokenPaymentBuilder(paymentCode, customerToken)
                                .setSecurityCode("123")
                                .build();
    
//Step 5: Construct transaction request.
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
                                                    .with(paymentRequest)
                                                    .build();
    
//Step 6: 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.
     }
});
//Step 2: Generate payment token id.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
   
//Step 3: Set customer token
NSString *customerToken = @"20052010380915759367";
     
//Step 4: Construct credit card request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
      
PaymentRequest *paymentRequest = [[[[CustomerTokenPaymentBuilder alloc] initWithPaymentCode: paymentCode token: customerToken]
                                     securityCode: @"123"]
                                     build];
   
//Step 5: Construct transaction request. 
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                         withPaymentRequest: paymentRequest]
                                                         build];
       
//Step 6: Execute payment request.
[[PGWSDK shared] proceedTransactionWithTransactionResultRequest: transactionResultRequest 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.
}];
//Step 2: Generate payment token id.
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
     
//Step 3: Set customer token
let customerToken: String = "20052010380915759367"
  
//Step 4: Construct credit card request.
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
   
let paymentRequest: PaymentRequest = CustomerTokenPaymentBuilder(paymentCode: paymentCode, customerToken)
                                     .securityCode("123")
                                     .build()
           
//Step 5: Construct transaction request.
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                         .with(paymentRequest)
                                                         .build()
           
//Step 6: 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.
}