Overview
This example shows how to set up a webhook handler in your existing app for incoming Stripe events. The handler triggers a task when acheckout.session.completed event is received. This is easily customisable to handle other Stripe events.
Key features
- Shows how to create a Stripe webhook handler in your app
- Triggers a task from your backend when a
checkout.session.completedevent is received
Environment variables
You’ll need to configure the following environment variables for this example to work:STRIPE_WEBHOOK_SECRETThe secret key used to verify the Stripe webhook signature.TRIGGER_API_URLYour Trigger.dev API url:https://api.trigger.devTRIGGER_SECRET_KEYYour Trigger.dev secret key
Setting up the Stripe webhook handler
First you’ll need to create a Stripe webhook handler route that listens for POST requests and verifies the Stripe signature. Here are examples of how you can set up a handler using different frameworks:Task code
This task is triggered when acheckout.session.completed event is received from Stripe.
trigger/stripe-checkout-completed.ts
Testing your task locally
To test everything is working you can use the Stripe CLI to send test events to your endpoint:- Install the Stripe CLI, and login
- Follow the instructions to test your handler. This will include a temporary
STRIPE_WEBHOOK_SECRETthat you can use for testing. - When triggering the event, use the
checkout.session.completedevent type. With the Stripe CLI:stripe trigger checkout.session.completed - If your endpoint is set up correctly, you should see the Stripe events logged in your console with a status of
200. - Then, check the Trigger.dev dashboard and you should see the successful run of the
stripe-webhooktask.

