Error handling

Errors

Every Paga API answers in two layers: the HTTP status says whether your request was accepted, and a response code in the body says what happened to the transaction. Handle both and you’ll never mistake a pending payment for a failed one.

The one rule to remember. A response/status code of 0 means success. Every other code needs looking up in the code list for that API before you act: some mean failed, but others mean pending, duplicate reference or another in-between state. An HTTP 200 on its own is not a success.

How to read any response

Use the same three checks for every API. Only the field names differ.

Check the HTTP status

401, 400, 403 or 500 means the request itself failed. See HTTP errors.

Read the response code in the body

statusCodeLook the code up in that API’s code list, then act on what it meansponseCode` for the Business API and Merchant Services.

Act on the code

Look the code up in that API’s code list, then act on what it means.

Success

Code 0. Fulfil the order or credit the customer.

<PagaTile labelLook it up" tone="failed">

Any other code. Check the code list before acting: it may mean failed, pending or duplicate. Never refund or resend on a non-zero code alonh the same reference. Don’t retry.

Look it up

Any other code. Check the code list before acting: it may mean failed, pending or duplicate. Never refund or resend on a non-zero code alone.

Response codes by API

Each API family has its own code list, which says what every code means and which ones are pending. Look up codes for the endpoint you called.

EndpointsCode fieldCode list
Collect API and Direct DebitstatusCodeCollect API status codes
Business APIresponseCodeBusiness API error codes
Merchant Services and Merchant Notification APIresponseCodeMerchant Service API error codes

HTTP errors

These come before any response code. The request didn’t reach the point where a transaction could be processed.

StatusWhat it meansWhat to doRetry?
401 UnauthorizedWrong keys, or keys that don’t match the environment’s base URLCheck keys and base URL. See AuthenticationAfter fixing
400 Bad RequestA value broke a validation rule. Most often the hashRecreate the hash with the exact values and order. Check required fieldsAfter fixing
403 ForbiddenRequest came from an IP address that isn’t whitelistedAdd the server’s IP. See IP whitelistingAfter fixing
500 Internal Server ErrorPaga couldn’t process the requestCheck status first, then retry with backoff. Contact support if it continuesYes, carefully
{
  "error": "Invalid paga account id or password"
}

Situations you should always handle

These come up across products. Find the matching code in the code list for your endpoint, and plan a response for each before you go live.

SituationWhat to do
Duplicate referenceDon’t resend. The first request may have succeeded. Check status with the original reference
Insufficient balanceStop and alert your team to fund the account. Retrying won’t help
Account or transaction limitSplit the amount or ask Paga to review your limits
Invalid bank or accountAsk the customer to check their details. Validate accounts before paying out
Reference too longKeep references to 50 characters or fewer
Partial paymentThe customer paid less than requested. Decide whether to accept, top up, or refund
Unknown errorTreat as pending, not failed. Check status before doing anything else

Retries and duplicate payments

Most double payments happen when a request times out and gets sent again. Your reference number is what prevents it.

One reference per transaction

Give every transaction a unique referenceNumber of up to 50 characters, and store it before you send the request.

Timed out? Check, don’t resend

If you get no response, check status with the same reference. Only send a new request if Paga has no record of it.

Retry with backoff

For HTTP 500s, wait a few seconds and double the wait each time. See Best practices.

Never retry a final failure

Fix the cause first, such as funding the account or correcting details, then start a new transaction with a new reference.

🚧

Show customers a clear message, not the raw error

Map each code to a message your customers understand, and log the full response, including the reference number, so your team and Paga support can trace it.

Need help? We’re here 24/7

Talk to our support team any time, or ask questions in the developer community.


What’s Next