> ## Documentation Index
> Fetch the complete documentation index at: https://trigger.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Receive and verify Stripe webhooks

> Verify Stripe's webhook signature and run a Trigger.dev task for each Stripe event, such as checkout.session.completed. Register the endpoint in Stripe, set the whsec_ signing secret, and filter by event type.

**`webhooks.stripe()` verifies the HMAC-SHA256 signature Stripe sends in `stripe-signature` on every request.**

```ts /trigger/stripe.ts theme={"theme":"css-variables"}
import { webhook, webhooks } from "@trigger.dev/sdk";

export const stripe = webhooks.endpoint.define({
  id: "stripe",
  source: webhooks.stripe(),
});

export const fulfillCheckout = webhook({
  id: "fulfill-checkout",
  endpoint: stripe,
  filter: "event.type == 'checkout.session.completed'",
  onEvent: async ({ event }) => {
    console.log("Checkout completed", event.data.object.id);
  },
});
```

| Setting | Value |
| - | - |
| Source | `webhooks.stripe()` |
| Verification | HMAC-SHA256 in `stripe-signature`, with a timestamp tolerance |
| Credential | Signing secret issued by Stripe (starts with `whsec_`) |
| Event type | `event.type` |
| Stripe docs | [Stripe webhook docs](https://docs.stripe.com/webhooks) |

## Set up Stripe

1. Start `trigger dev` or deploy, then copy the endpoint's **Webhook URL** from the **Webhooks** page.
2. In the Stripe Dashboard, open the **Webhooks** tab in Workbench and choose **Create an event destination**. Choose the **Snapshot** payload format, select the events you want, choose **Webhook endpoint** and paste the Webhook URL.
3. On the destination's settings page, choose **Reveal secret** and copy the signing secret.
4. Choose **Set signing secret** on the Trigger.dev endpoint and paste the secret.
5. Use a test mode destination for dev and staging environments and a live mode destination for production. Each has its own signing secret.

To create the destination from the Stripe CLI instead, the response's `secret` field is the signing secret:

```bash theme={"theme":"css-variables"}
stripe webhook_endpoints create -d url="<webhook URL>" -d "enabled_events[]=checkout.session.completed"
```

## Test locally

Your dev environment has its own Webhook URL, so you don't need `stripe listen` or a tunnel. With `trigger dev` running and a test mode destination pointing at the dev URL, send a test event with the Stripe CLI:

```bash theme={"theme":"css-variables"}
stripe trigger checkout.session.completed
```

The delivery appears on the endpoint's **Deliveries** tab with a link to the run it started. You can also send a sample event from the endpoint's **Test** tab. See [Verify the connection](https://trigger.dev/docs/webhooks/connect.md#verify-the-connection) if nothing arrives.

## Typing the event

`webhooks.stripe()` provides a default event shape. For the full Stripe types, install the `stripe` package and pass `Stripe.Event`:

```ts /trigger/stripe.ts theme={"theme":"css-variables"}
import type Stripe from "stripe";
import { webhooks } from "@trigger.dev/sdk";

export const stripe = webhooks.endpoint.define({
  id: "stripe",
  source: webhooks.stripe<Stripe.Event>(),
});
```

## Handle Stripe webhooks in your own route

If you already receive Stripe webhooks in your app, verify them with `stripe.webhooks.constructEvent()` and trigger a task from the route with `tasks.trigger()`. See [Use your own webhook handler](https://trigger.dev/docs/webhooks/own-handler.md) for a Next.js example.

## Next steps

> [card] [Filters](https://trigger.dev/docs/webhooks/filters.md)
>
> Run each subscriber only for the Stripe events it handles.

> [card] [Waiters](https://trigger.dev/docs/webhooks/waiters.md)
>
> Pause a run until a matching Stripe event arrives.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.