Stripe is a payment gateway that is becoming increasingly popular in the Web industry. It offers payment processing services, which can be easily integrated into your Web application using the Stripe API.
As in any other payment gateway it also provides us with Webhooks to make sure the payments are done in a reliable way. Webhooks are a tool Stripe uses to notify your site of account events. Although Webhooks can be used for many purposes, they are especially important when using subscriptions , where most activity occurs at the same time and behind the scenes.
Recently I was working on Stripe payment gateway and wanted to test Stripe Webhooks on localhost setup, before deploy code on live server. But the problem comes up when the developer is working on localhost setup since Stripe Webhooks need publicly accessible URLs to hit and work with. let me tell you!
How to Run Stripe Webhooks URL from localhost?
Then i have found perfect tool ngrok to expose a local web server to the internet.
ngrok is an application for Windows, Mac OS X, and Linux that creates a tunnel but also allows you to inspect all traffic that goes through the tunnel and replay that traffic for testing.
How to use ngrok and set up Stripe Webhooks url for localhost
1) First Download ngrok and extract it on your computer
2) Double click ngrok.exe and you will see a screen like so:
3) Try typing ngrok.exe http 80 at this terminal prompt to expose port 80
While running it, You will see a screen like so:
The Online is a good sign. It means the tunnel is working fine and your local web is now accessible at that particular 80 port.
Now your local server exposed to the web so it can be hit with webhooks from external services, just specify your ngrok url as the endpoint with your webhooks service and you’re almost done.
For example if we you have Stripe Webhooks Url on localhost like so
4) You can set up this url http://f253021b.ngrok.io/stripeproject/webhook.php to send test webhooks to your integration’s endpoint within your account’s webhooks settings.
Let me know if you get stuck anywhere in the process. Share your thoughts and experiences in the comments below!