VNSwitch uses HTTP status codes to say whether a request worked, and returns a JSON body with an error object when it did not. Read the code to decide what to do: it is stable, while message is written for people and can change.

Response (HTTP 404)

{
  "error": {
    "type": "invalid_request",
    "message": "Payment does not exist in our records",
    "code": "HE_02"
  }
}

Error response format

FieldTypeDescription
error.typestringBroad category, see the table below.
error.codestringSpecific error code, for example IR_04 or HE_02. Use this in your code.
error.messagestringHuman-readable explanation. Log it; do not parse it.
error.reasonstringOptional extra detail, for example which provider rejected the request.
error.connectorstringOptional. The payment provider involved, for provider errors.
error.dataanyOptional extra data, for example the list of missing fields for IR_21.
error.payment_idstringOptional. The payment the error is about.

Values of error.type:

typeMeaning
invalid_requestThe request was wrong or not allowed: bad or missing fields, bad key, unknown object, wrong state.
apiSomething went wrong inside VNSwitch.
connectorThe payment provider returned an error. The HTTP status is the provider’s status.
blockedThe payment was blocked by a risk or blocklist rule.
integrity_check_failedThe provider’s response did not match the request (for example a different amount).

If the request body is not valid JSON, or a field has the wrong JSON type (for example a decimal number in amount), VNSwitch answers 400 with code IR_06. In this one case the category field is named error_type instead of type. Rely on error.code and the HTTP status, which are always present.

blocked and integrity_check_failed errors are returned with HTTP status 200. Always check for an error object in the body, not only the status code.

Error codes

Codes starting with IR_ are invalid requests, HE_ are errors found by VNSwitch while handling a valid request, and CE_ come from the payment provider.

HTTPCodeMeaningWhat to do
401IR_01API key missing or invalid.Check the api-key header and that you use the key for the right environment.
404IR_02Unknown URL.Check the path and the base URL.
405IR_03HTTP method not allowed for this URL.Check the method.
400IR_04A required parameter is missing. The message names it.Add the field.
422IR_05A field has the wrong format.Fix the field.
400 / 422IR_06Invalid request body or invalid data.Fix the request.
400IR_07A field has an invalid value.Fix the value.
400IR_08client_secret missing or expired.Create a new payment or fetch a fresh secret.
400IR_09client_secret does not belong to this payment.Use the secret of the same payment.
400IR_12Maximum number of refunds reached for this payment.Do not retry.
400IR_13Refund amount is more than the captured amount.Lower the amount; check earlier refunds.
400IR_14The object is in a state that does not allow this action (for example capturing a payment that already succeeded).Retrieve the object and check its status.
400IR_16A precondition for the action is not met. The message explains it.Fix the cause, then retry.
400IR_19Not supported (for example a payment method type).Use a supported option.
400IR_20The payment provider does not support this action.Use another flow or provider.
400IR_21Several required parameters are missing. data lists them.Add the fields.
403IR_22Your key is not allowed to access this resource.Check that the object belongs to your account.
400IR_28Currency not supported.Use a currency enabled for your account.
400IR_39No payment provider on your account can process this payment method.Contact info@nivc.ai to enable it.
400IR_52The payment session has expired.Create a new payment.
500HE_00Internal error in VNSwitch.Retry safely (see below).
400HE_01Duplicate: an object with this ID already exists (for example the same payment_id or refund).Do not create it again. Retrieve the existing object.
404HE_02The object does not exist (payment, refund, customer, mandate, payment method, payout, event).Check the ID and the environment.
400HE_03Validation failed (for example refunding a payment that has not succeeded, or mandate validation).Fix the cause; do not retry unchanged.
404HE_04Object not found (for example dispute, file, address, successful payment).Check the ID.
501IR_00Not available yet.Do not retry.
400CE_01Authorization with the provider failed.Ask the customer to try again or use another method.
400CE_02Authentication (for example 3-D Secure) with the provider failed.Ask the customer to try again.
400CE_03Capture failed at the provider.Retrieve the payment, then decide.
400CE_04The card data is invalid.Ask the customer to check the card details.
400CE_05The card has expired.Ask for another card.
400CE_06Refund failed at the provider.Retrieve the refund, then decide.
Provider’sCE_00Other error from the payment provider. connector and reason give details.Log it; retry only if the status is 5xx.
200HE_03 (type blocked)The payment was blocked by a blocklist rule.Do not retry.
200IE_00Integrity check failed.Retrieve the object and contact info@nivc.ai.

A payment that the bank or provider declines is not always an API error. Often the request succeeds (HTTP 200) and the payment has status: “failed” with error_code and error_message fields. Handle both cases. See Payment lifecycle.

Retry failed requests safely

Money must never move twice because you retried. Follow these rules:

  • Never retry a 4xx error unchanged. It fails again. Fix the request first. HE_01 (duplicate) means the first request already worked: retrieve the object instead.
  • 5xx errors, timeouts and network failures are unknown outcomes. The request may or may not have been processed. Before you send it again, find out what happened:
    • If you set your own payment_id when creating the payment, retry with the same payment_id. If the first attempt went through, you get HE_01 instead of a second payment; then retrieve the payment.
    • For other actions (confirm, capture, refund, payout), retrieve the object first and check its status. Only repeat the action if it did not happen.
  • Back off between retries, for example 1, 2, 4 and 8 seconds, and stop after a few tries.
  • Do not retry blocked, IR_12, IR_13 or card errors (CE_04, CE_05). These need a different request or a different payment method.
  • Treat webhooks as the source of truth for results that arrive later. See Webhooks.

Log error.code, error.message and the object ID for every error. Include them when you contact info@nivc.ai.