In this episode, we're diving into setting up Stripe webhooks so our app can respond when a user signs up for a subscription—especially to track if a referral code was used. First, you'll see how to set up a public URL for your local development environment using Expose (or any other tool you prefer), so Stripe can send webhook events to your app during testing.
We'll walk through creating the Stripe webhook endpoint on the Stripe dashboard, making sure to select all the events listed in the Laravel Cashier docs. You'll also learn why it's important to exclude CSRF protection from the webhook route and how to add your Stripe webhook signing secret to your app's configuration for security.
Once webhooks are hitting your app, you'll see how Laravel Cashier dispatches a specific event whenever Stripe sends data—so you can hook into that and create your own listener, like a StripeEventListener
. We'll log out the incoming webhook payload together to check everything works, and you'll see how the referral code metadata comes through.
Finally, we'll quickly update the dashboard so it properly reflects when a user has an active subscription. By the end, we're fully set up to not only receive Stripe webhooks, but also start doing something useful with the data, like connecting referral codes to subscriptions. The foundation is ready for more advanced handling in the next parts!