These docs are for v4.0.2. Click to read the latest docs for v4.3.0.

Card Tokenization

Tokenization or stored card feature is a method to replace sensitive data such as credit card details with non-sensitive data. Whenever the card is stored, 2C2P will return the card token to merchant.

With 2C2P's Tokenization feature, merchants do not need to undertake a complex and time-consuming PCI-DSS certification process. All the sensitive information is protected at 2C2P with the most advanced security that is compliant with PCI-DSS standards.

 

📘

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.

📘

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"
}

 

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. Enable Tokenization

To enable tokenization, refer to the sample code below.

boolean cardTokenization = true; //Enable or Disable Tokenization
Boolean cardTokenization = true;  //Enable or Disable Tokenization
let cardTokenization: Bool = true //Enable or Disable Tokenization

 

4. Prepare Tokenization Request

To prepare a tokenization request, refer to the parameters below.

📘

Payment Request Parameter

Refer to: Payment Request API Parameter

🚧

Payment Channels

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

PaymentCode paymentCode = new PaymentCode("CC");
 
PaymentRequest paymentRequest = new CardPaymentBuilder(paymentCode, "4111111111111111")
                                .setExpiryMonth(12)
                                .setExpiryYear(2020)
                                .setSecurityCode("123")
                                .setTokenize(cardTokenization)
                                .build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
  
PaymentRequest *paymentRequest = [[[[[[[CardPaymentBuilder alloc] initWithPaymentCode: paymentCode cardNo: @"4111111111111111"]
                                        expiryMonth: 12]
                                        expiryYear: 2020]
                                        securityCode: @"123"]
                                        tokenize: cardTokenization]
                                        build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
  
let paymentRequest: PaymentRequest = CardPaymentBuilder(paymentCode: paymentCode, "4111111111111111")
                                     .expiryMonth(12)
                                     .expiryYear(2020)
                                     .securityCode("123")
                                     .tokenize(cardTokenization)
                                     .build()

 

5. Prepare Payment Transaction Request

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

📘

Payment Transaction Request API Parameters

Refer to: Do Payment Request API Parameters

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. Receive Payment Transaction Request Response

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

 

7. Initiate Payment Inquiry

To retrieve payment details and card tokens, merchants must initiate the Payment Inquiry API. Refer to the sample code below.

📘

Payment Inquiry API

Refer to: Payment Inquiry API

//Step 1: Generate payment token id.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
   
//Step 2: Enable Tokenization.
boolean cardTokenization = true; //Enable or Disable Tokenization
 
//Step 3: Construct credit card request.
PaymentCode paymentCode = new PaymentCode("CC");
 
PaymentRequest paymentRequest = new CardPaymentBuilder(paymentCode, "4111111111111111")
                                .setExpiryMonth(12)
                                .setExpiryYear(2020)
                                .setSecurityCode("123")
                                .setTokenize(cardTokenization)
                                .build();
   
//Step 4: Construct transaction request.
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
                                                    .with(paymentRequest)
                                                    .build();
   
//Step 5: 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 1: Generate payment token id.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
  
//Step 2: Enable Tokenization.
Boolean cardTokenization = true;  //Enable or Disable Tokenization
 
//Step 3: Construct credit card request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"CC"];
  
PaymentRequest *paymentRequest = [[[[[[[CardPaymentBuilder alloc] initWithPaymentCode: paymentCode cardNo: @"4111111111111111"]
                                        expiryMonth: 12]
                                        expiryYear: 2020]
                                        securityCode: @"123"]
                                        tokenize: cardTokenization]
                                        build];
  
//Step 4: Construct transaction request.  
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                         withPaymentRequest: paymentRequest]
                                                         build];
      
//Step 5: 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 1: Generate payment token id.
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
    
//Step 2: Enable Tokenization.
let cardTokenization: Bool = true //Enable or Disable Tokenization
 
//Step 3: Construct credit card request.
let paymentCode: PaymentCode = PaymentCode(channelCode: "CC")
  
let paymentRequest: PaymentRequest = CardPaymentBuilder(paymentCode: paymentCode, "4111111111111111")
                                     .expiryMonth(12)
                                     .expiryYear(2020)
                                     .securityCode("123")
                                     .tokenize(cardTokenization)
                                     .build()
          
//Step 4: Construct transaction request.
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
                                                         .with(paymentRequest)
                                                         .build()
          
//Step 5: 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.
}