Webhooks: How Not to Lose the Payment Status

The money arrived, the customer has the receipt, and in your system the order is still unpaid. Nobody stole anything and nothing failed on the payment side — the message that was supposed to tell your shop about it never landed, or landed and was ignored.

That message is a webhook, and it is the single most common source of first-week chaos after connecting payments. It is also entirely fixable, and almost all of the fixing happens on your side.

Contents

What a webhook is, and why the payment page is not enough

A webhook is a message the provider sends to your server when something happens to a payment: authorised, settled, refunded, disputed. It is the authoritative version of events.

The tempting alternative — marking the order paid when the customer lands back on your «thank you» page — fails constantly, and not in edge cases. The customer closes the tab, the phone loses signal, the bank confirmation takes a minute longer than the browser waits. The payment succeeded; the browser never came back to say so.

How the acceptance side is put together around this is described under payment processing.

The four failures you will actually meet

  • The message never arrives. Wrong address, an expired certificate, a firewall, a server that was restarting. From your side it looks exactly like a payment that did not happen.
  • It arrives twice. Retries are normal behaviour, not a bug. If your code treats each delivery as a new event, you ship the order twice or credit the balance twice.
  • It arrives out of order. «Settled» can land before «authorised». Order of events is not guaranteed; the state of the payment is.
  • It arrives, and your code answers slowly. A handler that does the whole business process inline times out, the provider sees a failure and retries — and now you have both problems at once.

Four rules that remove almost all of it

Answer immediately, work afterwards. The handler should accept the message, store it and reply. Everything else — updating the order, sending mail, notifying the warehouse — happens in a queue behind it.

Be idempotent. The same event, delivered five times, must change your system exactly once. Store the event identifier and check it before acting; this single rule prevents the double-shipment class of problem.

Verify the sender. Check the signature on every message and ignore anything that fails. A webhook endpoint is a public address, and anything reachable will eventually be poked at.

Trust the payment state, not the message order. Decide what to do from the state the event reports, not from what you expected to arrive next.

What to do when nothing arrives at all

Silence is not proof that a payment did not happen, and this is the part that costs money. Have a reconciliation job that asks the provider for the current state of anything that has been pending too long and repairs the order. Without it, every missed message is an order that never ships and a customer who eventually disputes — at 100,00 EUR a case on top of the amount, while a refund you issue yourself is 50,00 EUR. The published lines are on the pricing page.

The same job is what keeps your books straight: settlement arrives on T+7, the reserve is 10% held for 180 days, and matching those against your own orders is a separate discipline described in our piece on mass payouts for high-risk businesses.

What to log

Every message received, with its identifier, the time, and what your system did about it. When a customer says they paid and you say they did not, that log is the entire conversation. It is also what turns «something is broken» into a fixable question, and it is cheapest to build on day one. Where the money lands is described under business IBAN.

Testing it properly

  • Send yourself a duplicate. Deliver the same event twice and confirm nothing happens the second time.
  • Break the handler on purpose. Return an error and check that the retry arrives and is handled.
  • Test the refund path. It is the one that most often turns out to have no handler at all.
  • Test on the real domain. Certificates and firewalls behave differently outside a developer’s machine.
  • Run one live payment after every release. Most webhook breakage arrives with an unrelated deployment.

What else to check before switching acceptance on is in our merchant approval checklist.

Who owns this after launch

Webhook handling is written once by whoever connected payments and then belongs to nobody. That is why it breaks quietly: the code still runs, the messages still arrive, and the failures show up as customer complaints weeks later rather than as an alert.

Give it an owner and two alarms: one for messages that failed to process, one for payments that stayed pending longer than they should. Both are cheap to build and both pay for themselves the first time a release breaks the endpoint.

In short

Webhooks are the authoritative version of what happened to a payment, and the browser is not. Answer fast and work in a queue, be idempotent, verify the signature, trust the state rather than the order, and run a reconciliation job for messages that never came. Do that and the merchant account and your order system stop telling two different stories.

Read also: 3-D Secure: How Not to Lose Conversion at Confirmation.

Add SharPay as a preferred source on Google