StoicBuilder

HandbookIII the CastraWebhooks

IIIthe Castra, Stay in control

Webhooks

1 min readUpdated 28 November

In plain words

A webhook is a request another service sends to your server when something happens, like a payment succeeding, so your app can react without asking repeatedly.

Where you see it

After a QuickBite order is paid, Stripe sends checkout.session.completed to /api/webhooks/stripe. If your server is slow or errors, Stripe sends it again, which is how one order reaches the kitchen twice.

app/api/webhooks/stripe/route.tsserver
const body = await req.text();const sig = req.headers.get("stripe-signature")!;const event = stripe.webhooks.constructEvent( body, sig, process.env.STRIPE_WEBHOOK_SECRET!);
constructEvent throws if the request didn't come from Stripe. It needs the raw body, not parsed JSON.

What goes wrong

  1. Skipping the signature check

    Without it, anyone who finds the URL can post a fake "payment succeeded" event and collect free orders.

    const event = await req.json(); // trusted blindly
  2. Processing the same event twice

    Providers may deliver an event more than once, so duplicates are normal. Save each event ID and skip ones you've seen; this is called making the handler idempotent.

  3. Doing slow work before replying

    A handler that sends emails and builds PDFs before replying can make Stripe give up waiting and resend. Record the event, reply 200, and hand the slow part to a background job.

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
In the Stripe webhook handler, verify the signature using the raw request body and STRIPE_WEBHOOK_SECRET, save each event ID and skip duplicates, and reply 200 before any slow work. Then show me how to send a test event with the Stripe CLI.

Quick check

Sign in to earn +10 XP for it

A customer was charged once, but two identical QuickBite orders appeared. Most likely?

Got a prompt that touches webhooks?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.