Setting Up Stripe Webhook for Testing with ngrok
This guide will help you set up a Stripe webhook for testing purposes using ngrok to create a secure tunnel to your localhost.Prerequisites
- A Stripe account
- Node.js and npm installed
- ngrok installed (
npm install -g ngrok
) - Your application running on
localhost:3000
Steps
1. Start Your Local Server
Ensure your application is running onlocalhost:3000
.
2. Start ngrok
Open a new terminal window and run:3. Configure Stripe Webhook
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.4. Get Your Webhook Signing Secret
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.5. Set .env for Webhook secret
Copy the webhook sigining secret in your.env
file for STRIPE_WEBHOOK_ENDPOINT