This example demonstrates how to handle Stripe webhook events using Trigger.dev.
This example shows how to set up a webhook handler in your existing app for incoming Stripe events. The handler triggers a task when a checkout.session.completed
event is received. This is easily customisable to handle other Stripe events.
checkout.session.completed
event is receivedYou’ll need to configure the following environment variables for this example to work:
STRIPE_WEBHOOK_SECRET
The secret key used to verify the Stripe webhook signature.TRIGGER_API_URL
Your Trigger.dev API url: https://api.trigger.dev
TRIGGER_SECRET_KEY
Your Trigger.dev secret keyFirst 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:
This task is triggered when a checkout.session.completed
event is received from Stripe.
To test everything is working you can use the Stripe CLI to send test events to your endpoint:
STRIPE_WEBHOOK_SECRET
that you can use for testing.checkout.session.completed
event type. With the Stripe CLI: stripe trigger checkout.session.completed
200
.stripe-webhook
task.For more information on setting up and testing Stripe webhooks, refer to the Stripe Webhook Documentation.