Testing Stripe Webhooks on Local + Production
This guide will help you set up a Stripe webhook for testing purposes using ngrok to create a secure tunnel to your localhost.
npm install -g ngrok
)localhost:3000
Ensure your application is running on localhost:3000
.
Open a new terminal window and run:
You’ll see output similar to this:
Copy the HTTPS forwarding URL (e.g., https://xxxx-xx-xxx-xxx-xx.ngrok.io).
Log in to your Stripe Dashboard. Navigate to Developers > Webhooks. Click Add endpoint. In the Endpoint URL field, paste your ngrok HTTPS URL and add your webhook route. For example: https://xxxx-xx-xxx-xxx-xx.ngrok.io/api/webhook Select the events you want to listen for - we just need to listen to checkout success events. Click Add endpoint.
After creating the webhook:
Click on the newly created webhook in your Stripe Dashboard. Look for Signing secret and click Reveal. Copy this secret. You’ll need it to verify webhook signatures.
Copy the webhook sigining secret in your .env
file for STRIPE_WEBHOOK_ENDPOINT
Remember everytime you want to test locally you will need to have ngrok running. This will likely give you a new tunnel URL which you will have to update in the stripe dashboard.
When you deploy your app you can update the webhook endpoint to your production url /api/webhook
Testing Stripe Webhooks on Local + Production
This guide will help you set up a Stripe webhook for testing purposes using ngrok to create a secure tunnel to your localhost.
npm install -g ngrok
)localhost:3000
Ensure your application is running on localhost:3000
.
Open a new terminal window and run:
You’ll see output similar to this:
Copy the HTTPS forwarding URL (e.g., https://xxxx-xx-xxx-xxx-xx.ngrok.io).
Log in to your Stripe Dashboard. Navigate to Developers > Webhooks. Click Add endpoint. In the Endpoint URL field, paste your ngrok HTTPS URL and add your webhook route. For example: https://xxxx-xx-xxx-xxx-xx.ngrok.io/api/webhook Select the events you want to listen for - we just need to listen to checkout success events. Click Add endpoint.
After creating the webhook:
Click on the newly created webhook in your Stripe Dashboard. Look for Signing secret and click Reveal. Copy this secret. You’ll need it to verify webhook signatures.
Copy the webhook sigining secret in your .env
file for STRIPE_WEBHOOK_ENDPOINT
Remember everytime you want to test locally you will need to have ngrok running. This will likely give you a new tunnel URL which you will have to update in the stripe dashboard.
When you deploy your app you can update the webhook endpoint to your production url /api/webhook