THB Pay Api
# Code example
- The code example is for reference only. For specific parameter descriptions, please refer to
Request Parameter Description
TopPayRequestUtil Click to obtain code examples
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.Map;
import java.util.TreeMap;
public class PayDemo {
//MCH_ID: Merchant ID
//1.Please log in to the merchant backend
//2.Click on personal center > personal information
//3.Get Merchant ID in Basic Information
private static final String MCH_ID = "S820211021094748000001";
private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2JoMfFqLsSJjAiCahEnlP3aRj8yCT+WHzR+VvPBTw9S1i7iYWb+MY09CG/HYuHF4+IxshXDJygmndxKf/esuwPybS8mAd//yubHpmZsmBqg1FffT8VH1APa6ZRWASUp4U01ZrbCCp35QA8FuWrJGMJxGx4xk7KUtV2yujxC8noQIDAQAB"; // platform public key
private static final String MCH_PRIVATE_KEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJU8gKFKD0luIYx7X8+JRdCIE0UDBctS6LjXxWLEv/EO7jDBTid6zYP1KmNgpd2DAWWtBFBSQ+gcNwVZZSBHJiSDqVvvJVs2FEbeBvfdv4X93+IYRAXksBasSW5Tpdshbo82pVL4V7wuKCuFLk9UxBHbpQjWAbfyF66RmwIbZD71AgMBAAECgYBjPe7UU2nDDSfmQg0++CyjNjqKRC5QPfxhH6w1uF1kMueXKJWOj42n2RutJpJmsj31nY8m0u4xpsG4HvCu/GGSFhhKZCHLvzp41oY2ubYj9nuFNU//81LycQjulWo2y0UUBY0k2piEt+SwPaiUNbT6nMxNMjlnjRe2okp/3rw+KQJBANG3YlZWoVbCEqzy64bJJLxiPsCA5ErGB0NzRGitq44xkhqGtR8ZZQyVz40pruNa58d73O2xyJSy5+fmZGn4E+sCQQC2LBnguj0CSCKub0mPDcunTTz9V79VXBBZdlB1/YGmRUx2s4sQrJNZS7rL4EqBQ3maIRnG+s+AXCSTfsYrV6CfAkEAxugnVfpelhoGepEAgNuggyivmgfl/2Gpm/jk5l/qOjib+ZrQiQmeBPzGWX4yiSM8eMDrP2sC8r5pJFMp5DRONwJBAJ4n4XuSFJ9jgwCPy3vvzSv9SYLk6E6yM9uHdUlKgoGYzk6Lh6M9QFuY/J49plFdBDiEnj16yCU3WeXXfTJpzB8CQQDMNMR/rIOTE9xGybS3mlQbt22AUnO6XhupWcckEKW4nPGxATwYBQzCY3i/9FTGN0vA+9ZPC2cwHtNxI2kXf3Vp"; // merchant private key
private static final String payUrl = "https://tl-openapi.toppay.asia/gateway/prepaidOrder";
private static final String payNotify = "your notify url";
private static final String cashNotify = "your notify url";
public static void main(String[] args) throws Exception {
pay();
}
private static void pay() throws Exception {
Map<String, String> requestParams = new TreeMap<>();
requestParams.put("merchantCode", MCH_ID);
requestParams.put("orderType", "0"); // orderType(0-BAHT transaction)
requestParams.put("method", "BankTransfer"); // When using online banking, pass in the corresponding bank abbreviation, and pass in qr Pay when using a QR code, or not
requestParams.put("transAccNo", "1234567890"); // The card number paid by the user must be transmitted, and the real card number must be passed, otherwise the transaction will fail
requestParams.put("orderNum", "T1642592278863"); // merchant order number
requestParams.put("payMoney", "100.00"); // order amount
requestParams.put("notifyUrl", payNotify);// callback address
requestParams.put("dateTime", "20220101235959");// timestamp format yyyyMMddHHmmss
StringBuilder stringBuilder = new StringBuilder();
for (String key : requestParams.keySet()) {
stringBuilder.append(requestParams.get(key)); // stitching parameters
}
String keyStr = stringBuilder.toString(); // get the string to be encrypted
System.out.println("keyStr:" + keyStr);
String signedStr = TopPayRequestUtil.privateEncrypt(keyStr, TopPayRequestUtil.getPrivateKey(MCH_PRIVATE_KEY)); // private key encryption
requestParams.put("sign", signedStr);
String postJson = new Gson().toJson(requestParams);
System.out.println("Post Json Params:" + postJson);
String responseJson = TopPayRequestUtil.doPost(payUrl, postJson); // post request
System.out.println("Response Msg:" + responseJson);
}
}
# Request address
- Checkout counter mode (Mode 1): Open the checkout link to get payment information
- Request method: POST
- Request address: https://tl-openapi.toppay.asia/gateway/prepaidOrder
- Direct connection mode (Mode 2): Obtain payment information directly (applicable to merchants with their own checkout page)
- Request method: POST
- Request address: https://tl-openapi.toppay.asia/gateway/payment
# Request parameters
Note: Do not fill in Chinese in all parameters! ! !
- Checkout counter mode (Mode 1):
Param | Type | Required | Description | Example |
---|---|---|---|---|
merchantCode | string(32) | Y | merchant ID,Get it in merchant background | S820211021094748000001 |
orderType | string(10) | Y | order type | 0-Fiat Currency (Thai Baht) Transaction |
method | string(32) | N | Payment method | qrPay: Scan the QR code BankTransfer : Online banking transfer If not, choose your own payment method on the checkout page |
orderNum | string(32) | Y | merchant order number | 10000001 |
transAccNo | string(16) | Y | The real card number for payment is required.Must pass. Otherwise the order cannot be matched. | |
payMoney | string(10) | Y | payment amount(only two decimal) | 100.00 |
bankCode | String(10) | Y | payment bank number | 001 Click to view supported bank codes |
notifyUrl | string(100) | Y | Address to receive notification of successful order transaction | https://host:port/notifyUrl |
dateTime | string(255) | Y | timestamp format:yyyyMMddHHmmss | 20190101235959 |
paymentName | string(64) | Y | Payer Real Name | Jerry |
extendParam | string(100) | N | Extended parameters (uploaded content will be returned) | 123 |
sign | string(255) | Y | Sign | fnbSOvY83pr8hXg+Fd ... |
- Direct connection mode (Mode 2):
Param | Type | Required | Description | Example |
---|---|---|---|---|
merchantCode | string(32) | Y | merchant ID,Get it in merchant background | S820211021094748000001 |
orderType | string(10) | Y | order type | 0-Fiat currency transaction |
method | string(32) | Y | Payment method | qrPay : Scan the QR code👍 BankTransfer: Online banking transfer |
orderNum | string(32) | Y | merchant order number | 10000001 |
payMoney | string(10) | Y | payment amount(only two decimal) | 100.00 |
notifyUrl | string(100) | Y | Address to receive notification of successful order transaction | https://host:port/notifyUrl |
dateTime | string(32) | Y | timestamp format:yyyyMMddHHmmss | 20190101235959 |
transAccNo | string(16) | Y | Real card number for payment The real card number for payment is required.Must pass. Otherwise the order cannot be matched | 1234567890 |
returnAccName | string(10) | N | Whether the response parameters returns the payee name | Need to return: true No need to return: false |
paymentName | string(64) | Y | Payer Real Name | Jerry |
extendParam | string(100) | N | Extended parameters (uploaded content will be returned) | 123 |
sign | string(255) | Y | Sign | fnbSOvY83pr8hXg+Fd ... |
# Request example
- Checkout counter mode (Mode 1): (method parameters do not need to be passed, the page to be jumped is different)
{
"merchantCode": "S820211021094748000001",
"orderType": "0",
"orderNum": "T1642593166888",
"transAccNo": "1234567890",
"payMoney": "100.00",
"method": "qrPay",
"notifyUrl": "your notify url",
"dateTime": "20220101235959",
"paymentName": "Jerry",
"extendParam": "123456",
"sign": "fnbSOvY83pr8hXg+FdNNYi2ubQUGNv/qGYc4TjRl+Xxd1yc9fpkpTx5UQEDTgmhwdCKBkhHVsx2AiQbYDxZ5WBuU1GZeiJ"
}
- **Direct connection mode (mode 2): **
{
"merchantCode": "S820211021094748000001",
"orderType": "0",
"orderNum": "T1642593166888",
"transAccNo": "1234567890",
"payMoney": "100.00",
"method": "BankTransfer",
"notifyUrl": "your notify url",
"dateTime": "20220101235959",
"returnAccName": "false",
"paymentName": "Jerry",
"extendParam": "123456",
"sign": "fnbSOvY83pr8hXg+FdNNYi2ubQUGNv/qGYc4TjRl+Xxd1yc9fpkpTx5UQEDTgmhwdCKBkhHVsx2AiQbYDxZ5WBuU1GZeiJ"
}
# Response param
Param | Type | Required | Description | Example |
---|---|---|---|---|
platRespCode | String | Y | whether the business is successful | FAIL\SUCCESS |
platRespMessage | String | Y | interface response information prompt | Request Transaction Success |
platOrderNum | String | Y | platform order number | PI1453242857400963072 |
payMoney | String | Y | payment amount | 100.00 |
orderNum | String | Y | merchant order number | 23645782 |
bankName | String | N | bank name | KABNK |
custAccName | String | N | beneficiary name | NVIDJ |
url | String | N | cash register link | Cashier mode(mode 1),Returned when 'platRespCode' is SUCCESS |
payData | String | N | response parameters | Api mode(mode 2),Returned when 'platRespCode' is SUCCESS |
custAccName | String | N | Payee name | Api mode(mode 2),Returned when 'returnAccName' is true |
paymentName | string | N | Payer Real Name | Jerry |
extendParam | string | N | Extended parameters (uploaded content will be returned) | 123 |
# Response message example
- Mode 1 response message example (url is the checkout link)
{
"platOrderNum": "PRE1483771634191044608",
"payMoney": "100.00",
"orderNum": "T1642593166888",
"platRespCode": "SUCCESS",
"platRespMessage": "Request Transaction Success",
"url": "https://tl-openapi.toppay.asia/gateway/order/PRE1483771634191044608",
"paymentName": "Jerry",
"extendParam": "123456"
}
- Mode 2 response message example (when method=qrPay, payData returns the QR code serial number, when method=BankTransfer, returns the payment card number)
{
"platOrderNum": "PRE1483771634191044608",
"payMoney": "100.00",
"orderNum": "T1642593166888",
"platRespCode": "SUCCESS",
"method": "BankTransfer",
"bankName": "KBANK",
"custAccName": "NVIDJ",
"platRespMessage": "Request Transaction Success",
"custAccName": "สวัสดี",
"payData": "123456789",
"paymentName": "Jerry",
"extendParam": "123456"
}
Example of a failure response message
{
"platRespCode": "FAIL",
"platRespMessage": "Error message"
}
# Pay api callback notify
- When verifying the signature, you must use the
Platform Public Key
provided inMerchant Background-Receipt and Payment Configuration-API Configuration
to decrypt! ! ! - When verifying the signature, the actual callback parameters shall prevail. Do not verify the fixed parameters
- The final status of the order is subject to the status of the notification! ! !
- After accepting the asynchronous notification, you need to respond with the
SUCCESS
string, otherwise TopPay will continue to initiate 5 notifications! ! !
import com.google.gson.JsonObject;
public class TopPayNotify {
// test account
private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2JoMfFqLsSJjAiCahEnlP3aRj8yCT+WHzR+VvPBTw9S1i7iYWb+MY09CG/HYuHF4+IxshXDJygmndxKf/esuwPybS8mAd//yubHpmZsmBqg1FffT8VH1APa6ZRWASUp4U01ZrbCCp35QA8FuWrJGMJxGx4xk7KUtV2yujxC8noQIDAQAB"; // platform public key
public static void main(String[] args) throws Exception {
JsonObject notifyBody = new jsonObject();
boolean verifyResult = TopPayRequestUtil.verifySign(notifyBody,PLAT_PUBLIC_KEY);
if (verifyResult) {
// ... signature verification passed,do something
} else {
// ... signature verification error
}
}
}
# Notify Params
Param | Required | Remark | Example |
---|---|---|---|
code | Y | response code | 00 |
msg | Y | response message | SUCCESS |
method | Y | pay type | BankTransfer:Online bank transfer qrPay:QR code scanning |
status | Y | pay result | Click to view order status description |
platOrderNum | Y | platform order number | BK_1563278763273 |
orderNum | Y | merchant order number | T1231511321515 |
payMoney | Y | payment amount | 100.00 |
payFee | Y | merchant fee | 10.00 |
transAccNo | Y | Payment card number | 123456 |
paymentName | N | Payment name | Jerry |
extendParam | N | Extend parameters (uploaded content will be returned by the original path) | 123 |
platSign | Y | Platform Sign | ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs |
# Pay api callback notify example
{
"code": "00",
"msg": "SUCCESS",
"status": "SUCCESS",
"method": "BankTransfer",
"platOrderNum": "PRE1483771634191044608",
"orderNum": "T1642593166888",
"payMoney": "100.00",
"payFee": "10.00",
"transAccNo": "*****1236",
"paymentName": "Jerry",
"extendParam": "123456",
"platSign": "ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs"
}