Stripe Webhooks: Why Customers Paid and Got Nothing

If a customer paid and your app never unlocked anything, your server almost certainly never processed Stripe’s webhook. That is the usual “Stripe webhook not working” story. Open the Dashboard’s delivery log for your endpoint and read the answer your server gave. It tells you which of five causes you have:
- The signing secret in your app is the wrong one.
- Your framework changed the request body before the signature check.
- Your endpoint answered with an error, or too slowly.
- The URL Stripe calls is not the URL you think it is.
- Your code ignored the event that matters, or mishandled a repeat.
A webhook is Stripe calling your server to say “this happened”. The money moved, and the phone call to you failed.
Step 1: Look at what Stripe sees
In the Dashboard, open your webhook endpoint and find its event deliveries. Per Stripe’s webhook docs, you see your server’s response and any coming retry. A 400 or 401 points at verification (causes 1 and 2). A 500 points at your code. A timeout points at slow work. A 3xx means a redirect. No attempts at all means the wrong URL, or an endpoint registered in a different mode, since sandbox and live are separate.
One more check, because Stripe changed the Dashboard: when you create an endpoint it asks for a payload format, Thin (recommended) or Snapshot. The code below handles snapshot events. A thin destination needs the thin handler from the same docs page and, per those docs, a separate endpoint.
No terminal? Skip the CLI: fix the cause, then use Resend on the failed event in the Dashboard.
To reproduce locally, use Stripe’s CLI (docs).:
stripe listen --forward-to localhost:4242/webhook # prints a whsec_ secret for this sessionstripe trigger checkout.session.completedCause 1: The wrong signing secret
Stripe’s own troubleshooting guide says the most common cause is using the wrong endpoint secret. Each endpoint has its own whsec_ secret. Test and live differ, and a CLI session differs from a Dashboard endpoint. They look alike, so an app that works on your laptop fails once deployed.
Compare the last four characters of the secret in your hosting settings with the one in the Stripe Dashboard, and re-paste it if they differ. Trailing whitespace counts.
Cause 2: Your framework touched the body
Stripe signs the exact bytes it sent. Its docs say to make sure your framework does not manipulate the raw body. In Express, if express.json() is registered before your webhook route, the body arrives parsed, and the Stripe library refuses it:
Webhook payload must be provided as a string or a Buffer instance representing the _raw_ request body.Payload was provided as a parsed JavaScript object instead.The fix is order: the webhook route, with express.raw, goes before the JSON middleware. If you are not on Express, the rule is the same: hand Stripe’s check the untouched body text. The troubleshooting page has an example per framework, including Next.js App Router.
Cause 3: A slow or failing answer
Stripe’s guidance is to return a 2xx quickly, before complex logic. Per the same docs, live mode retries for up to three days with exponential back off, a sandbox three times over a few hours. Resend by hand: Dashboard up to 15 days, stripe events resend up to 30. (Checked 6 December 2026. These windows change.)
Cause 4: The wrong URL
A 3xx in the log means your host redirects (http to https, or to www). Register the final production URL directly. A stale preview deploy URL does the same damage.
Cause 5: You ignored the event, or mishandled a repeat
Per Stripe’s docs, events can arrive more than once and out of order, and in some cases two separate Event objects are sent for one thing, so match on the object ID inside data.object. For delayed payment methods, checkout.session.completed can arrive before the money has, so wait for checkout.session.async_payment_succeeded. On checkout.session.async_payment_failed, tell the customer and grant nothing. Stripe’s fulfillment guide says fulfillment must be safe to run more than once for the same Checkout Session, possibly at the same time.
Tests that say what the app does for a user
These tests never look inside your handler. They send signed events over HTTP and check what the user ends up with: behaviors, not implementation details. They sign with the Stripe SDK’s own generateTestHeaderString, so no account or network is needed. Passing proves your handler accepts a correctly signed payload, not that Stripe can reach your endpoint. Save as webhook.test.js, put your handler in app.js, run npm i express stripe, then node --test (Node 18 or newer).
const test = require("node:test");const assert = require("node:assert");const Stripe = require("stripe");const { makeApp } = require("./app.js");
const SECRET = "whsec_test_secret";const stripe = new Stripe("sk_test_unused");
async function withServer(fn, opts = {}) { const { app, credits, unmatched } = makeApp({ secret: SECRET, ...opts }); const server = app.listen(0); const url = `http://127.0.0.1:${server.address().port}/webhook`; try { await fn({ url, credits, unmatched }); } finally { server.close(); }}function send(url, event, secret = SECRET) { const payload = JSON.stringify(event); const header = stripe.webhooks.generateTestHeaderString({ payload, secret }); return fetch(url, { method: "POST", headers: { "content-type": "application/json", "stripe-signature": header }, body: payload });}const session = (type, id, payment_status, user = "u1", sid = "cs_" + id) => ({ id, object: "event", type, data: { object: { id: sid, object: "checkout.session", client_reference_id: user, payment_status } },});
test("a paid checkout gives the user their 100 credits", () => withServer(async ({ url, credits }) => { const r = await send(url, session("checkout.session.completed", "evt_1", "paid")); assert.equal(r.status, 200); assert.equal(credits.get("u1"), 100);}));
test("a request signed with the wrong secret gives nothing and is refused", () => withServer(async ({ url, credits }) => { const r = await send(url, session("checkout.session.completed", "evt_2", "paid"), "whsec_attacker"); assert.equal(r.status, 400); assert.equal(credits.get("u1"), undefined);}));
test("the same event delivered twice gives the credits once and is answered 200 both times", () => withServer(async ({ url, credits }) => { const e = session("checkout.session.completed", "evt_3", "paid"); assert.equal((await send(url, e)).status, 200); assert.equal((await send(url, e)).status, 200); assert.equal(credits.get("u1"), 100);}));
test("a delayed payment method gives credits only after the payment actually succeeds", () => withServer(async ({ url, credits }) => { await send(url, session("checkout.session.completed", "evt_4", "unpaid")); assert.equal(credits.get("u1"), undefined); await send(url, session("checkout.session.async_payment_succeeded", "evt_5", "paid")); assert.equal(credits.get("u1"), 100);}));
test("an event type we do not care about is answered 200 so Stripe stops retrying", () => withServer(async ({ url }) => { const r = await send(url, { id: "evt_6", object: "event", type: "customer.created", data: { object: {} } }); assert.equal(r.status, 200);}));
test("if giving the credits fails once, Stripe's retry still gives them", async () => { let calls = 0; const credits = new Map(); const grant = (u) => { if (calls++ === 0) throw new Error("database down"); credits.set(u, 100); }; await withServer(async ({ url }) => { const e = session("checkout.session.completed", "evt_7", "paid"); assert.equal((await send(url, e)).status, 500); assert.equal((await send(url, e)).status, 200); assert.equal(credits.get("u1"), 100); }, { grant });});
test("two different events about the same paid session give the credits once", () => withServer(async ({ url, credits }) => { await send(url, session("checkout.session.completed", "evt_8", "paid", "u1", "cs_same")); await send(url, session("checkout.session.async_payment_succeeded", "evt_9", "paid", "u1", "cs_same")); assert.equal(credits.get("u1"), 100);}));
test("a paid session with no user attached gives nobody credits and is recorded for a human", () => withServer(async ({ url, credits, unmatched }) => { const r = await send(url, session("checkout.session.completed", "evt_10", "paid", null, "cs_orphan")); assert.equal(r.status, 200); assert.equal(credits.size, 0); assert.deepEqual(unmatched, ["cs_orphan"]);}));
test("a signature made for one payload does not work for a different payload", () => withServer(async ({ url, credits }) => { const real = JSON.stringify(session("checkout.session.completed", "evt_11", "unpaid")); const header = stripe.webhooks.generateTestHeaderString({ payload: real, secret: SECRET }); const forged = JSON.stringify(session("checkout.session.completed", "evt_11", "paid")); const r = await fetch(url, { method: "POST", headers: { "content-type": "application/json", "stripe-signature": header }, body: forged }); assert.equal(r.status, 400); assert.equal(credits.get("u1"), undefined);}));Here is the handler most people end up with, app.js for the first run:
const express = require("express");const Stripe = require("stripe");function makeApp({ secret, grant }) { const stripe = new Stripe("sk_test_unused"); const credits = new Map(); const give = grant || ((u) => credits.set(u, (credits.get(u) || 0) + 100)); const app = express(); app.use(express.json()); app.post("/webhook", (req, res) => { let event; try { event = stripe.webhooks.constructEvent(req.body, req.headers["stripe-signature"], secret); } catch (e) { return res.status(400).send("bad signature"); } if (event.type === "checkout.session.completed") give(event.data.object.client_reference_id); res.sendStatus(200); }); return { app, credits, unmatched: [] };}module.exports = { makeApp };Each stage of the fix was run in a scratch folder with Node 22, stripe 23.2.0 and express 5.3.0:
| Handler | Pass | Fail | Why |
|---|---|---|---|
Usual one (express.json() first) | 2 | 7 | Parsed body, so every real event is refused |
| Raw body only | 6 | 3 | Accepts events, but grants twice on repeats, grants on unpaid, and misfiles a payment with no user |
| Raw body plus “seen event ids” check, recorded before the work | 6 | 3 | A failure while granting marks the event done, so the retry is skipped and the customer paid for nothing |
| Final version below | 9 | 0 |
Tests 2 and 9 pass against the usual handler, because a handler that rejects everything also rejects forged events.
The third row is the trap. A repeat check feels like the fix, yet it loses a payment: the event id is written down, the database call fails, and Stripe’s retry is answered “already seen”. Record the work as done only after it succeeds, and key it on the Checkout Session id, so two different events about one payment give credits once.
const express = require("express");const Stripe = require("stripe");function makeApp({ secret, grant }) { const stripe = new Stripe("sk_test_unused"); const credits = new Map(); const give = grant || ((u) => credits.set(u, (credits.get(u) || 0) + 100)); const fulfilled = new Set(); // Checkout Session ids already given. A database table in real life. const unmatched = []; const app = express(); app.post("/webhook", express.raw({ type: "application/json" }), (req, res) => { let event; try { event = stripe.webhooks.constructEvent(req.body, req.headers["stripe-signature"], secret); } catch (e) { return res.status(400).send("bad signature"); } const s = event.data.object; const paidNow = (event.type === "checkout.session.completed" && s.payment_status === "paid") || event.type === "checkout.session.async_payment_succeeded"; if (!paidNow) return res.sendStatus(200); // unrelated, unpaid yet, or failed: nothing to give if (fulfilled.has(s.id)) return res.sendStatus(200); if (!s.client_reference_id) { unmatched.push(s.id); return res.sendStatus(200); } try { give(s.client_reference_id); } catch (e) { return res.sendStatus(500); // not recorded as done, so Stripe's retry gets another go } fulfilled.add(s.id); // recorded only after the work worked res.sendStatus(200); }); app.use(express.json()); return { app, credits, unmatched };}module.exports = { makeApp };Nine of nine pass. This file keeps its list in memory, which resets on restart and is not shared between servers. In your database, make the grant and the “done” record one transaction with a unique constraint on the session id, and let a duplicate insert mean “already done”. Two simultaneous deliveries would both pass an in-memory check, and these tests do not cover that. The tests do not cover subscriptions, refunds or invoice.* events, and were not run against a live Stripe account. Do not paste this file into your app. Ask your AI tool to run the same tests against your real handler.
A prompt to paste into your AI tool
Find every Stripe webhook route in this app. For each, tell me: which middleware runs before it (is the body parsed as JSON before the signature check?), where the signing secret is read from and whether it is the right one for test versus live, how it checks the signature, whether it records an event or session as done before or after the work succeeds, how it avoids giving the same Checkout Session twice, and what slow work it does before answering. Do not change any code yet.
No Express, for example on Supabase Edge Functions? Give the same prompt and ask your AI tool to translate the tests to your stack. A Supabase Edge Function version of this handler was not verified for this post, so check the result against Stripe’s docs for your framework.
The check an engineer does by hand
Run stripe listen --forward-to localhost:<your port>/<your route>, then stripe trigger checkout.session.completed in another terminal. Your route should answer 200. Resend the same event, and make a database write fail once on purpose. The user should end up with exactly one grant.
Webhooks sit behind the Stripe testing checklist, and the signing secret must stay out of the browser. If a bad deploy caused it, roll it back first, then resend. Add webhooks to the launch checklist.
The Get AI Native ebook goes deeper on this. It is free, and the expected launch is around Christmas. Join the waitlist on the homepage.