Fetch and return available balance of Stripe account
Submitted by:
Karen Stepanyan
This function will fetch Stripe account available balance of particular currency.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const apiKey = secrets.API_KEY
const balanceCurrency = args[0] || 'usd'
if (!apiKey) {
throw Error("Stripe API Key is required")
}
const config = {
url: `https://${apiKey}@api.stripe.com/v1/balance`,
}
const response = await Functions.makeHttpRequest(config)
const balance = response.data.available.find(c => c.currency.toLowerCase() === balanceCurrency.toLowerCase())
const balanceInCents = Math.round(balance.amount * 100)
return Functions.encodeUint256(balanceInCents)