Account balance inquiry
# Code example
- 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.JsonObject;
public class BalanceQuery {
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 BALANCE_QUERY_URL = "https://vnm-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", "VND");
List<String> paramNameList = new ArrayList<>();
for (String key : maps.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(orderQueryUrl, postJson);
System.out.println("Response Msg:" + responseJson);
}
}
# API address
- Request method : POST
- Request address : https://vnm-openapi.toppay.asia/gateway/interface/getBalance
# Request Parameters
| Params | Type | Required | Ex |
|---|---|---|---|
| merchantCode | MchId | Y | S820211021094748000001 |
| currency | Currency | N | VND(If not passed, balances in all currencies will be displayed) |
| sign RSA Signature | Y | ja6R8eukQ... |
# Request message example
{
"merchantCode": "S8202110212321300001",
"currency": "VND",
"sign": "X/o+IQUzLJqYe9Feid9Uww72mJGOvhJSJEIfo1EUChrZyVZnzGHtd61QhOqRmXCtAwk7V7k="
}
# Response Parameters
| Params | Type | Required | Desc | Ex |
|---|---|---|---|---|
| success | BOOLEAN | Y | Request Result | true/false |
| code | Int | Y | Code | 1000-SUCCESS,all others are failures |
| message | String | Y | message | Response Info |
| data | Json | Y | Data | The following parameters are returned in data, or null if failed |
| mchId | String | Y | MchId | S8202110212321300001 |
| mchName | String | Y | MchName | test |
| mchNo | String | Y | MchNo | TP123 |
| currency | String | Y | Currency | VND |
| balance | String | Y | Available balance | 1000.00 |
| freeze | String | Y | Freeze Balance | 10.00 |
| waitingSettleAmount | String | Y | Amount to be settled | 200.00 |
| freezeWaitingSettleAmount | String | Y | Freeze the amount to be settled | 100.00 |
| totalAmount | String | Y | Total amount (available balance + frozen balance + pending settlement amount + frozen pending settlement amount) | 20000.00 |
# Response result example
{
"success": true,
"code": 1000,
"message": "SUCCESS",
"data": [
{
"mchId": "S82022091232130000001",
"mchName": "test",
"mchNo": "test",
"country": "VIETNAM",
"currency": "VND",
"balance": "1000000.01",
"freeze": "10.00",
"waitingSettleAmount": "10.00",
"freezeWaitingSettleAmount": "20.00",
"totalAmount": "1000040.01"
}
]
}