Skip to content
Last updated

Errors and retries

Two different things can go wrong with a payment, and they look nothing alike.

  • The request failed. The API returns a 4xx or 5xx with an error body. Nothing was charged.
  • The payment was declined. The API returns 200 with a transaction whose result is DECLINED. The request worked; the issuer said no.

This page is about the first. For the second, see Handle declines.

The error envelope

Every failure returns the same four fields.

{
  "error_code": "INVALID_REQUEST_DATA",
  "error_message": "The API request contains invalid data.",
  "details": {
    "amount": "Invalid amount",
    "payment_method.pan": "Malformed PAN"
  },
  "source": {
    "system": "TSYS",
    "code": "13",
    "message": "Invalid amount"
  }
}
FieldWhat it carries
error_codeThe stable code to branch on. Always present
error_messageThat code in words, for a log
detailsField name to problem, when the failure was about specific fields. A few codes use named keys instead, listed in API response codes. Otherwise null
sourceThe processor's own code and text, passed through unchanged. Null when the gateway raised the error itself

Branch on error_code, never on error_message. The message is prose and may be reworded. The code is part of the contract.

source is for your support and reconciliation, not for your control flow. It tells you what TSYS or VeriCheck said, in their vocabulary, so a support ticket can quote it.

The codes

Fifteen, and that is the whole list. The status tells you the kind of failure, and the code tells you which one.

Statuserror_codeWhat happenedSafe to retry
400INVALID_REQUEST_DATAA field is present and its value is unusable. details names the fieldsNo — fix the request
400REQUIRED_DATA_MISSINGA required field is absentNo — supply the field
400INVALID_ACTIONThe operation does not apply to the transaction's current state, such as capturing a saleNo — read the transaction first
400AMOUNT_LIMIT_EXCEEDEDA single amount is outside the allowed rangeNo
400VELOCITY_LIMIT_EXCEEDEDA count or dollar cap over a period is spent. details names the limitNot until the period resets
401NOT_AUTHENTICATEDApi-Key or Client-Id is missing or wrongNo — check both headers
403UNAUTHORIZED_ACTIONAuthenticated, but not allowed to do thisNo
403PROCESSOR_NOT_CONFIGUREDThe merchant is not boarded to the processor this payment routes to. details names bothNo — not until the merchant is boarded
404RESOURCE_NOT_FOUNDNo such transaction, client, or integrationNo — check the ID
409DUPLICATE_ACTIONThe same operation was already done, or is underway, such as canceling a transaction twiceNo
429TOO_MANY_REQUESTSThe processor's request limit for the merchant was exceeded, and the transaction was not attemptedYes, with backoff
500SYSTEM_ERRORA fault inside the gatewayYes, but read the next section first
500INTEGRATION_CONFIG_ERRORThe merchant's stored integration record is wrongNo — not until it is corrected
502DOWNSTREAM_ERRORThe gateway reached the processor and could not use its replyYes, but read the next section first
503PROCESSOR_UNAVAILABLEThe processor is down or unreachable, and did not process the requestYes, with backoff

error_code is a plain string, so treat this list as one that can grow. Handle a code you do not recognize by falling back on the HTTP status.

A 401 does not distinguish a missing header from a wrong key. If you get one, check that both Api-Key and Client-Id are present before assuming the key is bad — a missing Client-Id produces the same answer.

Not every operation can return every code. 404 is declared on 11 of the 19 operations, 409 on 7, and 502 on only 4: creating, capturing, and canceling a transaction, and closing a batch. 429 and 503 are declared on 2 each: creating and canceling a transaction.

500, 502 and 503 are not the same

This is the distinction that matters when money is involved.

  • A 500 with SYSTEM_ERROR is a fault inside the gateway. The fault can come after the processor accepted the transaction, so the transaction may exist.
  • A 502 means the gateway reached the processor and could not use what came back. The processor may have seen the transaction.
  • A 503 means the processor is down or could not be reached, and never received the request. No transaction exists.

All three are safe to retry in the sense that the API will accept the request again. A 500 and a 502 need a check first. A 503 does not.

After a 500 or a 502 on a payment, reconcile before retrying. Call GET /v1/transactions filtered to the window in question and look for a transaction matching what you sent. The API has no idempotency key, so a retry that the first attempt already completed creates a second charge.

Retrying

Retry 429 and 503 after a backoff, and a 502 or a 500 carrying SYSTEM_ERROR once you have reconciled. Do not retry 400, 401, 403, 404, or 409, or a 500 carrying INTEGRATION_CONFIG_ERROR — the request will fail the same way until something changes.

Use exponential backoff with jitter: wait a short interval, double it each attempt, and add a small random offset so a fleet of clients does not retry in lockstep. Three or four attempts is usually enough; past that, the failure is not transient.

A 429 is the processor's limit, not ours. The gateway sets no rate limit of its own. A 429 with TOO_MANY_REQUESTS means VeriCheck's request limit for the merchant was exceeded on a bank account payment, and the transaction was not attempted, so a retry after a backoff cannot charge twice. No Retry-After header is sent, because no processor says how long its limits last.

Every response carries a request ID

Successful or not, every response includes an x-request-id header holding a GUID.

x-request-id: 73039bd9-c380-4186-bffe-259125144a56

Log it with every request you send. It is what lets support trace one specific call through the gateway. A support ticket without it usually turns into a request for it.

What to show a person

Do not put error_code, response_code, or anything from source in front of a cardholder. "Do not honor" and 51 mean nothing to them and sometimes imply something untrue about their account.

Map to a short, actionable sentence — "That card was declined. Try another card" — and keep the codes in your logs, where they are useful.

Next steps