Skip to main content

Error Reference

All API errors return a JSON body with an error field (string code) and optionally a details field with field-level validation messages.


Error response format

{
"error": "bad_request",
"details": {
"amount": ["can't be blank"],
"currency": ["is invalid"]
}
}

HTTP status codes

CodeMeaningCommon cause
400Bad RequestMalformed JSON or missing required fields
401UnauthorizedMissing or invalid x-api-key / Bearer token
403ForbiddenValid credentials but no permission for this resource
404Not FoundTransaction or resource with given ID does not exist
409ConflictDuplicate txid — a transaction with this ID already exists
422Unprocessable EntityValidation failed — check details
429Too Many RequestsRate limit exceeded
500Internal Server ErrorPlatform error — contact support with transaction ID

Transaction error codes

These appear in error_description within webhook payloads and transaction status responses:

CodeMeaningRecommended action
insufficient_fundsCard declined: insufficient fundsAsk payer to use another card
card_declinedCard declined by issuerAsk payer to contact their bank
expired_cardCard expiry date has passedAsk payer to update card details
invalid_card_numberCard number is invalidCheck card number format
invalid_cvvCVV is incorrectAsk payer to re-enter CVV
do_not_honourGeneric bank declineAsk payer to contact their bank
lost_cardCard reported lostDo not retry
stolen_cardCard reported stolenDo not retry
restricted_cardCard cannot be used for this transactionAsk payer to use another card
transaction_limit_exceededAmount exceeds card/account limitsAsk payer to use another payment method
3ds_failed3D Secure authentication failedAsk payer to retry or use another card
3ds_timeout3D Secure timed outRetry the transaction
provider_unavailablePayment provider is temporarily unavailableRetry after a delay
routing_failedNo provider found for this transactionContact your platform operator
duplicate_txidtxid already exists for this terminalUse a unique txid per transaction
currency_not_supportedCurrency not supported by this terminalCheck terminal configuration
amount_too_lowAmount below minimum for this providerIncrease transaction amount
amount_too_highAmount above maximum for this providerSplit into smaller transactions
antifraud_rejectBlocked by anti-fraud rulesContact your platform operator

Validation errors (422)

Validation errors include a details map with field-level messages:

{
"error": "unprocessable_entity",
"details": {
"params.amount": ["can't be blank", "must be greater than 0"],
"params.currency": ["is invalid — use ISO 4217 code"],
"params.txid": ["has already been taken"]
}
}

Handling errors in your code

Retry strategy

Error typeRetry?Notes
provider_unavailable✅ YesWait 30–60 seconds, max 3 retries
3ds_timeout✅ YesRetry once immediately
insufficient_funds❌ NoShow alternative payment method
card_declined❌ NoShow alternative payment method
lost_card, stolen_card❌ NeverDo not retry or re-present
duplicate_txid❌ NoGenerate a new unique txid
routing_failed❌ NoContact your platform operator

Example error handling (Python)

import requests

response = requests.post(
'https://4pay.online/api/v1/transactions',
headers={'x-api-key': 'YOUR_API_KEY', 'Content-Type': 'application/json'},
json={'params': {'type': 'payment', 'amount': 1000, 'currency': 'USD', 'txid': 'order-1'}}
)

if response.status_code == 422:
errors = response.json().get('details', {})
for field, messages in errors.items():
print(f"{field}: {', '.join(messages)}")
elif response.status_code == 409:
print("Duplicate txid — use a unique order ID")
elif response.status_code >= 500:
print("Platform error — retry later or contact support")
else:
tx = response.json()
print(f"Transaction created: {tx['id']}")

Contact support

For persistent errors or unexpected 500 responses, contact: