QR Payment
The 2C2P PGW SDK allows customers to scan and pay through a merchant's mobile application.
API Method
References
1. Prepare Payment Token Request
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": ["QR"]
}
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";
val 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"
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
3. Prepare Payment Request
To prepare a payment request, refer to the sample code below.
Payment Request Parameters
Refer to: Payment Request API Parameters
Payment Channel Matrix
To see the available QR payment options, refer to: Payment Channel Matrix
QR Type Code
Refer to: QR Type Code Enums
PaymentCode paymentCode = new PaymentCode("VEMVQR");
PaymentRequest paymentRequest = new QRPaymentBuilder(paymentCode)
.setType(QRTypeCode.URL)
.setName("DavidBilly")
.setEmail("[email protected]")
.setMobileNo("0888888888")
.build();
val paymentCode = PaymentCode("VEMVQR")
val paymentRequest = QRPaymentBuilder(paymentCode).apply {
type(QRTypeCode.URL)
name("DavidBilly")
email("[email protected]")
mobileNo("0888888888")
}.build()
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: @"VEMVQR"];
PaymentRequest *paymentRequest = [[[[[[[QRPaymentBuilder alloc] initWithPaymentCode: paymentCode]
type: QRTypeCode.URL]
name: @"DavidBilly"]
email: @"[email protected]"]
mobileNo: @"0888888888"]
build];
let paymentCode: PaymentCode = PaymentCode(channelCode: "VEMVQR")
let paymentRequest: PaymentRequest = QRPaymentBuilder(paymentCode: paymentCode)
.type(QRTypeCode.URL)
.name("DavidBilly")
.email("[email protected]")
.mobileNo("0888888888")
.build()
Map<String, dynamic> paymentCode = {
'channelCode': 'VEMVQR'
};
Map<String, dynamic> paymentRequest = {
'qrType': QRTypeCode.url,
'name': 'DavidBilly',
'email': '[email protected]',
'mobileNo': '0888888888'
};
let paymentCode = {
'channelCode': 'VEMVQR'
};
let paymentRequest = {
'qrType': QRTypeCode.url,
'name': 'DavidBilly',
'email': '[email protected]',
'mobileNo': '0888888888'
};
4. Prepare Transaction Request
To prepare a transaction request, refer to the parameters below.
Transaction Request API Parameters
Refer to: Do Payment Request API Parameters
TransactionResultRequest transactionResultRequest = new TransactionResultRequestBuilder(paymentToken)
.with(paymentRequest)
.build();
val transactionResultRequest = TransactionResultRequestBuilder(paymentToken).apply {
with(paymentRequest)
}.build()
TransactionResultRequest *transactionResultRequest = [[[[TransactionResultRequestBuilder alloc] initWithPaymentToken: paymentToken]
withPaymentRequest: paymentRequest]
build];
let transactionResultRequest: TransactionResultRequest = TransactionResultRequestBuilder(paymentToken: paymentToken)
.with(paymentRequest)
.build()
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
let transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
5. Receive Transaction Request Response
To receive a transaction request response, refer to the parameters below.
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.TransactionQRPayment)) {
if (response.getType().equals(QRTypeCode.URL)) {
String qrUrl = response.getData(); //Display QR image by using url.
} else if (response.getType().equals(QRTypeCode.Base64)) {
String qrBase64 = response.getData(); //Open base64 image.
} else if (response.getType().equals(QRTypeCode.Raw)) {
String qrRaw = response.getData(); //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.getInstance().proceedTransaction(transactionResultRequest, object : APIResponseCallback<TransactionResultResponse> {
override fun onResponse(response: TransactionResultResponse) {
if (response.responseCode == APIResponseCode.TransactionQRPayment) {
if (response.type == QRTypeCode.URL) {
val qrUrl = response.data //Display QR image by using url.
} else if (response.type == QRTypeCode.Base64) {
val qrBase64 = response.data //Open base64 image.
} else if (response.type == QRTypeCode.Raw) {
val qrRaw = response.data //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 fun onFailure(error: Throwable) {
//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]) {
NSString *qrBase64 = response.data; //Open base64 image.
} else if([response.type isEqualToString: QRTypeCode.Raw]) {
NSString *qrRaw = response.data; //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 {
let qrUrl: String = response.data //Display QR image by using url.
} else if response.type == QRTypeCode.Base64 {
let qrBase64: String = response.data //Open base64 image
} else if response.type == QRTypeCode.Raw {
let qrRaw: String = response.data //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.
}
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionQRPayment) {
if (response['type'] == QRTypeCode.url) {
String qrUrl = response['data']; //Display QR image by using url.
} else if (response['type'] == QRTypeCode.base64) {
String qrBase64 = response['data']; //Open base64 image
} else if (response['type'] == QRTypeCode.raw) {
String qrRaw = response['data']; //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) {
//Get error response and display error.
});
await RTNPGW.proceedTransaction(JSON.stringify(transactionResultRequest)).then((response: string) => {
let transactionResultResponse = JSON.parse(response);
if (transactionResultResponse?.responseCode == APIResponseCode.transactionQRPayment) {
if (transactionResultResponse?.type == QRTypeCode.url) {
let qrUrl = transactionResultResponse?.data; //Display QR image by using url.
} else if (transactionResultResponse?.type == QRTypeCode.base64) {
let qrBase64 = transactionResultResponse?.data; //Open base64 image
} else if (transactionResultResponse?.type == QRTypeCode.raw) {
let qrRaw = transactionResultResponse?.data; //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.
}
}).catch ((error: Error) => {
//Get error response and display error
});
6. Initiate Transaction Status Inquiry
A QR code will be generated for the customer to scan and pay. To retrieve transaction details and status, merchants must initiate the Transaction Status Inquiry API. Refer to the sample code below.
Transaction Status Inquiry API
Refer to: Transaction Status Inquiry API
Full Sample Code
The following sample code demonstrates requests and responses for each step of the process.
//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("0888888888")
.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)) {
String qrBase64 = response.getData(); //Open base64 image.
} else if (response.getType().equals(QRTypeCode.Raw)) {
String qrRaw = response.getData(); //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.
val paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
//Step 2: Construct QR request.
val paymentCode = PaymentCode("VEMVQR")
val paymentRequest = QRPaymentBuilder(paymentCode).apply {
type(QRTypeCode.URL)
name("DavidBilly")
email("[email protected]")
mobileNo("0888888888")
}.build()
//Step 3: Construct transaction request.
val transactionResultRequest = TransactionResultRequestBuilder(paymentToken).apply {
with(paymentRequest)
}.build()
//Step 4: Execute payment request.
PGWSDK.getInstance().proceedTransaction(transactionResultRequest, object : APIResponseCallback<TransactionResultResponse> {
override fun onResponse(response: TransactionResultResponse) {
if (response.responseCode == APIResponseCode.TransactionQRPayment) {
if (response.type == QRTypeCode.URL) {
val qrUrl = response.data //Display QR image by using url.
} else if (response.type == QRTypeCode.Base64) {
val qrBase64 = response.data //Open base64 image.
} else if (response.type == QRTypeCode.Raw) {
val qrRaw = response.data //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 fun onFailure(error: Throwable) {
//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: @"0888888888"]
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]) {
NSString *qrBase64 = response.data; //Open base64 image.
} else if([response.type isEqualToString: QRTypeCode.Raw]) {
NSString *qrRaw = response.data; //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("0888888888")
.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 {
let qrUrl: String = response.data //Display QR image by using url.
} else if response.type == QRTypeCode.Base64 {
let qrBase64: String = response.data //Open base64 image
} else if response.type == QRTypeCode.Raw {
let qrRaw: String = response.data //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 1: Generate payment token.
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
//Step 2: Construct QR request.
Map<String, dynamic> paymentCode = {
'channelCode': 'VEMVQR'
};
Map<String, dynamic> paymentRequest = {
'qrType': QRTypeCode.url,
'name': 'DavidBilly',
'email': '[email protected]',
'mobileNo': '0888888888'
};
//Step 3: Construct transaction request.
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
//Step 4: Execute payment request.
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionQRPayment) {
if (response['type'] == QRTypeCode.url) {
String qrUrl = response['data']; //Display QR image by using url.
} else if (response['type'] == QRTypeCode.base64) {
String qrBase64 = response['data']; //Open base64 image
} else if (response['type'] == QRTypeCode.raw) {
String qrRaw = response['data']; //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) {
//Get error response and display error.
});
//Step 1: Generate payment token.
let paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
//Step 2: Construct QR request.
let paymentCode = {
'channelCode': 'VEMVQR'
};
let paymentRequest = {
'qrType': QRTypeCode.url,
'name': 'DavidBilly',
'email': '[email protected]',
'mobileNo': '0888888888'
};
//Step 3: Construct transaction request.
let transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
//Step 4: Execute payment request.
await RTNPGW.proceedTransaction(JSON.stringify(transactionResultRequest)).then((response: string) => {
let transactionResultResponse = JSON.parse(response);
if (transactionResultResponse?.responseCode == APIResponseCode.transactionQRPayment) {
if (transactionResultResponse?.type == QRTypeCode.url) {
let qrUrl = transactionResultResponse?.data; //Display QR image by using url.
} else if (transactionResultResponse?.type == QRTypeCode.base64) {
let qrBase64 = transactionResultResponse?.data; //Open base64 image
} else if (transactionResultResponse?.type == QRTypeCode.raw) {
let qrRaw = transactionResultResponse?.data; //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.
}
}).catch ((error: Error) => {
//Get error response and display error
});
Updated 26 days ago