General
Payment Webhook Returns 405 or Says Ignored Event: A 7-Layer Triage Order
Table of contents
First, split the failure into three regimesLayer 1 — Reachability: can the gateway physically reach that URL?Layer 2 — Subscription: is the provider actually sending that event?Layer 3 — Signature: raw body, header casing, key generationLayer 4 — Idempotency: the receipt arrived twiceLayer 5 — State and amount: the receipt is valid but you refuse itLayer 6 — Isolation: two products, one endpointLayer 7 — Delivery: you accepted it, then lost itA customer pays. Your dashboard still says unpaid. The payment provider's console shows a green checkmark next to "webhook delivered". Somewhere between those two facts there is a bug, and it is almost never where you look first.
The expensive mistake in payment debugging is guessing. Adding a
What works is an order. A payment callback can only fail in seven places. Walk them in sequence, prove each one is excluded with a single command or log line, and the fault collapses to one layer.
This is that order.
Before touching any layer, answer one question: did the request reach my code at all?
| Evidence | Regime | Look at |
|---|---|---|
| Gateway log shows delivery failure / non-2xx | Never arrived | Layers 1–2 |
| Your access log has the request, response is 4xx/5xx | Arrived, rejected | Layer 3 |
| Your log has the request and a 2xx, but the order is unchanged | Arrived, accepted, ignored downstream | Layers 4–7 |
Most teams skip this and start at layer 4, because "the handler ran, so routing is fine" is a comfortable assumption. It is also wrong often enough to waste hours.
A
Common causes, in the order they actually happen:
- The route is registered for
- A trailing-slash mismatch (
- A CDN or WAF rule blocking the provider's egress IP range.
- A reverse proxy that caps request body size, returning a generic 4xx before your app sees anything.
Prove it in 30 seconds:
If
Providers separate "I accepted your endpoint URL" from "I will send you this event type". Setting one does not imply the other.
Check three things:
The event names in your subscription match the events the provider emits today — names get renamed and versioned ( The endpoint is bound to the environment you are testing. A callback registered in sandbox will never fire in live, and vice versa. The endpoint URL survived the last domain change. This is the single most common regression after moving from a staging host to production.
The tell: the gateway's delivery log shows *nothing at all* for the failing order. No attempt, no retry, no error. Absence is evidence — it points at layer 2, not layer 3.
If your log shows the request arriving but every single one fails verification, stop looking at your webhook handler's business logic. You have a transport-level mismatch.
Three sub-causes account for nearly all of them:
The body was parsed before it was verified. Most signature schemes sign the exact bytes received. A framework that deserializes JSON into an object and then re-serializes it for verification will, with near certainty, produce different bytes — key order, float formatting, unicode escaping. Verify against the raw buffer, and only parse afterwards:
Header name casing. HTTP header names are case-insensitive; your dictionary lookup may not be.
Key mismatch across environments. The signing secret rotated, or you loaded the sandbox secret into production. You do not need to paste keys into a chat to check this: compare the first four characters and the length of both values, in both environments, side by side.
This layer does not produce 405s. It produces money problems.
Providers retry on timeout. A handler that takes longer than the provider's timeout will be called again — while the first call is still running. Without an idempotency key that is enforced by the database, both calls fulfil.
The two design mistakes that cause it:
- No unique constraint on the provider's event ID. Application-level "check then insert" is a race, not a guarantee.
- Fulfilling first, marking second. The order is inverted; a crash between the two steps double-fulfils on retry.
The fix is a unique index, not a code review:
Then insert a
The handler runs, verification passes, and the order still does not flip to paid. Three recurring causes:
- Currency and minor units. One side sends
- Irreversible state machine. The order was already
- Trusting the client for state. If a "payment succeeded" flag can also be set by the browser's return URL, an attacker will set it without paying. The webhook is the only authority; the return page just polls.
If you run more than one product behind a single callback URL, add one test to your suite permanently: pay the smallest possible amount in product A, and confirm the credit lands in A — not in B, and not on the user's account in both.
The failure modes are boring and predictable: a shared signing secret makes products indistinguishable; the callback carries an email instead of your internal user ID, so a user with two accounts gets attributed to whichever row the query returned first; a shared event table has no product column.
The last layer is the most embarrassing: the webhook succeeded, the order is paid, and the customer still cannot use the product.
Look at the queue, not the handler:
- The fulfilment job threw, was logged at
- The entitlement was written to a read replica (or a cache) that the UI does not read.
- A downstream API returned 401 because a key expired, and the retry was swallowed.
For each of these the fix is the same shape: make delivery recoverable. Persist intent before doing the work, retry with backoff, and expose a reconciliation query (*"paid orders with no active entitlement"*) that you can run at any time.
Every layer above produces a fix. None of them proves the fix. Four actions do:
- [ ] Pay the minimum amount once — credit appears within seconds, not minutes.
- [ ] Replay the same event from the gateway console 3× — credit appears once.
- [ ] Refund — access is revoked within the promised window.
- [ ] Pay in a second product — the credit lands in the right one.
If a fix cannot pass all four, it is not a fix. It is a patch that has moved the failure to a less visible place.
Each layer you skip costs a full debug cycle. Teams that jump straight to reading the handler code skip layers 1 and 2, where roughly a third of real incidents live — a domain change, an unsubscribed event, a WAF rule. Teams that fix idempotency without confirming the request ever arrived spend an afternoon on a bug that is actually a routing issue.
Walk the seven layers in order. Each one has a cheap test. When a layer's test passes, you have *earned* the right to ignore it.
---
*Debugging a payment integration and want a second pair of eyes on the log trail? [Try the free Lint tools](https://tools.aicreditsapi.com/tools/) — no subscription, bring your own API key.*
The expensive mistake in payment debugging is guessing. Adding a
print() to the handler, redeploying, asking the customer to pay again — each cycle costs money and trust.What works is an order. A payment callback can only fail in seven places. Walk them in sequence, prove each one is excluded with a single command or log line, and the fault collapses to one layer.
This is that order.
First, split the failure into three regimes
Before touching any layer, answer one question: did the request reach my code at all?
| Evidence | Regime | Look at |
|---|---|---|
| Gateway log shows delivery failure / non-2xx | Never arrived | Layers 1–2 |
| Your access log has the request, response is 4xx/5xx | Arrived, rejected | Layer 3 |
| Your log has the request and a 2xx, but the order is unchanged | Arrived, accepted, ignored downstream | Layers 4–7 |
Most teams skip this and start at layer 4, because "the handler ran, so routing is fine" is a comfortable assumption. It is also wrong often enough to waste hours.
Layer 1 — Reachability: can the gateway physically reach that URL?
A
405 Method Not Allowed is the classic signature of this layer. It means something answered — your server, or a proxy in front of it — and refused the method.Common causes, in the order they actually happen:
- The route is registered for
POST only, and an uptime monitor or the provider's setup probe hits it with GET.- A trailing-slash mismatch (
/webhook vs /webhook/) behind a proxy that does not normalize.- A CDN or WAF rule blocking the provider's egress IP range.
- A reverse proxy that caps request body size, returning a generic 4xx before your app sees anything.
Prove it in 30 seconds:
# Is anything answering my endpoint, and with what?
curl -i -X POST https://api.example.com/payments/webhook \
-H 'Content-Type: application/json' -d '{}'
# Is the request even hitting the origin? Watch the access log while retrying.
tail -f /var/log/nginx/access.log | grep payments/webhookIf
curl from your laptop works but the gateway still fails, you have not found the problem — you have found a difference between your network and theirs. That difference (IP allowlist, TLS, WAF) is the bug.Layer 2 — Subscription: is the provider actually sending that event?
Providers separate "I accepted your endpoint URL" from "I will send you this event type". Setting one does not imply the other.
Check three things:
order.succeeded vs payment_intent.succeeded).The tell: the gateway's delivery log shows *nothing at all* for the failing order. No attempt, no retry, no error. Absence is evidence — it points at layer 2, not layer 3.
Layer 3 — Signature: raw body, header casing, key generation
If your log shows the request arriving but every single one fails verification, stop looking at your webhook handler's business logic. You have a transport-level mismatch.
Three sub-causes account for nearly all of them:
The body was parsed before it was verified. Most signature schemes sign the exact bytes received. A framework that deserializes JSON into an object and then re-serializes it for verification will, with near certainty, produce different bytes — key order, float formatting, unicode escaping. Verify against the raw buffer, and only parse afterwards:
raw = request.get_data() # Flask: raw bytes, before any parsing
if not verify_signature(raw, request.headers.get("X-Signature")):
abort(401)
payload = json.loads(raw) # parse only after verificationHeader name casing. HTTP header names are case-insensitive; your dictionary lookup may not be.
request.headers.get("Stripe-Signature") and request.headers.get("stripe-signature") can behave differently depending on the proxy in between. Use a case-insensitive accessor, and log the *complete* header dict once when debugging — do not assume the name you read in the docs is the name on the wire.Key mismatch across environments. The signing secret rotated, or you loaded the sandbox secret into production. You do not need to paste keys into a chat to check this: compare the first four characters and the length of both values, in both environments, side by side.
Layer 4 — Idempotency: the receipt arrived twice
This layer does not produce 405s. It produces money problems.
Providers retry on timeout. A handler that takes longer than the provider's timeout will be called again — while the first call is still running. Without an idempotency key that is enforced by the database, both calls fulfil.
The two design mistakes that cause it:
- No unique constraint on the provider's event ID. Application-level "check then insert" is a race, not a guarantee.
- Fulfilling first, marking second. The order is inverted; a crash between the two steps double-fulfils on retry.
The fix is a unique index, not a code review:
CREATE UNIQUE INDEX uniq_provider_event
ON fulfilment (provider, provider_event_id);Then insert a
processing row first. If the insert violates the constraint, the event is a duplicate — return 200 and stop. If it succeeds, fulfil, then mark done. A crash mid-way leaves a processing row you can reconcile, instead of a silent double credit.Layer 5 — State and amount: the receipt is valid but you refuse it
The handler runs, verification passes, and the order still does not flip to paid. Three recurring causes:
- Currency and minor units. One side sends
1999 (cents), the other compares to 19.99. Compare integers in minor units, always.- Irreversible state machine. The order was already
cancelled by a timeout job when the payment arrived. Decide explicitly what a late success does to a cancelled order — refund, or revive — and encode it.- Trusting the client for state. If a "payment succeeded" flag can also be set by the browser's return URL, an attacker will set it without paying. The webhook is the only authority; the return page just polls.
Layer 6 — Isolation: two products, one endpoint
If you run more than one product behind a single callback URL, add one test to your suite permanently: pay the smallest possible amount in product A, and confirm the credit lands in A — not in B, and not on the user's account in both.
The failure modes are boring and predictable: a shared signing secret makes products indistinguishable; the callback carries an email instead of your internal user ID, so a user with two accounts gets attributed to whichever row the query returned first; a shared event table has no product column.
Layer 7 — Delivery: you accepted it, then lost it
The last layer is the most embarrassing: the webhook succeeded, the order is paid, and the customer still cannot use the product.
Look at the queue, not the handler:
- The fulfilment job threw, was logged at
info, and never retried.- The entitlement was written to a read replica (or a cache) that the UI does not read.
- A downstream API returned 401 because a key expired, and the retry was swallowed.
For each of these the fix is the same shape: make delivery recoverable. Persist intent before doing the work, retry with backoff, and expose a reconciliation query (*"paid orders with no active entitlement"*) that you can run at any time.
The verification checklist that closes the incident
Every layer above produces a fix. None of them proves the fix. Four actions do:
- [ ] Pay the minimum amount once — credit appears within seconds, not minutes.
- [ ] Replay the same event from the gateway console 3× — credit appears once.
- [ ] Refund — access is revoked within the promised window.
- [ ] Pay in a second product — the credit lands in the right one.
If a fix cannot pass all four, it is not a fix. It is a patch that has moved the failure to a less visible place.
Why the order matters more than the fix
Each layer you skip costs a full debug cycle. Teams that jump straight to reading the handler code skip layers 1 and 2, where roughly a third of real incidents live — a domain change, an unsubscribed event, a WAF rule. Teams that fix idempotency without confirming the request ever arrived spend an afternoon on a bug that is actually a routing issue.
Walk the seven layers in order. Each one has a cheap test. When a layer's test passes, you have *earned* the right to ignore it.
---
*Debugging a payment integration and want a second pair of eyes on the log trail? [Try the free Lint tools](https://tools.aicreditsapi.com/tools/) — no subscription, bring your own API key.*
📌 Prices and tool count in this article may be outdated. Lint now ships 16 tools with Pro at $12/mo, or $60/year. See the current pricing page.
Stop letting Grammarly break your code
16 AI tools built for developers. Code-aware parsing.
Or upgrade to Pro for 500 checks a day · All tools · No ads