xtopaydocs

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.

400 Bad Request
{
  "success": false,
  "message": "Enter an amount of at least GH₵1",
  "code": "invalid"
}

Codes

HTTPcodeWhat it meansWhat to do
400invalidSomething in the request isn't rightFix it; message says what
401unauthorizedThe key is missing, wrong or rolledCheck your secret key
403forbiddenNot 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 offmessage says which
404not_foundThere's no such checkout, payment, transfer or refundCheck the ID or reference
409takenThat client_reference (or a checkout's reference) is already used, or an Idempotency-Key was used for a different requestUse a new one, or look up what you made before
400insufficient_balanceThere isn't enough available for a transfer (with its fee) or a refundWait for more payments to settle, or send less
400limit_exceededA transfer is over your business's limit per transfer, or would go over its limit per daySend less, or ask your owner to change the limits; message says which
429rate_limitedToo many requestsWait for the seconds in the Retry-After header
500server_errorSomething went wrong on our sideRetry after a moment
502, 503unavailableThe payment network didn't answer, or something isn't switched on yetRetry 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-Key header 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, marked Idempotent-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 gets 409 taken; find the first with GET /v1/payments?client_reference=… or GET /v1/transfers?client_reference=….

Wait a little longer between each retry (1 second, then 2, then 4), and give up after a few.

On this page