Appearance
Webhook retries, duplicates and ordering
MOOKHPay delivers each event at least once, retries a failed delivery for about 12 hours, and makes no promise about order. Build your receiver so that a repeat or an out-of-order event does no harm.
What counts as delivered
An attempt is delivered when your endpoint answers with a 2xx status within 8 seconds. Everything else is a failed attempt:
- any other status, including
3xx(redirects are not followed) and4xx; - no answer within 8 seconds;
- a connection, TLS or DNS error.
Retries
A failed attempt is retried with exponential backoff. These are the defaults; a deployment can change the number of attempts (MERCHANT_WEBHOOK_ATTEMPTS) and the first wait (MERCHANT_WEBHOOK_BACKOFF_MS).
| Attempt | Wait before it | Time since the first attempt |
|---|---|---|
| 1 | — | 0 |
| 2 | 84 s | 1 min 24 s |
| 3 | 168 s | 4 min 12 s |
| 4 | 336 s | 9 min 48 s |
| 5 | 11 min 12 s | 21 min |
| 6 | 22 min 24 s | 43 min 24 s |
| 7 | 44 min 48 s | 1 h 28 min 12 s |
| 8 | 1 h 29 min 36 s | 2 h 57 min 48 s |
| 9 | 2 h 59 min 12 s | 5 h 57 min |
| 10 | 5 h 58 min 24 s | 11 h 55 min 24 s |
The waits are approximate: a busy queue can add a little.
- Every attempt sends the same body, byte for byte, with the same
idandX-Mookh-Event-Id, and a newX-Mookh-TimestampandX-Mookh-Signature. - While retries remain, the delivery shows
pendingunder API Integrations, Deliveries, with the attempt count and the last answer. After the last failed attempt it showsfailedand is not tried again. - A failed delivery can be sent again from the hub with Resend, for 30 days. A resend is one attempt with the same
id. See Resend a delivery. - To recover many events at once, read the objects:
GET /checkouts/:id,GET /charges/:id,GET /refunds/:id,GET /accounts/:id/payouts/:payout_idorGET /accounts/:id.
Failures that are not retried
These are recorded as failed at once, with no further attempts, because retrying would not change them:
| Cause | Recorded error |
|---|---|
| The endpoint was no longer active when the attempt ran. Events are fanned out only to active endpoints and nothing switches an active endpoint off today, so this is rare | endpoint is inactive |
| The endpoint's address no longer passes the URL rules, or its name now resolves to a private address | The rule it broke, such as url resolves to a private address |
Deleting an endpoint drops its pending deliveries.
The failing-endpoint email
When an endpoint keeps failing, MOOKHPay emails the account that owns it, once per spell of failures:
- A spell starts with the endpoint's first failed attempt and ends at its next delivered one.
- The email is sent when one delivery has failed half of its attempts (its 5th attempt, with the default 10), if no email has been sent in this spell.
- It names the endpoint (host and path), when the failures started, how many events have failed, the last answer (
500 Internal Server Error,Timed outorNo answer), and when retries of that delivery stop.
One delivered attempt ends the spell; the next spell can send another email. A resend that fails never sends the email.
Duplicates
Delivery is at least once. A delivery can arrive twice if MOOKHPay's worker stops after your server answered but before it recorded the answer, and a resend from the hub arrives again on purpose. Make your handler idempotent.
Deduplicate on the body's id (also sent as X-Mookh-Event-Id). It is the same on every retry, on every resend, and on every endpoint of your account that receives the event. Record each id you have handled, in the same transaction as the work it caused, and answer 2xx without doing the work again when one comes back.
A platform and a seller who both receive an event are two accounts, and each gets its own event with its own id.
MOOKHPay makes one event for each event type and subject, so one id stands for:
| Event | One id per |
|---|---|
payment.succeeded, payment.failed | checkout_id |
charge.expired, charge.cancelled | charge |
payout.paid, payout.failed | payout_id |
refund.succeeded, refund.declined | refund_id (when refund_id is null, intent_id) |
refund.failed | refund_id and attempt. A refund that fails twice sends two events with two ids |
account.created | account |
account.linked, account.claimed, account.disconnected | account and created_at |
account.updated | account and the content of data |
Two consequences of keying on the checkout:
- Each endpoint receives at most one
payment.failedand onepayment.succeededfor a checkout, however many payment attempts it has. If the first attempt fails and a second attempt fails too, the second sends no event. A charge that fails moves tofailedand is not retried, so this matters most for hosted checkouts, where the payer can try again. PollGET /checkouts/:idif you need to see every attempt. payment.failedfollowed bypayment.succeededfor the samecheckout_idis normal: the payer failed once, then paid.
Order
Events can arrive in any order. Deliveries are sent in parallel and each one retries on its own schedule, so an event whose first attempt failed can arrive hours after a later event about the same payment.
Cases you will meet:
| You receive | Then | Why |
|---|---|---|
payment.failed | payment.succeeded, same checkout_id | A later attempt on the checkout was paid |
payment.succeeded | payment.failed, same checkout_id | The payment.failed for an earlier attempt was retried and arrived late |
charge.expired or charge.cancelled | payment.succeeded, same charge | A prompt already on the payer's phone was approved after the charge ended. The payment is booked and the charge moves to succeeded, up to 7 days later |
account.claimed | account.created | Both can be delayed; claims are read from MOOKHPay's account service once a minute by default |
refund.failed | refund.succeeded or refund.declined, same refund_id | An attempt to send the money failed and the refund went back to MOOKHPay, which then sent it another way or declined it |
Rules that keep you correct whatever the order:
- Treat
payment.succeededas final. Never let a later-arrivingpayment.failedundo a fulfilled order. - Before you act on an event that changes state, re-read the object from the API and act on what it says now. The webhook says something changed; the object says what is true.
- Use
created_atonly to compare events you already hold. It is when MOOKHPay prepared the payload (foraccount.linked,account.claimedandaccount.disconnected, when it happened), not when the payment settled.