Skip to content

Concepts

Errors and idempotency

Match the machine-readable error code, retry only what is safe to retry, and use idempotency keys so a retry never creates a second payment.

Error format

422 Unprocessable Entity
{
  "error": {
    "code": "validation_failed",
    "message": "Validation failed.",
    "field": "amountCents"
  }
}

Use error.code; messages can change. Validation errors name the field in error.field. An unknown top-level field is reported as body and an unknown customer field as customer. Malformed JSON and invalid headers return 400 invalid_request.

Error codes

HTTPCodeWhat to do
400invalid_request invalid_queryFix the JSON, headers or filters.
401unauthorizedCheck the full key, its environment, and that your account is active.
404not_foundCheck the ID and the key’s environment. Other merchants’ payments also return 404.
409idempotency_in_progressThe first request is still running. Retry later with the same key and body.
409idempotency_key_reusedThe key was used with a different body. Restore the original pairing; do not retry automatically.
409payment_in_progressAn attempt is processing. Poll the payment; do not charge again.
409action_requiredComplete the customer action first.
409confirmation_in_progressConfirmation is processing. Poll the payment.
409confirmation_not_requiredNothing to confirm. Read the current state.
409result_pendingThe previous result is being reconciled. Poll before submitting again.
410checkout_expired attempts_exhaustedCheckout is closed. Read the payment before deciding on a new checkout.
422validation_failedFix the field in error.field. An explicit environment must match the key.
422card_token_rejectedFix card capture, then read the checkout state before another attempt.
429rate_limitedWait for Retry-After and reduce concurrency.
503service_unavailableRetry with backoff within a limit, then escalate. It does not mean your key is invalid.

Errors describe the request, not the payment. A failed request never replaces reading the payment status.

Idempotency

POST /v1/payments and the sandbox simulation endpoints require an Idempotency-Key header: 16–255 visible ASCII characters, unique per order.

  • Store it first. Generate and save the key with the order before sending, so a retry after a crash reuses it.
  • Same key, same body: replays the original 201 response, with no second payment.
  • Same key, different body: 409 idempotency_key_reused.
  • Scope and lifetime: per merchant and operation, kept for 24 hours. Use different keys in sandbox and live.

Never create a new payment because a response was lost

Retry with the same key and body instead. Keep your own unique order constraint beyond the 24-hour window, and contact Wegopay if a response is still unknown near that limit.

Retry policy

  • On 429, wait for Retry-After. On 503, honour it when present; otherwise use exponential backoff with jitter.
  • On network errors, retry with the original key and body using the same backoff.
  • Stop after a bounded number of attempts and investigate.
  • Never log authorization headers, checkout URLs, signing secrets or payment payloads.