Do Payment
The Do Payment API allows merchant applications to relay information about a customer's selected payment method to 2C2P's PGW for processing.
Refer to the links below for parameters and code samples for each step:
- Generate Payment Token
- Prepare Payment Request
- Prepare Transaction Request
- Execute Payment Request
- Full Sample Code
API Method
References
1. Generate Payment Token
To prepare a payment token request, refer to the required parameters below.
{
"merchantID": "JT04",
"invoiceNo": "1595219400",
"description": "2 days 1 night hotel room",
"amount": 10.0,
"currencyCode": "THB",
"nonceStr": "a8092512-b144-41b0-8284-568bb5e9264c",
"paymentChannel": ["ALL"]
}
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"
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
Payment Token API
Refer to: Payment Token API
3. Prepare Payment Request
To prepare a payment request, refer to the parameters below.
Request API Parameters
Refer to: Do Payment Request API Parameters
PaymentCode paymentCode = new PaymentCode(PaymentChannelCode.Group.CreditCard);
PaymentRequest paymentRequest = new UniversalPaymentBuilder(paymentCode)
.setCardNo("4111111111111111")
.setExpiryMonth(12)
.setExpiryYear(2020)
.setSecurityCode("123")
.build();
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: PaymentChannelCodeGroup.CreditCard];
PaymentRequest *paymentRequest = [[[[[[[UniversalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
cardNo: @"card no"]
expiryMonth: 12]
expiryYear: 2020]
securityCode: @"123"]
build];
let paymentCode: PaymentCode = PaymentCode(channelCode: PaymentChannelCode.Group.CreditCard)
let paymentRequest: PaymentRequest = UniversalPaymentBuilder(paymentCode: paymentCode)
.cardNo("4111111111111111")
.expiryMonth(12)
.expiryYear(2022)
.securityCode("123")
.build()
Map<String, dynamic> paymentCode = {
'channelCode': 'CC'
};
Map<String, dynamic> paymentRequest = {
'cardNo': '4111111111111111',
'expiryMonth': 12,
'expiryYear': 2025,
'securityCode': '123'
};
4. Prepare Transaction Request
To prepare a 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()
Map<String, dynamic> transactionResultRequest = {
'paymentToken': paymentToken,
'payment': {
'code': {
...paymentCode
},
'data': {
...paymentRequest
}
}
};
5. Execute Payment Request
To execute a payment request and receive the API response, refer to the parameters below.
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.
}
PGWSDK().proceedTransaction(transactionResultRequest, (response) {
if (response['responseCode'] == APIResponseCode.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
Full Sample Code
The following sample code demonstrates requests and parameters for each step of the process.
String paymentToken = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
//Step 2: Construct payment request.
PaymentCode paymentCode = new PaymentCode(PaymentChannelCode.Group.CreditCard);
PaymentRequest paymentRequest = new UniversalPaymentBuilder(paymentCode)
.setCardNo("4111111111111111")
.setExpiryMonth(12)
.setExpiryYear(2020)
.setSecurityCode("123")
.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.
}
});
NSString *paymentToken = @"roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL";
//Step 2: Construct payment request.
PaymentCode *paymentCode = [[PaymentCode alloc] initWithChannelCode: PaymentChannelCodeGroup.CreditCard];
PaymentRequest *paymentRequest = [[[[[[[UniversalPaymentBuilder alloc] initWithPaymentCode: paymentCode]
cardNo: @"card no"]
expiryMonth: 12]
expiryYear: 2020]
securityCode: @"123"]
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.
}];
let paymentToken: String = "roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL"
//Step 2: Construct credit card request.
let paymentCode: PaymentCode = PaymentCode(channelCode: PaymentChannelCode.Group.CreditCard)
let paymentRequest: PaymentRequest = UniversalPaymentBuilder(paymentCode: paymentCode)
.cardNo("4111111111111111")
.expiryMonth(12)
.expiryYear(2022)
.securityCode("123")
.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.
}
String paymentToken = 'roZG9I1hk/GYjNt+BYPYbxQtKElbZDs9M5cXuEbE+Z0QTr/yUcl1oG7t0AGoOJlBhzeyBtf5mQi1UqGbjC66E85S4m63CfV/awwNbbLbkxsvfgzn0KSv7JzH3gcs/OIL';
//Step 2: Construct credit card request.
Map<String, dynamic> paymentCode = {
'channelCode': 'CC'
};
Map<String, dynamic> paymentRequest = {
'cardNo': '4111111111111111',
'expiryMonth': 12,
'expiryYear': 2025,
'securityCode': '123'
};
//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.transactionAuthenticateRedirect || response['responseCode'] == APIResponseCode.transactionAuthenticateFullRedirect) {
String redirectUrl = response['data']; //Open WebView
} else if (response['responseCode'] == APIResponseCode.transactionCompleted) {
//Inquiry payment result by using invoice no.
} else {
//Get error response and display error.
}
}, (error) {
//Get error response and display error.
});
Updated 4 months ago