How to use Stripe CLI with Laravel Valet

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.

  1. Install Stripe CLI: brew install stripe/stripe-cli/stripe
  2. Authenticate Stripe CLI using testing keys: stripe login –api-key sk_test_xxxxxxxxxxxxxx
  3. Edit your host file: sudo nano /private/etc/hosts and add a host record for your local site: 127.0.0.1 AddYourSiteHere.test
  4. Flush your DNS: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
  5. Run stripe CLI to listen to webhooks: stripe listen –skip-verify –forward-to https://AddYourSiteHere.test/stripe/webhook
  6. Make sure STRIPE_WEBHOOK_SECRET env value matches the output from Stripe CLI from step 5.
  7. 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.LYWeather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.  

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.