Key concepts

Idempotency

Nexpay supports idempotent requests for financial mutation endpoints, allowing you to safely retry requests without the risk of performing the same operation twice. This is especially important for payment operations where network issues or timeouts may leave you uncertain whether a request was processed.


How it works

Financial mutation endpoints support idempotency — most importantly submitting a payment intent (POST /v2/payment-intents/{id}/submit). Nexpay uses two mechanisms to prevent duplicates:

  1. Idempotency key (recommended) -- You provide an explicit key via the Idempotency-Key header.
  2. Automatic fingerprinting -- If no key is provided, Nexpay automatically generates a fingerprint based on the request body to detect identical requests.

When an idempotency key is provided, it takes precedence over automatic fingerprinting.


Using the Idempotency-Key header

Include the Idempotency-Key header in your request with a unique value (e.g. a UUID) that identifies the intended operation:

curl -X POST 'https://api.nexpay.com.au/v2/payment-intents/507f1f77bcf86cd799439011/submit' \
  -H 'X-API-Key: nxp_ck_your-client-id:nxp_sk_your-secret' \
  -H 'Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000'

Submit is idempotent; Create is not

POST /v2/payment-intents/{id}/submit is the idempotent call. POST /v2/payment-intents (Create) is not — a retried Create produces a second draft intent. See Manual payment with splits.


Behavior

ScenarioResult
First request with a given keyRequest is processed normally and the response is cached.
Retry with the same key and the same bodyThe cached response from the original request is returned. The operation is not executed again.
Same key but different request bodyHTTP 422 Unprocessable Entity is returned. This prevents replay attacks where a previously used key is reused with a modified amount or other parameters.
No Idempotency-Key header providedNexpay automatically detects duplicate requests by fingerprinting the request body. Identical requests within the deduplication window are treated as retries.

Key reuse with different body

If you send a request with the same Idempotency-Key but a different request body, Nexpay will reject it with HTTP 422. Always generate a new key for each unique operation.


Best practices

  • Generate a unique key per operation -- Use a UUID or another unique identifier for each distinct payment. Do not reuse keys across different operations.

  • Store keys alongside your records -- Save the idempotency key with the corresponding record in your system so you can reliably retry with the same key if needed.

  • Retry safely on network errors -- If a request times out or you receive a network error, retry with the same Idempotency-Key to safely determine whether the original request was processed.

  • Keys expire after 24 hours -- Idempotency keys are valid for 24 hours after the first request. After expiry, the same key may be reused for a new operation; an expired key replayed within the same 24h window returns the originally cached response.

  • Which errors bind the key, which release it — Some errors lock the key to a failed-response replay; others leave the key un-engaged so a retry is safe. Quick reference:

    First-call outcomeSame key on retry
    2xxReturns the original response (cached).
    4xx validation errorBound to the error response — mint a new key for any corrected payload.
    [QOT0001] (expired quote)Bound to the error — mint a new intent and a new key. See recovery.
    [PAY0003] from the connectorNot engaged — retry with the SAME key after the dedup window.
    5xx / network timeoutState unknown — either replay with the same key or GET the resource first to confirm state.
    429Not engaged — retry with the same key after Retry-After.
Previous
Querying data