agentleFS
blitzhash360-webblitzhash360-web/blitzhash-vibe-coding-rules/skills/stripe-webhook-setup/SKILL.md

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

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
  1. Very specific:

    Make it idempotent: Create a processed_events table (or collection) with event_id as a unique key.

    line 25
  2. Distinctive:

    Production: create the endpoint in the Stripe Dashboard with only the needed events, put its signing secret in the hosting env, and check …

    line 30
  3. Distinctive:

    Use test-mode keys while building.

    line 38
  4. Very specific:

    Never print, log or commit sk_live, rk_live or whsec values.

    line 39
  5. Distinctive:

    Never issue refunds, cancel subscriptions or change prices from code you are testing.

    line 40

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Find the runtime (Node server, Next.js App Router, Express, edge runtime, Python) and the existing Stripe client. Confirm STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET come from env vars on the server only.
  2. Get the raw body. Next.js App Router: await req.text(). Express: express.raw({ type: "application/json" }) on this route only, registered before express.json(). Firebase Functions: req.rawBody. Python frameworks: the raw request bytes.
  3. 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_event in Python. Bad signature returns 400 and stops.
  4. Make it idempotent. Create a processed_events table (or collection) with event_id as a unique key. Skip events already stored; store after successful processing.
  5. Handle only the events you need, typically checkout.session.completed, invoice.paid, invoice.payment_failed, customer.subscription.updated and customer.subscription.deleted. For subscription state, re-fetch the subscription from the API rather than trusting event order.
  6. 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.
  7. Respond fast. Return 200 once recorded; push slow work (emails, PDFs) to a queue.
  8. Test locally: stripe listen --forward-to localhost:3000/api/webhooks/stripe, put the printed whsec_... value in your local .env, then stripe trigger checkout.session.completed. Send the same event twice and confirm it is processed once.
  9. 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)

  1. Use test-mode keys while building. Never switch to live keys or create live webhook endpoints without the user's explicit "yes".
  2. Never print, log or commit sk_live, rk_live or whsec values. Use placeholders such as whsec_REPLACE_ME in docs.
  3. Never issue refunds, cancel subscriptions or change prices from code you are testing.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.