Kenziiee Flavius
Kenziiee Flavius

Reputation: 1947

Using Stripe Webhooks with Laravel Valet

Scenario

I'm trying to use stripe to set up payments on my application, but when i try to setup webhooks it throws an error because its trying to send to a site that technically doesn't exist (because it exists locally).

obviously internally i can provide the domain name but from an external source "mysite.test" doesnt exist.

Is there a way to get the IP address / port for my specific laravel valet site? I tried pinging "mysite.test" and it returned 127.0.0.1 but my guess is that is the valet server not the specific website because im tyring to link to stripe.

The error in question: "Test webhook error: Domain unknown"

Upvotes: 1

Views: 789

Answers (2)

Tim
Tim

Reputation: 783

Stripe now offers a CLI that makes it easy to handle Webhooks in Laravel Valet. There are a few gotchas explained here: https://timleland.com/how-to-use-stripe-cli-with-laravel-valet/

  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.

Upvotes: 1

koopajah
koopajah

Reputation: 25652

Your server runs locally so it does not exist externally. To remediate this you have to use a tool that lets the rest of the world connect to your local server. I would recommend ngrok for this.

Upvotes: 1

Related Questions