Account Balance Inquiry
# Code example
TopPayRequestUtil Click to obtain code examples
import com.google.gson.JsonObject;
public class BalanceQuery {
//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 BALANCE_QUERY_URL = "https://tl-openapi.toppay.asia/gateway/interface/getBalance";
public static void main(String[] args) throws Exception {
query();
}
private static void query() throws Exception {
Map<String, String> requestParams = new TreeMap<>();
requestParams.put("merchantCode", MCH_ID);
requestParams.put("currency", "THB"); // currency(THB)
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(BALANCE_QUERY_URL, postJson); // send post json request
System.out.println("Response Msg:" + responseJson);
}
}
# Request address
- Request type:
POST
- Request address:
https://tl-openapi.toppay.asia/gateway/interface/getBalance
# Request Param
param | required | description | example |
---|---|---|---|
merchantCode | Y | merchant code | S820211021094748000001 |
currency | N | currency | THB(If no currency is passed, the balance of all currency units will be displayed) |
sign | Y | RSA sign | ja6R8eukQ... |
# Request example
{
"merchantCode": "S8202110212321300001",
"currency": "THB",
"sign": "X/o+IQUzLJqYe9Feid9Uww72mJGOvhJSJEIfo1EUChrZyVZnzGHtd61QhOqRmXCtAwk7V7k="
}
# Response param
param | Type | Required | Description | Example |
---|---|---|---|---|
success | BOOLEAN | Y | response status | true/false |
code | int | Y | response code | 1000 means success, others are failure |
message | String | Y | response message | return specific response information |
data | Json | Y | data | The following parameters are all returned in data, or null if failed |
mchId | String | Y | merchant ID | S8202110212321300001 |
mchName | String | Y | merchant name | test |
mchNo | String | Y | merchant number | TP123 |
currency | string | Y | currency | IDR |
balance | String | Y | balance | 1000.00 |
freeze | String | Y | freeze | 10.00 |
waitingSettleAmount | String | Y | waiting settle amount | 200.00 |
freezeWaitingSettleAmount | String | Y | freeze waiting settle amount | 100.00 |
totalAmount | String | Y | total amount(balance+freeze+waiting settle amount +freeze waiting settle amount) | 20000.00 |
# Response example
{
"success": true,
"code": 1000,
"message": "SUCCESS",
"data": [
{
"mchId": "S82022091232130000001",
"mchName": "test",
"mchNo": "test",
"country": "THAILAND",
"currency": "THB",
"balance": "1000000.01",
"freeze": "10.00",
"waitingSettleAmount": "10.00",
"freezeWaitingSettleAmount": "20.00",
"totalAmount": "1000040.01"
}
]
}