Errors and retries
How the API says something went wrong, what each code means, and how to retry safely.
When a request fails, success is false, message says what's wrong in
words you can show a person, and code says what kind of failure it is.
{
"success": false,
"message": "Enter an amount of at least GH₵1",
"code": "invalid"
}Codes
| HTTP | code | What it means | What to do |
|---|---|---|---|
| 400 | invalid | Something in the request isn't right | Fix it; message says what |
| 401 | unauthorized | The key is missing, wrong or rolled | Check your secret key |
| 403 | forbidden | Not allowed: the request came from an address that isn't on the key's allowlist, a live charge or transfer needs a verified business or an allowlist, or sending money is switched off | message says which |
| 404 | not_found | There's no such checkout, payment, transfer or refund | Check the ID or reference |
| 409 | taken | That client_reference (or a checkout's reference) is already used, or an Idempotency-Key was used for a different request | Use a new one, or look up what you made before |
| 400 | insufficient_balance | There isn't enough available for a transfer (with its fee) or a refund | Wait for more payments to settle, or send less |
| 400 | limit_exceeded | A transfer is over your business's limit per transfer, or would go over its limit per day | Send less, or ask your owner to change the limits; message says which |
| 429 | rate_limited | Too many requests | Wait for the seconds in the Retry-After header |
| 500 | server_error | Something went wrong on our side | Retry after a moment |
| 502, 503 | unavailable | The payment network didn't answer, or something isn't switched on yet | Retry later; message says which |
Retrying safely
Networks fail: a request can time out after Xtopay has done the work. Retrying is safe when you can't charge twice:
- Send an
Idempotency-Keyheader on every POST: a value you make once per action, like an order or USSD session number. A retry with the same key within 24 hours gets the first answer back, markedIdempotent-Replayed: true, and nothing happens twice. Only successful answers are kept: if the first request was refused, put it right and send it again with the same key. - Give charges and transfers a
client_reference. A second one with the same one gets409 taken; find the first withGET /v1/payments?client_reference=…orGET /v1/transfers?client_reference=….
Wait a little longer between each retry (1 second, then 2, then 4), and give up after a few.