Laravel Cashier Webhook: Get current user Laravel Cashier Webhook: Get current user laravel laravel

Laravel Cashier Webhook: Get current user


Reading the answer to this question - the event is fired on the date/time the subscription actually ends, not when the customer initiates the cancellation.

Based off Laravels Cashier Docs - your route should actually be:

Route::post('stripe/webhook', 'Laravel\Cashier\WebhookController@handleWebhook');

Make sure your webhook settings in stripe actually point to yourapp.com/stripe/webhook

Based on the handleWebhook method in the Laravel\Cashier code - yes, any appropriately named method (begins with handle, camelcased to a strip event) will override an existing one.


If you want to use your extended controller in the routes; remember to add a constructor at the beginning of the class:

public function __construct(){  parent::__construct();}

So the handleWebhook method is available when you do

Route::post('stripe/webhook', 'WebhookController@handleWebhook');

instead of calling the Laravel\Cashier\WebhookController in the route.


I have this working and I am pointing the route to my Controller.

Route::post(    'stripe/webhook',    'WebhookController@handleWebhook');

Since we are extending the base controller any methods in the base controller are already available. The point of this controller is to have access to all of the base controller methods. This way you can extend any new methods or overwrite existing ones.

I also had an issue with getting my code to catch webhook events. Something to note is that if you are in the test environment of stripe and triggering webhook events make sure that you add the env variable.

CASHIER_ENV=testing

In the base webhook controller it checks first to make sure the events exists and the event wont exist if the webhook is being generated within the test environment.

public function handleWebhook(Request $request){    $payload = json_decode($request->getContent(), true);    if (! $this->isInTestingEnvironment() && ! $this->eventExistsOnStripe($payload['id'])) {        return;    }    $method = 'handle'.studly_case(str_replace('.', '_', $payload['type']));    if (method_exists($this, $method)) {        return $this->{$method}($payload);    } else {        return $this->missingMethod();    }}


$billable = $this->getBillable($payload['data']['object']['customer']);$user = $billable; // billable is User object