๐ŸชRegistering Event Handlers

Registering your own handlers

As previously stated , we do not handle any events by default, rather allow you to handle your own.

In exactly the same way that Cashier does. The only difference is the event that you subscribe to.

So instead of the below code (outlined in Cashier Docs):

<?php
 
namespace App\Providers;
 
use App\Listeners\StripeEventListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Laravel\Cashier\Events\WebhookReceived;
 
class EventServiceProvider extends ServiceProvider
{
    protected $listen = [
       WebhookReceived::class => [
          StripeEventListener::class,
       ],
    ];
}

You would simply use the following instead. This will tell Laravel to handle webhooks received via the connect endpoint instead.

The advantage of this, is that it allows you to register webhooks in parallel with Connect, which is sometimes required when you are dealing with both direct and destination charges.

In the next articles we will provide some examples of event handling.

Last updated