GetUserBalanceByCurrency (iOS SDK)

This function allows you to see the current balance a user has in their wallet. It can be useful as a check before a user tries to initiate a payment as the authorized invoice will fail anytime a user has insufficient funds.

Prerequisites

  • Authorized User Password Token (A User Password Token is a string that enables Tilia Wallet to verify that a request belongs to an authorized session)
  • Currency Code (The 3 Digit code you use for your token)
note

All methods and flows in the Tilia SDK require you to have a server setup that communicates with Tilia’s APIs (your server will have a private api key which needs to remain secure and should never be exposed to client-side applications). Your client application should communicate with your own api (ensuring user authentication) to retrieve data required by the Tilia SDK.

Server-Side Code Example to Retrieve User Access Token

  • Requires your server to retrieve a client credentials access token. See more here .
  • Requires an account id for a user that has been registered with Tilia. See more here .
Copy
Copied
curl -i -X POST \
  https://auth.staging.tilia-inc.com/authorize/user \
  -H 'Authorization: Bearer <CLIENT_CREDENTIALS_ACCESS_TOKEN_HERE>' \
  -H 'Content-Type: application/json' \
  -d '{
    "account_id": "<USER_ACCOUNT_ID_HERE>",
    "return_token": true,
  }'

Example Responce Payload

Copy
Copied
{
    "status": "Success",
    "message": [],
    "codes": [],
    "payload": {
        "token": {
            "access_token": "USER_PASSWORD_TOKEN",
            "token_type": "Bearer",
            "refresh_token": "REFRESH_TOKEN",
            "expiry": "TOKEN_EXPIRATION"
        }
    }
}

Your api should return the access_token to your client application to use in the Tilia SDK. For more information on the /authorize/user endpoint go here

Swift Code Example

Copy
Copied
TLManager.shared.setToken("USER_PASSWORD_TOKEN")
TLManager.shared.getUserBalanceByCurrencyCode("USD") { result in print(result) }