Web Payment Card (WPC)

The 2C2P PGW SDK allows merchants to accept payments from Web Payment Card.

πŸ“˜

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": "JT08",
    "invoiceNo": "1595219400",
    "description": "2 days 1 night hotel room",
    "amount": 1000.0,
    "currencyCode": "VND",
    "nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
    "paymentChannel": ["WEBPAY"]
}

Β 

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"

Β 

3. Prepare Payment Request

To prepare an payment request, refer to the sample code below.

πŸ“˜

Payment Request Parameters

Refer to Payment Request API Parameters

🚧

Payment Channel Matrix

Refer to the payment channel codes, agent codes, & agent Channel code from Payment Channel List .

PaymentCode paymentCode = new PaymentCode("123", "VNABB", "WEBPAY");
 
PaymentRequest paymentRequest = new WebPaymentBuilder(paymentCode)
                                .setCardNo("9704160000000018")
                                .setExpiryMonth(12)
                                .setExpiryYear(2025)
                                .setIssuedMonth(1)
                                .setIssuedYear(2023)
                                .setSecurityCode("123")
                                .setName("DavidBilly")
                                .setEmail("[email protected]")
                                .setMobileNo("08888888")
                                .build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"123" agentCode: @"VNABB" agentChannelCode: @"WEBPAY"];
     
PaymentRequest *paymentRequest = [[[[[[[[[[[[WebPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                             cardNo: @"9704160000000018"]
                                             expiryMonth: 12]
                                             expiryYear: 2025]
                                             issuedMonth: 1]
                                             issuedYear: 2023]
                                             securityCode: @"123"]
                                             name: @"DavidBilly"]
                                             email: @"[email protected]"]
                                             mobileNo: @"08888888"]
                                             build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "123", "VNABB", "WEBPAY")
 
let paymentRequest: PaymentRequest = WebPaymentBuilder(paymentCode: paymentCode)
                                     .cardNo("9704160000000018")
                                     .expiryMonth(12)
                                     .expiryYear(2025)
                                     .issuedMonth(1)
                                     .issuedYear(2023)
                                     .securityCode("123")
                                     .name("DavidBilly")
                                     .email("[email protected]")
                                     .mobileNo("08888888")
                                     .build()

Β 

4. Prepare Transaction Request

To prepare a transaction request, refer to the parameters and sample code below.

πŸ“˜

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()

Β 

5. Receive Transaction Request Response

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

πŸ“˜

Transaction Response API Parameter

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

Β 

6. Initiate Payment Inquiry

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

πŸ“˜

Payment Inquiry API

Refer to: Payment Inquiry API

Β 

Full Sample Code

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

//Step 1: Generate payment token id.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
  
//Step 2: Construct web payment card request.
PaymentCode paymentCode = new PaymentCode("123", "VNABB", "WEBPAY");
 
PaymentRequest paymentRequest = new WebPaymentBuilder(paymentCode)
                                .setCardNo("9704160000000018")
                                .setExpiryMonth(12)
                                .setExpiryYear(2025)
                                .setIssuedMonth(1)
                                .setIssuedYear(2023)
                                .setSecurityCode("123")
                                .setName("DavidBilly")
                                .setEmail("[email protected]")
                                .setMobileNo("08888888")
                                .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.
     }
});
//Step 1: Generate payment token id.
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct web payment card request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"123" agentCode: @"VNABB" agentChannelCode: @"WEBPAY"];
     
PaymentRequest *paymentRequest = [[[[[[[[[[[[WebPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                             cardNo: @"9704160000000018"]
                                             expiryMonth: 12]
                                             expiryYear: 2025]
                                             issuedMonth: 1]
                                             issuedYear: 2023]
                                             securityCode: @"123"]
                                             name: @"DavidBilly"]
                                             email: @"[email protected]"]
                                             mobileNo: @"08888888"]
                                             build];
 
//Step 3: Construct transaction request.   
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
                                                         withPaymentRequest: paymentRequest]
                                                         build];
     
//Step 4: 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: Construct web payment card request.
let paymentCode: PaymentCode = PaymentCode(channelCode: "123", "VNABB", "WEBPAY")
 
let paymentRequest: PaymentRequest = WebPaymentBuilder(paymentCode: paymentCode)
                                     .cardNo("9704160000000018")
                                     .expiryMonth(12)
                                     .expiryYear(2025)
                                     .issuedMonth(1)
                                     .issuedYear(2023)
                                     .securityCode("123")
                                     .name("DavidBilly")
                                     .email("[email protected]")
                                     .mobileNo("08888888")
                                     .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.
}