Stripe webhook
POST /api/v1/webhooks/stripe
Public route. Stripe sends events to this endpoint after checkout sessions complete or expire.
Simulate a Stripe webhook event (local/test only)
Signature verification
The server verifies the Stripe signature againstSTRIPE_WEBHOOK_SECRET:
- It reads the
stripe-signatureheader from the request. - It calls
stripe.webhooks.constructEvent(rawBody, signature, webhookSecret)(or the mock equivalent in local mode). - If verification fails, it returns
400 invalid_signature.
Events handled
Idempotency
Each checkout session is fulfilled at most once. The webhook handler checks the receipt status and thecredit_entries unique constraint on (workspace, idem_scope, idempotency_key). Replayed events never double-credit.
Stripe verification in local mode
WhenSTRIPE_MOCK_SENTINEL=enabled, the server uses a deterministic mock client that verifies signatures with HMAC-SHA256 over the raw body using STRIPE_WEBHOOK_SECRET as the key. This mirrors Stripe’s verification closely enough that a tampered body or wrong secret fails identically to production.