Use Stripe CLI with Laravel Herd or Valet or nginx.

Rezaul H Reza 17 February 2024 Tutorial 3 minutes read

Stripe ClI listeting to cashier webhook
Stripe is a terrific company for developers wanting to integrate paytments into their application. Their API's and developer facilities are top-notch. One of the awesome tools Stripe offers is the Stripe CLI, a command-line tool for testing and simulating webhooks easily on your local device. This is pretty useful when you want to use laravel cashier to develop your saas product locally.

However, the Stripe CLI doesn't immediately work with Laravel Herd, a blazing fast, native Laravel and PHP development environment for macOS, which includes PHP, nginx, dnsmasq, and Node.js. This trick also applies for laravel valet, or local site configured with nginx.

Ensure stripe cli installed in your local. Stripe CLI Installation guide




1. Update your /etc/hosts file


To make the Stripe CLI work with Laravel Valet, make a change to your hosts file (/etc/hosts). You can edit it with Nano-editor using:


sudo nano /etc/hosts



Add the following rule to your /etc/hosts file, replacing `mysite.test` with your domain:


127.0.0.1 mysite



Save the file.

2. Flush the DNS cache

Flush the DNS cache to ensure the changes take effect:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder


You might also need to clear your browser cache/cookies.

 3. Use Stripe CLI with Laravel Herd/Valet/Localhost 🚀

Now you can use the Stripe CLI with Laravel Valet. For example, if you're using Laravel Cashier with Stripe, you can forward webhooks to your local application with:


stripe listen --forward-to https://mysite.test/stripe/webhook



Wrapping up

Give it a try and let me know how it goes!

Related Posts

use-value-objects-in-laravel
Use Value Objects in Laravel 5 minutes read

Read more

Rezaul H Reza,07 January 2023

Write a comment

Comments (1)

Jan

2 days ago

Hello Rezaul, you are a live saver!!! Works like a charm. Thank You!

Leave a Reply