A TypeScript webhook handler for Stripe events using Codehooks.io.
- Verifies Stripe webhook signatures for security
- Logs all events to console
- Stores events in a
stripe_eventscollection - Includes health check endpoint
coho create my-stripe-handler --template stripe-webhook-handler
cd my-stripe-handler
npm installmkdir my-stripe-handler
cd my-stripe-handler
coho install stripe-webhook-handler
npm installcoho deploy-
Configure environment variables using one of these methods:
Option A: Via Codehooks Studio
- Go to your project in Codehooks Studio
- Navigate to Settings → Environment Variables
- Add:
STRIPE_SECRET_KEYwith valuesk_test_... - Add:
STRIPE_WEBHOOK_SECRETwith valuewhsec_...
Option B: Via CLI
coho set-env STRIPE_SECRET_KEY "sk_test_..." coho set-env STRIPE_WEBHOOK_SECRET "whsec_..."
-
Configure Stripe webhook:
- Go to https://dashboard.stripe.com/webhooks
- Add endpoint with your deployed URL:
https://YOUR_PROJECT.api.codehooks.io/dev/webhook - Select the events you want to receive
- Copy the webhook signing secret to your environment variables
POST /webhook- Stripe webhook endpointGET /- Health check
Events are stored in the stripe_events collection with the following structure:
{
"event_id": "evt_...",
"type": "payment_intent.succeeded",
"created": 1234567890,
"livemode": false,
"data": { ... },
"api_version": "2024-11-20.acacia",
"request": { ... },
"received_at": "2024-01-01T00:00:00.000Z"
}Use the Stripe CLI to test webhooks locally:
stripe listen --forward-to https://your-project.api.codehooks.io/dev/webhook
stripe trigger payment_intent.succeeded