Balance

Checking Balance via the API

To determine if a user's balance has changed before making calls to retrieve real-time balance data, follow these steps:

  1. Initiate a POST request to <https://api.flick.co/v2/balance/check> with the account_id as one of the parameters. This request will allow you to verify and track any changes in the user's account balance.
curl -X POST https://api.flick.co/v2/balance/check
-H 'Content-Type: application/json' 
-H 'Authorization: Bearer <secretKey>'
-d '{ 
			account_id: "xxxxxxxxxxxx" 
		}'
  1. After two minutes, make a GET request to data.callback_url in the response in step 1

Request

curl -X GET https://api.flick.co/v2/callback?record={recordId}&method=CHECK_BALANCE
-H 'Content-Type: application/json' 
-H 'Authorization: Bearer <secretKey>'

Response

{
    "status": "success",
    "message": "Successfully checked balance",
    "data": {
        "balance_changed": false,
        "last_checked": "2021-07-16T14:20:05.968Z",
        "last_fetched": "2021-07-15T01:02:01.615Z"
    }
}
Announcement Box

   Add a debounce of about 60 seconds to accommodate for banks with duplicate delays


Balance callback

Refreshing a balance may not provide an instantaneous response because it involves interactions with the customer's financial institution. Instead, you will receive a callback_url as part of the JSON response. You can refer to an example on how to handle this response and retrieve the updated balance in real-time.

For detailed instructions on how this process works, please check the API Reference, which will provide you with a comprehensive understanding of the procedures involved.

Request

exports.fetchBalance = async (req, res, next) => {
    req.setTimeout(0)
    const baseURL = 'https://api.flick.co/v2' 
    const { account_id, waitTime } = req.body //waitTime is in minutes
    const token = `Your_JWT_token`
    let config = {
        headers: {
            'Content-Type': 'application/json',
            Authorization: `Bearer ${token}`
        }
    }
    const getBalanceReq = () => {
        try {
            return axios.post(`${baseURL}/balance/refresh`, { account_id: account_id },config)
        } catch (error) {
            console.error(error)
        }
    }
    const getCallBackData = (data) => {
        try {
            return axios.get(data, config)
        } catch (error) {
            console.error(error)
        }
    }
    const getCallBackReq = async () => {
        getBalanceReq()
            .then(async response  => {
                if (response.data.data) {
                    await waitFor(waitTime * 60000) // covert minutes to milliseconds
                    return [ response.data.data.callback_url.replace("undefined", "callback")].join('')
                }
            }).then(callBack => {
                getCallBackData(callBack)
                    .then(response => {
                       res.json(response.data)
                    })
                    .catch(error => {
                        console.log(error)
                    })
            })
            .catch(error => {
                console.log(error)
            })
    }
    getCallBackReq()
}

const waitFor = (ms) => new Promise(r => setTimeout(r, ms))

Response

{
    "status": "success",
    "message": "Successfully checked balance",
    "data": {
        "balance_changed": true,
        "last_checked": "Fri Jan 01 2021 21:25:05 GMT-0500"
    }
}

Current and periodic balance

The balance information typically includes both ledger and available balances. In scenarios involving fraud detection and prevention of insufficient funds (NSF), it is advisable to use the available balance. This is because the available balance reflects the predicted balance after accounting for any pending transactions, whereas the ledger balance does not consider pending transactions.

The available balance represents the funds that are accessible for spending and may not necessarily equate to the total account value. Occasionally, a financial institution may not provide available balance information.

In such cases, you can calculate the available balance by starting with the current balance and then using our Transaction product to identify any pending transactions. Adjust the balance accordingly based on these pending transactions.

🚀Now that you have a better understanding of how balance works, you can explore the API Reference page to test the balance API in real-time. This will allow you to put your knowledge into practice and seamlessly integrate balance information into your applications.


Parameters

Field

Description

id ObjectID

Unique Auth ID (Unique Flick Identifier)

available_balance
Number

Amount of Available Funds in the Account

ledger_balance
Number

The Closing Balance of the Account

account
ObjectID

Unique Account ID (Unique Flick Identifier)

connected
Boolean

Customer Connection Status (Did they Choose to Connect this Account to You?)

customer
ObjectID

Unique Customer ID (Unique Flick Identifier)

record
ObjectID

Unique Record ID (Unique Flick Identifier)

owner
ObjectID

Unique Company ID (Unique Flick Identifier) (Your Client Token)

env
String

Flick API Env the Auth was Pulled from production or production-sandbox

created_at
Date

Date of Authentication

last_updated
Object

Last Date of Authentication