Collect orders
# Code Sample
- The code example is for reference only. For specific parameter descriptions, please refer to the request parameter description.
TopPayRequestUtil(Click here to get the code sample)
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 TopPayDemo {
private static final String MCH_ID = "S820250514103726000009";
private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqG.........iDtQIDAQAB";
private static final String MCH_PRIVATE_KEY = "MIICeAIBAD9Fz0.......jKTtoWN6j3F1V0bdyvhh";
private static final String payUrl = "https://vnm-openapi.toppay.asia/gateway/prePayIn";
private static final String payNotify = "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");
requestParams.put("method", "QR");
requestParams.put("orderNum", "T1324657980");
requestParams.put("payMoney", "10000.00");
requestParams.put("notifyUrl", payNotify);
requestParams.put("dateTime", "20250514102512");
List<String> paramNameList = new ArrayList<>();
for (String key : requestParams.keySet()) {
paramNameList.add(key);
}
Collections.sort(paramNameList);
StringBuilder stringBuilder = new StringBuilder();
for (String key : paramNameList) {
stringBuilder.append(requestParams.get(key));
}
String keyStr = stringBuilder.toString();
System.out.println("keyStr:" + keyStr);
String signedStr = TopPayRequestUtil.privateEncrypt(keyStr, TopPayRequestUtil.getPrivateKey(MCH_PRIVATE_KEY));
requestParams.put("sign", signedStr);
String postJson = new Gson().toJson(requestParams);
System.out.println("Post Json Params:" + postJson);
String responseJson = TopPayRequestUtil.doPost(payUrl, postJson);
System.out.println("Response Msg:" + responseJson);
}
}
# Api Address
Cashier (Mode 1): Use our POS system for transactions.
Request Method: POST
Request URL: https://vnm-openapi.toppay.asia/gateway/prePayIn
Direct Connection Mode (Mode 2): Retrieve payment information (suitable for merchants with their own POS page).
Request Method: POST
Request URL: https://vnm-openapi.toppay.asia/gateway/payment
# Request Parameters
Note: Do not fill in Chinese in all parameters!!!
| Params | Type | Required | Desc | Ex |
|---|---|---|---|---|
| merchantCode | String | Y | MchId | S820250514103726000009 |
| orderType | String | Y | Order Type | The default value is 0 |
| method | String | Y | Method | BANK_QR Click to view supported payment methods |
| orderNum | String | Y | Merchant order number | T1642592278863 |
| payMoney | String | Y | Payment amount (only two decimal places are allowed) | 10000.00 |
| notifyUrl | String | Y | Notification Address | https://host:port/notifyUrl |
| dateTime | String | Y | yyyyMMddHHmmss | 20190101235959 |
| extendParam | String | N | Transparent parameters (uploaded content will be returned by the original path) | test |
| sign | String | Y | Signature | fnbSOvY83pr8hXg+Fd ... |
# Request Params Example
{
"merchantCode": "S820250514103726000009",
"orderType": "0",
"orderNum": "T1642593166888",
"payMoney": "10000.00",
"method": "QR",
"notifyUrl": "your notify url",
"dateTime": "20250514102565",
"extendParam": "TEST",
"sign": "fnbSOvY83pr8hXg+FdNNYi2ubQUGNv/qGYc4TjRl+Xxd1yc9fpkpTx5UQEDTgmhwdCKBkhHVsx2AiQbYDxZ5WBuU1GZeiJ"
}
# Response Params
| Params | Type | Required | Desc | Ex |
|---|---|---|---|---|
| platRespCode | String | Y | Request Result | FAIL\SUCCESS |
| platRespMessage | String | Y | Message | Request Transaction Success |
| platOrderNum | String | Y | Platform order number | PI1453242857400963072 |
| payMoney | string | Y | Payment amount | 10000.00 |
| orderNum | String | Y | Merchant order number | T1234567980 |
| payData | String | N | Payment Info | Mode 1 returns a link, Mode 2 returns payment information |
| extendParam | string(100) | N | Transparent parameters (uploaded content will be returned by the original path) | 123 |
# Response Params Example
{
"platOrderNum": "P16546513165462132132",
"payMoney": "10000.00",
"orderNum": "T1642593166888",
"platRespCode": "SUCCESS",
"platRespMessage": "Request Transaction Success",
"payData": "https://vnm-openapi.toppay.asia/gateway/order/P16546513165462132132",
"extendParam": "TEST"
}
# Order Notification
- **When verifying the signature, use the platform public key provided in the merchant backend-payment configuration-API configuration for decryption! ! ! **
- When verifying the signature, the actual callback parameters shall prevail, and do not verify the fixed parameters
- **The final status of the order shall be based on the status of the notification! ! ! **
- **After receiving the asynchronous notification, you need to respond to the
SUCCESSstring, otherwise TopPay will continue to initiate 5 notifications! ! ! **
import com.google.gson.JsonObject;
public class TopPayNotify {
private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqG.........iDtQIDAQAB";
public static void main(String[] args) throws Exception {
JsonObject notifyBody = new jsonObject();
boolean verifyResult = TopPayRequestUtil.verifySign(notifyBody,PLAT_PUBLIC_KEY);
if (verifyResult) {
} else {
}
}
}
# Params
| Params | Required | Desc | Ex |
|---|---|---|---|
| code | Y | Code | 00 |
| msg | Y | Message | SUCCESS |
| method | Y | Method | QR |
| status | Y | Order Status | Order Status |
| platOrderNum | Y | Platform order number | P16546513165462132132 |
| orderNum | Y | Merchant order number | T1231511321515 |
| payMoney | Y | Order amount | 10000.00 |
| extendParam | N | Transparent parameters (uploaded content will be returned by the original path) | TEST |
| platSign | Platform Signature | ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs |
# Response Example
{
"code": "00",
"msg": "SUCCESS",
"status": "SUCCESS",
"method": "QR",
"platOrderNum": "P16546513165462132132",
"orderNum": "T1642593166888",
"payMoney": "10000.00",
"extendParam": "TEST",
"platSign": "ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs"
}