Marlow StudioCode & setup

Code & setup

Generated handler code for each destination. Drop in, set the env var, you're done.

Environment
STRIPE_SECRET_KEY=sk_live_…
WHOOKHOUND_SECRET=whsec_8X9Lq2vBqXfP4nM7sR3tY6kZ8wL2cV5x
WHOOKHOUND_URL=https://ingress.whookhound.dev/whk/tnt_3kQy
1// app/api/stripe/route.ts
2import { headers } from 'next/headers';
3import Stripe from 'stripe';
4
5const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
6
7export async function POST(req: Request) {
8 const body = await req.text();
9 const sig = headers().get('stripe-signature')!;
10
11 let event: Stripe.Event;
12 try {
13 // Verifies the Whookhound-resigned signature with your destination secret.
14 event = stripe.webhooks.constructEvent(body, sig, process.env.WHOOKHOUND_SECRET!);
15 } catch (err) {
16 return new Response(`Webhook error: ${(err as Error).message}`, { status: 400 });
17 }
18
19 switch (event.type) {
20 case 'checkout.session.completed':
21 // ...your logic
22 break;
23 case 'customer.subscription.updated':
24 // ...your logic
25 break;
26 }
27 return Response.json({ received: true });
28}
Setup checklist
Store A · production
Destination URL configured
Signing secret generated
Route attached (3 routes)
Env vars set in deployment
First test event delivered
Test fire

Send a sample checkout.session.completed through this route to verify your handler.

CLI
npx whookhound listen \
  --route rt_a1b \
  --forward http://localhost:3000/api/stripe