QR Payment

QR Payment is contactless payment that allow customer to scan and pay with their mobile app.

Mobile SDK allow customer to make a secure payment by using QR Payment in your mobile app.

 

Below are steps to integrate QR Payment.

Step 1 : Generate Payment Token

Step 2 : Construct Payment Request

Step 3 : Construct Transaction Request

Step 4 : Execute Payment Request

Step 5 : Initiate Transaction Status Inquiry

 

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.

📘

Payment Token API

Please refer: 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": ["QR"]
}

 
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"

 

Step 2 : Construct Payment Request

Below code show how to construct payment request.

📘

Payment Request Parameter

Please refer: QR Payment Request API Parameter

🚧

Payment Channel

QR Payment support a few of options.
Please refer Payment Channel Matrix to know the Channel for individual QR payment option.

PaymentCode paymentCode = new PaymentCode("VEMVQR");

PaymentRequest paymentRequest = new QRPaymentBuilder(paymentCode)
                                .setType(QRTypeCode.URL)
                                .setName("DavidBilly")
                                .setEmail("[email protected]")
                                .setMobileNo("08888888")
                                .build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"VEMVQR"];

PaymentRequest *paymentRequest = [[[[[[[QRPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                        type: QRTypeCode.URL]
                                        name: @"DavidBilly"]
                                        email: @"[email protected]"]
                                        mobileNo: @"08888888"]
                                        build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "VEMVQR")

let paymentRequest: PaymentRequest = QRPaymentBuilder(paymentCode: paymentCode)
                                     .type(QRTypeCode.URL)
                                     .name("DavidBilly")
                                     .email("[email protected]")
                                     .mobileNo("08888888")
                                     .build()

 

Step 3 : Construct Transaction Request

Below code show how to construct transaction request.

📘

Transaction Request API Parameter

Please refer: Do Payment Request API Parameter

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

 

Step 4 : Execute Payment Request

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

📘

Transaction Response API Parameter

Please refer: Do Payment Response API Parameter

🚧

References

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

QR Type Code
Please refer : QR Type Code Enums

PGWSDK.getInstance().proceedTransaction(transactionResultRequest, new APIResponseCallback<TransactionResultResponse>() {
 
     @Override
     public void onResponse(TransactionResultResponse response) {
 
          if(response.getResponseCode().equals(APIResponseCode.TransactionQRPayment)) {
 
               if(response.getType().equals(QRTypeCode.URL)) {
 
                    String qrUrl = response.getData(); //Display QR image by using url.
               } else if(response.getType().equals(QRTypeCode.Base64)) {
 
                    //Open base64 image.
               } else if(response.getType().equals(QRTypeCode.Raw)) {
 
                    //Build QR image by using raw string.
               }
 
               //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
           } 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.TransactionQRPayment]) {
                
           if([response.type isEqualToString: QRTypeCode.URL]) {
                    
               NSString *qrUrl = response.data; //Display QR image by using url.
           } else if([response.type isEqualToString: QRTypeCode.Base64]) {
                    
               //Open base64 image.
           } else if([response.type isEqualToString: QRTypeCode.Raw]) {
                    
               //Build QR image by using raw string.
           }
                
           //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
      } 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.TransactionQRPayment {
                 
          if response.type == QRTypeCode.URL {
 
               guard let qrUrl: String = response.data else { return } //Display QR image by using url.           
          } else if response.type == QRTypeCode.Base64 {
 
              //Open base64 image
          } else if response.type == QRTypeCode.Raw {
 
              //Build QR image by raw string
          }
 
          //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
      } else {
                 
          //Get error response and display error.
      }
}) { (error: NSError) in
             
     //Get error response and display error.
}

 

Step 5 :Initiate Transaction Status Inquiry

QR Code has been generated for customer to scan and pay. For checking transaction status, required initiate Transaction Status Inquiry

📘

SDK API

Please refer : Transaction Status Inquiry API

 

Full Sample Code

Full Sample Code Show below.

//Step 1 : Generate payment token
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
 
//Step 2: Construct QR request.
PaymentCode paymentCode = new PaymentCode("VEMVQR");
 
PaymentRequest paymentRequest = new QRPaymentBuilder(paymentCode)
                                .setType(QRTypeCode.URL)
                                .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.TransactionQRPayment)) {
 
               if(response.getType().equals(QRTypeCode.URL)) {
 
                    String qrUrl = response.getData(); //Display QR image by using url.
               } else if(response.getType().equals(QRTypeCode.Base64)) {
 
                    //Open base64 image.
               } else if(response.getType().equals(QRTypeCode.Raw)) {
 
                    //Build QR image by using raw string.
               }
 
               //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
           } 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 QR request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"VEMVQR"];
     
PaymentRequest *paymentRequest = [[[[[[[QRPaymentBuilder alloc] initWithPaymentCode: paymentCode]
                                        type: QRTypeCode.URL]
                                        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.TransactionQRPayment]) {
                
           if([response.type isEqualToString: QRTypeCode.URL]) {
                    
               NSString *qrUrl = response.data; //Display QR image by using url.
           } else if([response.type isEqualToString: QRTypeCode.Base64]) {
                    
               //Open base64 image.
           } else if([response.type isEqualToString: QRTypeCode.Raw]) {
                    
               //Build QR image by using raw string.
           }
                
           //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
      } else {
                
          //Get error response and display error.
      }
} failure: ^(NSError * _Nonnull error) {
            
     //Get error response and display error.
}];
//Step 1 : Generate payment token
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
    
//Step 2: Construct QR request.
let paymentCode: PaymentCode = PaymentCode(channelCode: "VEMVQR")
 
let paymentRequest: PaymentRequest = QRPaymentBuilder(paymentCode: paymentCode)
                                     .type(QRTypeCode.URL)
                                     .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.TransactionQRPayment {
                 
          if response.type == QRTypeCode.URL {
 
               guard let qrUrl: String = response.data else { return } //Display QR image by using url.           
          } else if response.type == QRTypeCode.Base64 {
 
              //Open base64 image
          } else if response.type == QRTypeCode.Raw {
 
              //Build QR image by raw string
          }
 
          //Note: For QR payment MUST keep repeating request Transaction Status Inquiry API to check payment status until customer take payment action like scan QR for payment or cancel payment.
      } else {
                 
          //Get error response and display error.
      }
}) { (error: NSError) in
             
     //Get error response and display error.
}