Skip to content

Handle Senfenico API errors

Every response is a success, a refusal or an unknown outcome. A refusal is not resent as is, and an unknown outcome is checked before any new attempt.

Success:

{
"status": true,
"message": "Charge attempted",
"data": { "reference": "CH261126-101502-ORANGE_BF-8b41079ee8", "status": "send_otp" }
}

Business or validation failure:

{
"status": false,
"message": "Invalid data provided. Please check the input and try again.",
"error_code": "INVALID_DATA",
"errors": {
"amount": ["Ensure this value is greater than or equal to 100."],
"payment_method_details": {
"phone": ["Phone number must be 8 digits long."]
}
}
}
  • Base your logic on error_code, never on message (technical English text that may change).
  • errors is only present for validation errors; it can be nested.
  • Responses have no description or description_fr field. The text shown to the customer is yours to write.
HTTP Typical cases Body
200 Successful read; result of POST /charges/submit (success or failure); charge initialization refused by the operator envelope, status true or false
201 Charge, checkout or transfer created envelope, status: true
202 Bulk transfer accepted (see failed_transfers) envelope
400 INVALID_DATA, BATCH_SIZE_LIMIT_EXCEEDED, UNSUPPORTED_PROVIDER envelope + optional errors
403 Missing or invalid key; IP_NOT_ALLOWED; MERCHANT_INSUFFICIENT_FUNDS; more rarely UNAUTHORIZED_CHARGE_PROVIDER envelope, status as a string for a refused key
404 Object not found, or created in the other mode (test/live) envelope, sometimes without error_code
429 Too many requests {"detail": "…"}, not the envelope
500 INTERNAL_ERROR, or an unexpected error envelope, or an HTML page

A refused key returns "status": "False" as a string: compare strictly to true and test the HTTP code first (see Missing or invalid key).

Outcome Condition Action
Success HTTP 2xx and status === true carry on
Refused HTTP 400, 403, 404, or HTTP 200 with status: false don’t resend the same request; fix it or tell the customer
Unknown timeout, network failure, HTTP 5xx, non-JSON body check before any new create
Slow down HTTP 429 wait, then retry
/** 'ok' | 'refused' | 'unknown' | 'throttled' */
function classify(int $http, ?array $json): string
{
if ($http === 0 || $http >= 500 || $json === null) {
return 'unknown'; // network, 5xx, HTML
}
if ($http === 429) {
return 'throttled';
}
if ($http >= 200 && $http < 300 && ($json['status'] ?? null) === true) {
return 'ok';
}
return 'refused';
}

Base your logic on error_code. For each code, Error codes gives the cause, a message to show the customer and what to do next. Never show the raw message, which is technical English.

Two cases need special care. CHARGE_NOT_FOUND after /charges/submit can mean the charge is already paid, so re-read it before showing anything. MERCHANT_INSUFFICIENT_FUNDS (HTTP 403) is about your own balance, and no transfer was created.

Creating a charge calls the operator and can take several tens of seconds. Set a 90 s timeout on charge creation and OTP submission, never less than 60 s (see Limits), and 20 s on reads. If your code gives up before the response, the charge may exist, and resending it would create a second one. Search for it by ext_id first, following Search before recreating, which gives the code and also covers transfers, /charges/submit and checkouts.

  • Every response is classified: success (2xx and status === true), refused, unknown, slow down.
  • status is compared strictly to true (authentication errors return the string "False").
  • Non-JSON bodies (429, HTML 500) don’t crash your code.
  • Logic relies on error_code, and the customer sees a message you wrote.
  • A charge initialization with HTTP 200 and status: false is treated as a failure.
  • After an unknown outcome, you search by ext_id before recreating a charge or transfer.
  • CHARGE_NOT_FOUND after a submit triggers a re-read of the charge.