Billing
Top Up
Top-ups add prepaid credit to the account by charging one of its saved cards. There are three kinds: balance, the money that pays for calls (and, on pre-pay accounts, for messages); call credit, the older name of the same balance; and SMS credits, bought in packages. Each kind has a one-off top-up, a calculate preview of the price with VAT, and an automatic top-up configuration that NUACOM charges when the balance drops to a limit. The cards come from Payments; the SMS packages and what the credits buy are in Conversations / SMS.
Workflow (what the portal does)
The portal's Balance Top Up page:
- Preview the price:
POST /v2/top-up/balance/calculatewithamount, an integer from 1 to 9999 in the account's billing currency (billing.billing_currencyon the account info), answers{"amount": 20.0, "vat_rate": 0.23, "vat": 4.6, "total": 24.6}.vat_rateis the rate in force today for the account's VAT type (0when none applies);vatandtotalare rounded to two decimals. The portal recalculates as the amount changes. - Charge the card:
POST /v2/top-up/balancewith the sameamountandpayment_method, theidof one of the account's cards fromGET /v2/payments.totalis charged to the card at once, without the cardholder present, and the answer is204with no body. The balance is credited shortly after, when Stripe's confirmation reaches NUACOM, and a receipt is emailed to the account's billing address. - Watch the balance: the portal polls the balance until it changes. Read
billing.account_balanceonGET /v2/account_info. - Automatic top-up:
GET /v2/top-up/auto/balancereturns the configuration, or204when there is none.POST /v2/top-up/auto/balancewithamount(1–9999),balance_limit(an integer of at least 1) andpayment_methodcreates or replaces it and answers204: whenever the balance is at or belowbalance_limit, NUACOM chargesamountplus VAT to that card.DELETE /v2/top-up/auto/balanceswitches it off (204, also when nothing was configured).
The call credit endpoints, POST /v2/top-up/call/calculate, POST /v2/top-up/call and the GET, POST and DELETE /v2/top-up/auto/call configuration, take the same inputs (credit_limit in place of balance_limit), and a top-up through them credits the same balance; they are the older Call Credit Top Up page. Use the balance endpoints for new work.
The portal's SMS Top Up page:
- Pick a package:
GET /v2/sms/packageslists them withid,amountof credits andcost, at the account's own prices where NUACOM has agreed some. - Preview:
POST /v2/top-up/sms/calculatewithpackage_idquotes the package'scostasamount, withvat_rate,vatandtotal. - Charge:
POST /v2/top-up/smswithpackage_idandpayment_methodchargestotalto the card (204). The credits are added when the confirmation arrives and show inbilling.sms_balanceon the account info; they stay valid for one year from the purchase. - Automatic top-up:
GET,POST /v2/top-up/auto/sms(package_id,credit_limit,payment_method) andDELETE /v2/top-up/auto/smsstore an SMS configuration. Read Pitfalls before relying on it.
curl -X POST https://api.api-nuacom.com/v2/top-up/balance \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"amount": 20, "payment_method": "pm_1AbCdEfGhIjKlMnOpQrStUvW"}'
Reading a configuration
An automatic top-up configuration carries id, account_id, user_id (the admin who saved it), payment_type (2 for a Stripe card, 1 for a card held with NUACOM's earlier card records), payment_method (the pm_… id, or the legacy card reference), amount on the balance and call kinds or package_id on the SMS kind, balance_limit or credit_limit, and set_time, when it was last saved.
How the automatic top-up runs
flowchart TD
trigger["Call ends, or SMS/MMS/WhatsApp message sent (scheduled or bulk included)"] --> compare{"balance <= balance_limit?"}
compare -- "no" --> skip["No charge"]
compare -- "yes" --> charge["Charge amount + VAT to saved card"]
charge -- "success" --> credited["Balance credited"]
charge -- "card reports no longer usable" --> removed["Configuration removed at once"]
charge -- "declined" --> retry1["Retry 1, 5 minutes later<br/>billing address emailed"]
retry1 -- "success" --> credited
retry1 -- "declined" --> retry2["Retry 2, 5 minutes later"]
retry2 -- "success" --> credited
retry2 -- "declined" --> removed
- It runs after a call ends and after an SMS, MMS or WhatsApp message is sent, scheduled and bulk sends included. It reads the balance configuration, compares the account balance with
balance_limitand, at or below it, chargesamountplus VAT to the saved card without the cardholder present. One attempt runs at a time. - A declined card is retried twice, five minutes apart. The billing address is emailed about the failure (a card that needs 3-D Secure gets an email asking to authenticate it). After the third failure the configuration is removed, and saving it again is what re-enables it. A card that Stripe reports as no longer usable is not retried: the configuration is removed at the first failure.
Roles and access
- Every endpoint in this group needs an account admin: the user behind the token must be an admin of the account, or the answer is
403with the body"Forbidden". - The API does not look at the account's billing type: it accepts a top-up from a bill-pay account as readily as from a pre-pay one. Which pages the portal shows is the portal's decision.
- The ISO dates option (per account) switches
set_timeto ISO 8601 in the requested timezone.
Pitfalls
204means the card was charged, not that the balance has moved. The credit lands when Stripe's confirmation arrives, shortly after; poll the account info rather than repeating the top-up.- Two payment failures answer
400with anerror_code:PAYMENT-DECLINED(messagecarries the card provider's reason) andPAYMENT-INCOMPLETE(the payment needs the cardholder;incomplete_payment.client_secretidentifies it, and the portal completes it with Stripe.js in the browser). Nothing is credited until the payment succeeds; a completedPAYMENT-INCOMPLETEpayment is credited through the same confirmation. See Errors. payment_methodmust be one of the account's cards, else422witherrors.payment_method"Payment method does not exists". The threeautosave endpoints also accept a saved card reference from an earlier card record, but the automatic top-up this API runs charges Stripe cards only: save apm_…id.- Only the balance configuration drives the automatic top-up that runs after calls and messages. The call and SMS configurations are stored and returned for the older portal pages, but no charge is made from them through this API.
amountis an integer:20.50is refused with422, and9999is the maximum per top-up.- A card referenced by any of the three configurations cannot be deleted from Payments until the configuration points at another card.
GET /v2/top-up/auto/…answers204, not404ornull, when nothing is configured;DELETEanswers204even then.- SMS credits expire one year after purchase.