Docs
Webhook Integration

Webhook Integration

In this part of the documentation you will learn how to integrate stripe webhook for local and live environment.

Webhook integration for local development

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

  1. Go to the Webhooks tab under the Developers page

stripe

  1. Now click on the Add endpoint button.

stripe

  1. Select Test in a local environment

stripe

  1. Install Stripe CLI (opens in a new tab) and login 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 the env file.

stripe

Copy it from the terminal and add it to this variable.

STRIPE_WEBHOOK_SECRET=YOUR_WEBHOOK_SECRET

Now go ahead and test the subscription, it should work in your local environment.

Webhook integration for the live site

In the last part, we saw how to integrate Webhook for testing locally. Now we are going to see how to integrate Stripe Webhook 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.

stripe

  1. Now add your site URL here: stripe

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

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

stripe

  1. Now click on the Select Events button.

stripe

Once you click on the button, you’ll see something like this. Now check the Select all events box. Click the Add Events button.

stripe

  1. Now click on the Add endpoint button.

stripe

We are almost done. One last thing we have to do is get the Webhook secret for the live site and add that to the .env file.

After you’ve added the endpoint you’ll see something like this. Click on the URL.

stripe

Click Reveal, you’ll see the secret key there. Copy the key and add that to your live site's .env file.

stripe