Money
How amounts are written in requests, responses and webhooks.
Every amount is a JSON integer in the currency's smallest unit, called the minor unit.
Tanzanian shillings (TZS) have 0 decimals, so the minor unit is one shilling and 10000 means TZS 10,000.
{
"amount": 10000,
"currency": "TZS"
}This holds in requests, in responses and in webhook events. Fees and balances are amounts too:
{
"currency": "TZS",
"available": 480,
"held": 0
}Do not send an amount as a string, and do not add decimals. 10000.0000 and "10000" are not amounts the API accepts.
Amounts that need more than the minor unit
A price can cost less than one unit, such as TZS 0.5 for each call you meter. For these prices, billing has a second field that ends in
Decimal. It is a string with up to 12 decimal places:
{
"currency": "TZS",
"unitAmountDecimal": "0.5"
}When you create such a price, send either unitAmount or unitAmountDecimal, never both. Invoice lines and payments are
always whole amounts in the minor unit.
A wrong amount
A request with a non-integer number in an amount field is refused with 400, the code amount_invalid and the field in
param:
{
"error": {
"type": "invalid_request_error",
"code": "amount_invalid",
"message": "amount must be an integer in the currency's minor unit, for example 10000 for TZS 10,000",
"param": "amount",
"requestId": "req_4f1c2a9e8b7d4c3a9f0e1d2c3b4a5f6e"
}
}A ...Decimal field that is not a decimal string with up to 12 places gets the same code, with the message
unitAmountDecimal must be a decimal string with up to 12 decimal places.
Reading amounts
Read every amount as an integer. In JavaScript, a JSON integer is read exactly up to 9,007,199,254,740,991, which is far
more than any payment. Compare ...Decimal fields as strings or with a decimal library, never as floating point numbers.