Skip to content

sud.getBalance ​

Queries the game currency balance and cumulative totals.

Parameters ​

Object object ​

PropertyTypeDefaultRequiredDescription
envnumber0No0 for production, 1 for testing
successfunctionNoCallback for a successful query
failfunctionNoCallback for a failed query
completefunctionNoCallback invoked when the call ends, after either success or failure

Callback Parameters ​

success ​

PropertyTypeDescription
balancenumberTotal game currency balance, including both paid and granted amounts
presentBalancenumberCurrent granted game currency balance
sumSavenumberCumulative game currency topped up
sumPresentnumberCumulative game currency granted
sumBalancenumberCumulative game currency obtained
sumCostnumberCumulative game currency spent

The paid balance is balance - presentBalance. The API does not return it separately, so compute it yourself.

fail ​

PropertyTypeDescription
errCodenumberError code
errMsgstringError message

complete carries no arguments. It is invoked after success or fail, and runs only once per request.

Notes ​

  • env must match the env used in signData when the order was created, otherwise you will read the balance of the other environment.
  • Order delivery and reading the updated balance are two separate things. The balance may lag briefly after the server confirms delivery, so retry on a failed query instead of treating it as a delivery failure.
  • Refresh the UI from this API's result. Do not treat locally incremented or decremented values on the client as the balance.

Example Code ​

javascript
sud.getBalance({
    env: 0,
    success: (res) => {
        const paidBalance = res.balance - res.presentBalance;
        console.log('Total balance', res.balance);
        console.log('Paid balance', paidBalance);
        console.log('Granted balance', res.presentBalance);
        console.log('Topped up', res.sumSave, 'Spent', res.sumCost);
    },
    fail: (err) => {
        console.error('Failed to query balance', err.errCode, err.errMsg);
    },
    complete: () => {
        console.log('Query balance call finished');
    },
});