Build the Stripe webhook handler for payment events. Make sure it follows our API conventions and handles the error cases from the integration guide.
JP
Read
src/api/routes.ts
Castles Knowledge
⟨⟩
API Design Conventions
Product → Architecture
Stripe Integration Guide
Product → Integrations
Your API conventions require all webhook handlers to use the verifySignature middleware and return structured error responses. The Stripe integration guide lists three critical error cases: signature mismatch, duplicate event, and unhandled event type.

Building the handler now with all three covered.
C
src/api/webhooks/stripe.ts — new file
+import { verifySignature } from '../middleware';
+import { ApiError } from '../conventions';
+
+export const handleStripeWebhook = [
+ verifySignature('stripe'),
+ async (req, res) => {
+ const { type, data } = req.body;
+ if (await isDuplicate(data.id))
+ return res.status(200).json({ skip: true });
Handler follows your conventions: signature verification middleware, structured ApiError responses, and idempotency check. Pushing to feat/stripe-webhooks.
C
Bash
git checkout -b feat/stripe-webhooks
⌘ Esc to focus or unfocus Claude
✓ Ln 47, Col 12
UTF-8
TypeScript
Claude Code Ready