Skip to Content
DocsStripeWebhook Integration

Webhook Integration

In this part of the documentation, you will learn how to integrate Stripe webhooks for both local and live environments.

Webhook Integration for Local Development

Follow the instructions below to integrate the Stripe webhook for local development.

  1. Go to the Developers tab in the bottom left corner of the Stripe dashboard.

stripe

  1. Click on the Webhooks tab in the dropdown menu.

stripe

  1. Select Test in a local environment.

stripe

  1. Install the Stripe CLI  and log in to Stripe.
stripe login
  1. Run this command to forward the event to the webhook. I’ve added this script to package.json file
npm run stripe:listen
  1. Add the webhook secret to your .env file.

stripe

Copy the secret from the terminal and add it to this variable:

STRIPE_WEBHOOK_SECRET=YOUR_WEBHOOK_SECRET

Now you can test the subscription—it should work in your local environment.

Webhook Integration for Live Site

In the previous section, we covered how to integrate webhooks for local testing. Now we’ll learn how to integrate Stripe webhooks for a live site.

Follow these instructions to enable the webhook for your live site:

  1. Go to the Webhooks tab under the Developers tab (same as before). Click the Add destination button.

stripe

  1. Select the latest API version from this drop-down menu.

stripe

  1. Select the events you want to listen to and click the Continue button.

stripe

  1. After clicking the Continue button, you will see the Choose destination type page. Select the Webhook endpoint option and click the Continue button.

stripe

  1. Add your live site URL and click the Create destination button. You will be redirected to the Webhook endpoint page.

stripe Note: Your live site URL is not just the root URL. It must follow this pattern: https://yoursite.com/api/webhook

  1. Copy the secret key.

stripe We’re almost done! The last step is to copy the webhook secret for your live site and add it to your .env file using this variable:

STRIPE_WEBHOOK_SECRET=YOUR_WEBHOOK_SECRET