Handling webhooks locally can be a challenge. In the past, I have used ngrok using Valet Share to expose my local site to the internet. This worked but required me to either pay for a dedicated URL or update Stripe’s webhook whenever I wanted to run a test locally. I recently discovered Stripe’s CLI, which includes a listen for events feature that forwards webhooks to your local application.
My current local setup uses Laravel Valet to host multiple local development sites. Unfortunately, the Stripe CLI doesn’t immediately work with Laravel Valet. After some searching, I found a solution to get the Stripe CLI working with Laravel Valet to work together.
- Install Stripe CLI: brew install stripe/stripe-cli/stripe
- Authenticate Stripe CLI using testing keys: stripe login –api-key sk_test_xxxxxxxxxxxxxx
- Edit your host file: sudo nano /private/etc/hosts and add a host record for your local site: 127.0.0.1 AddYourSiteHere.test
- Flush your DNS: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
- Run stripe CLI to listen to webhooks: stripe listen –skip-verify –forward-to https://AddYourSiteHere.test/stripe/webhook
- Make sure STRIPE_WEBHOOK_SECRET env value matches the output from Stripe CLI from step 5.
- Your webhooks should now work locally.
Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LY, Weather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.