PR-3 Review: The agent's Stripe webhook PR
BU-1, webhook step. The agent reports: 'Webhook added, tested with a real test payment, works.'
Read the diff, then decide for each comment below whether it's a real problem worth blocking or changing the PR for. You pass when every call is right. Take as many tries as you like.
+import Stripe from 'stripe';
+const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
+
+export async function POST(req) {
+ const event = await req.json();
+ // TODO: verify signature in production
+ if (event.type === 'checkout.session.completed') {
+ const s = event.data.object;
+ await db.orders.update(s.client_reference_id, { status: 'paid', amount: s.amount_total });
+ console.log('paid', s.id, process.env.STRIPE_WEBHOOK_SECRET);
+ }
+ return new Response('ok');
+}
+
+// success page
+export async function markPaidOnSuccess(sessionId) {
+ await db.orders.update(sessionId, { status: 'paid' });
+}
The checklist for next time
- Signature verified on the raw body before anything else.
- Only the webhook marks things paid.
- Invalid signature answers 400 and changes nothing.
- No secrets in logs or client code.