Retries and Idempotency
How callback failures are determined, the retry schedule (1 minute to 24 hours, up to 8 times), manual resends, and preventing duplicate grants with X-StagePay-Delivery.
Failure determination
| Result | Outcome |
|---|---|
| HTTP 2xx | Success (delivered) |
| Any non-2xx status code (3xx, 4xx, and 5xx alike) | Failure → retry |
| Connection failure, TLS error, 10-second timeout | Failure → retry |
Callback URL not set / URL that is not http(s) | Immediately failed (no retries) |
Redirects (3xx) are not followed, so register the final address directly.
Retry schedule
If the initial attempt fails, StagePay retries up to 8 times at the intervals below (9 attempts in total).
| Retry | Wait after previous attempt | Cumulative from initial attempt (approx.) |
|---|---|---|
| 1 | 1 minute | 1 minute |
| 2 | 5 minutes | 6 minutes |
| 3 | 15 minutes | 21 minutes |
| 4 | 1 hour | 1 hour 21 minutes |
| 5 | 3 hours | 4 hours 21 minutes |
| 6 | 6 hours | 10 hours 21 minutes |
| 7 | 12 hours | 22 hours 21 minutes |
| 8 | 24 hours | About 46 hours |
If all 8 retries fail, the callback status becomes failed and it is no longer sent automatically. Because of the worker cycle, actual delivery times can be delayed by tens of seconds.
Manual resend
You can resend a failed callback from the console under Transaction details → Callbacks.
- It is sent again with the same
X-StagePay-Deliveryvalue (the idempotency key is preserved). - Resending resets the attempt count, so the retry schedule above starts over from the beginning.
X-StagePay-Timestampand the signature are recalculated on every send. Even an old callback that is resent passes the timestamp check.
Idempotency
A callback for the same payment may arrive more than once (retries, manual resends, lost merchant responses). Make sure your merchant server grants only once.
Choose an idempotency key
- Primary key:
X-StagePay-Delivery— always the same value for retries of the same event - Secondary key:
tid+event— payment completion occurs only once per transaction
Record it atomically
Before granting, first INSERT the idempotency key into a table with a unique constraint. If a duplicate key error occurs, treat the callback as already processed and respond with 200.
Grant and record in the same transaction
Where possible, wrap the idempotency key INSERT and the item grant in a single DB transaction. If the grant fails partway, it is rolled back and processed again on the next retry.
CREATE TABLE stagepay_deliveries (
delivery_id uuid PRIMARY KEY,
tid text NOT NULL,
event text NOT NULL,
received_at timestamptz NOT NULL DEFAULT now(),
UNIQUE (tid, event)
);async function handleCallback(db, deliveryId, event) {
const client = await db.connect();
try {
await client.query('BEGIN');
const r = await client.query(
`INSERT INTO stagepay_deliveries (delivery_id, tid, event) VALUES ($1, $2, $3)
ON CONFLICT DO NOTHING`,
[deliveryId, event.tid, event.event],
);
if (r.rowCount === 0) {
await client.query('ROLLBACK');
return 'duplicate'; // Already processed → respond 200
}
if (event.event === 'payment.succeeded') {
await grantItem(client, event); // Verify the order (productId, amountMinor, currency), then grant
} else if (event.event === 'payment.refunded') {
await revokeItem(client, event); // Handle according to your clawback policy
}
await client.query('COMMIT');
return 'processed';
} catch (e) {
await client.query('ROLLBACK');
throw e; // Respond 5xx → StagePay retries
} finally {
client.release();
}
}Ordering
Callback order is not guaranteed. For example, payment.refunded may arrive before a payment.succeeded that is still being retried. The body's transactionStatus and refundedAmountMinor reflect the transaction state at send time, so if you need the latest state, query the transaction with the REST API.
Callback Signature Verification
The X-StagePay-Signature HMAC-SHA256 signature specification, verification examples in Node.js, PHP, Python, Go, and Java, and fixed test vectors.
GamePot App Specifics
Checkout parameters, GamePot regional callback endpoints, and payload format differences for apps whose webhookType is GAMEPOT.