How to fetch user's funds?

smallcase Gateway partners can now fetch funds available in users' broking account.

📘

The workflow is quite similar to other transactional intents that we have (like transaction, connect).

Steps to fetch funds:

1. Create transactionId from backend

Create a transactionId to fetch funds by making a POST request to /gateway/<gatewayname>/transaction endpoint by passing appropriate headers & body params.

Headers

  1. x-gateway-secret : this is apiSecret shared for authentication
  2. x-gateway-authtoken : JWT signed with shared secret & payload of connected user

Body Params

{
    "intent": "FETCH_FUNDS"
}

sample cURL

curl --location --request POST 'https://gatewayapi.smallcase.com/gateway/gatewayname/transaction' \
--header 'x-gateway-secret: ironmanisalive' \
--header 'x-gateway-authtoken: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzbWFsbGNhc2VBdXRoSWQiOiJzdXBwb3J0QHNtYWxsY2FzZS5jb20iLCJpYXQiOjE2MjI3MTc0NjcsImV4cCI6MTY0MjcyMTA2N30.AuDtMODEWQfIpDyldz6h44MaBwJaIOAoV-5-lRtyCBQ' \
--header 'Content-Type: application/json' \
--data-raw '{
    "intent": "FETCH_FUNDS"
}'

📘

Note

  1. Fetch Funds works for connected users only. Make sure to pass authtoken with smallcaseAuthId (and not guest: true)

  2. This request to generate transactionId through Gateway API must be done from the backend platform (not client interface). This is to ensure that the secrets are not exposed

2. Call triggerTransaction SDK method on client side

scGateway.triggerTransaction({
  transactionId: <transactionId>
})
.then(res => res)
.catch(err => err)

At this point, SDK will ask the user to do broker login (if not already) and then fetch funds from their broker account. Once the process completes, SDK will resolve the promise. And you can find funds data in then block in the above example.

Sample response

{
    "success": true,
    "errors": null,
    "data": {
        "funds": 1234.5
    }
}

👍

Done

You can now store this funds response in your database and use it on your UI until the next time funds are fetched.


Broker support

All brokers support fetching funds, other than the exception of bank-based brokers (Axis Sec., HDFC Sec.).

In the case of bank brokers, funds' value will always be zero. They do this for security reasons, as the available funds is actually the user's bank balance.