In this episode, we dive into handling custom webhook events from Stripe in a Laravel application. If you ever need your app to do something special when a Stripe event comes in (like sending an email or updating the database), this is how you'll set it up!
We start by touring the webhook controller that the Laravel Cashier package provides. You’ll see how incoming Stripe webhooks are received and dispatched as events inside the app. Then, we set up our own listener for these events, specifically the webhook.received
event, which is a good spot to hook into before any of the built-in logic runs.
As an example, we create a new event listener that watches for the subscription created event from Stripe. To make sure our code only responds to the exact event we want (and not every webhook), we check the event type in the payload before running any logic. This way, you can trigger emails, database updates, or anything else—just for that specific Stripe event!
We test this setup by creating and cancelling subscriptions, checking the Laravel logs to make sure only the correct events are being detected and logged. Now you have a starting point to handle any custom Stripe webhook events you need in your app. In the next episode, we'll show how to send an email when a subscription is cancelled.