stripe-webhook-setup
Skill0 starsChanged 23 days agoMITView on GitHub
Set up or fix a Stripe webhook endpoint correctly - raw-body signature verification, idempotent processing, out-of-order events, fulfilment from webhooks, and local testing with the Stripe CLI. Works for Next.js, Express, Cloudflare Workers, Firebase Functions, Supabase Edge Functions and Python. Use when the user adds payments or subscriptions, says "payment succeeded but nothing happened", or sees webhook signature errors.
- Reads credentials
In this repository8 other files it gives its agents.
- AGENTS.mdAGENTS.md
- packs/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-rate-limitingSkill
- database-access-rulesSkill
- launch-polishSkill
- lean-changesSkill
- secure-api-endpointSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Make it idempotent: Create a processed_events table (or collection) with event_id as a unique key.
- Distinctive: line 30
Production: create the endpoint in the Stripe Dashboard with only the needed events, put its signing secret in the hosting env, and check …
- Distinctive: line 38
Use test-mode keys while building.
- Very specific: line 39
Never print, log or commit sk_live, rk_live or whsec values.
- Distinctive: line 40
Never issue refunds, cancel subscriptions or change prices from code you are testing.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Stripe webhook setup
The success page is not proof of payment. The verified webhook is.
When to use
- Adding Stripe Checkout, subscriptions or one-off payments.
- "No signatures found matching the expected signature" errors.
- Paid users not getting access, or users getting access twice.
Steps
- Find the runtime (Node server, Next.js App Router, Express, edge runtime, Python) and the existing Stripe client. Confirm
STRIPE_SECRET_KEYandSTRIPE_WEBHOOK_SECRETcome from env vars on the server only. - Get the raw body. Next.js App Router:
await req.text(). Express:express.raw({ type: "application/json" })on this route only, registered beforeexpress.json(). Firebase Functions:req.rawBody. Python frameworks: the raw request bytes. - Verify the signature.
stripe.webhooks.constructEvent(raw, sig, secret)in Node;await stripe.webhooks.constructEventAsync(raw, sig, secret, undefined, Stripe.createSubtleCryptoProvider())on edge runtimes;stripe.Webhook.construct_eventin Python. Bad signature returns 400 and stops. - Make it idempotent. Create a
processed_eventstable (or collection) withevent_idas a unique key. Skip events already stored; store after successful processing. - Handle only the events you need, typically
checkout.session.completed,invoice.paid,invoice.payment_failed,customer.subscription.updatedandcustomer.subscription.deleted. For subscription state, re-fetch the subscription from the API rather than trusting event order. - Fulfil here, not on the success page. Grant access, credits or plan changes in the webhook handler. The success page only shows status by reading your database.
- Respond fast. Return 200 once recorded; push slow work (emails, PDFs) to a queue.
- Test locally:
stripe listen --forward-to localhost:3000/api/webhooks/stripe, put the printedwhsec_...value in your local.env, thenstripe trigger checkout.session.completed. Send the same event twice and confirm it is processed once. - Production: create the endpoint in the Stripe Dashboard with only the needed events, put its signing secret in the hosting env, and check the Dashboard's webhook delivery log after the first live payment.
Output format
The webhook handler, the idempotency table or migration, the list of subscribed events, and the local test commands.
Safety rules (always)
- Use test-mode keys while building. Never switch to live keys or create live webhook endpoints without the user's explicit "yes".
- Never print, log or commit
sk_live,rk_liveorwhsecvalues. Use placeholders such aswhsec_REPLACE_MEin docs. - Never issue refunds, cancel subscriptions or change prices from code you are testing.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

