Skip to content

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) and 4xx;
  • 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).

AttemptWait before itTime since the first attempt
1—0
284 s1 min 24 s
3168 s4 min 12 s
4336 s9 min 48 s
511 min 12 s21 min
622 min 24 s43 min 24 s
744 min 48 s1 h 28 min 12 s
81 h 29 min 36 s2 h 57 min 48 s
92 h 59 min 12 s5 h 57 min
105 h 58 min 24 s11 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 id and X-Mookh-Event-Id, and a new X-Mookh-Timestamp and X-Mookh-Signature.
  • While retries remain, the delivery shows pending under API Integrations, Deliveries, with the attempt count and the last answer. After the last failed attempt it shows failed and 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_id or GET /accounts/:id.

Failures that are not retried ​

These are recorded as failed at once, with no further attempts, because retrying would not change them:

CauseRecorded 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 rareendpoint is inactive
The endpoint's address no longer passes the URL rules, or its name now resolves to a private addressThe 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 out or No 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:

EventOne id per
payment.succeeded, payment.failedcheckout_id
charge.expired, charge.cancelledcharge
payout.paid, payout.failedpayout_id
refund.succeeded, refund.declinedrefund_id (when refund_id is null, intent_id)
refund.failedrefund_id and attempt. A refund that fails twice sends two events with two ids
account.createdaccount
account.linked, account.claimed, account.disconnectedaccount and created_at
account.updatedaccount and the content of data

Two consequences of keying on the checkout:

  • Each endpoint receives at most one payment.failed and one payment.succeeded for 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 to failed and is not retried, so this matters most for hosted checkouts, where the payer can try again. Poll GET /checkouts/:id if you need to see every attempt.
  • payment.failed followed by payment.succeeded for the same checkout_id is 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 receiveThenWhy
payment.failedpayment.succeeded, same checkout_idA later attempt on the checkout was paid
payment.succeededpayment.failed, same checkout_idThe payment.failed for an earlier attempt was retried and arrived late
charge.expired or charge.cancelledpayment.succeeded, same chargeA 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.claimedaccount.createdBoth can be delayed; claims are read from MOOKHPay's account service once a minute by default
refund.failedrefund.succeeded or refund.declined, same refund_idAn 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:

  1. Treat payment.succeeded as final. Never let a later-arriving payment.failed undo a fulfilled order.
  2. 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.
  3. Use created_at only to compare events you already hold. It is when MOOKHPay prepared the payload (for account.linked, account.claimed and account.disconnected, when it happened), not when the payment settled.

Staging documentation. A checkout made with a secret key on staging charges a real phone. See Environments.