Hi.
I am having problems handling invoice.payment_failed events from Stripe. My handleInvoicePaymentFailed() in my custom WebhookController class does not get called. For now I simply need to add a little extra functionality after the event has been received. I need to update the 'active' field in the database for the user involved.
For this I have the following code in place.
Routes.php
Route::post('stripe/webhook','WebhookController@handleWebhook');
Custom WebhookController in app/controllers - see comments for the problem
<?php
class WebhookController extends \Laravel\Cashier\WebhookController {
public function handleWebhook()
{
// If adding the update code here the Company is updated - I am using Company 1 just for testing for now
$company = Company::find(1);
$company->active = 0;
$company->update();
// Fallback to failed payment check...
return parent::handleWebhook();
}
// This never gets called
public function handleInvoicePaymentFailed(array $payload)
{
// This never happens
$company = Company::find(1);
$company->active = 0;
$company->update();
}
}
When I run an ' invoice.payment_failed' in stripe.com / accounts / webhooks with the following settings my handleInvoicePaymentFailed never gets called. Im unsure how to make that happen from within my class as I obviously only need it to occur at the appropriate time, ie and invoice payment failing.
Webhook settings in Stripe.com
URL: https://my-domain-here/stripe/webhook
Mode: Test
- Send me all events
Then send test webhook
Event: invoice.payment_failed
Version: 2014-11-20 (default)
I also tried changing 'Send me all events' to Select Events - Invoice.payment_failed. I was hoping that the default handleWebhook would then channel the event to my own handleInvoicePaymentFailed(). Instead i GET A 'Test webhook sent successfully' message but no changes in the database.
- What should actually change in the database when this event is received? I thought it would cancel the account so that I was would then see a 'subscription_ends_at' date appear?
Finally I have also tried creating a route directly to the handleInvoicePaymentFailed() in my WebhookController
Route::post('stripe/webhook/handle-invoice-payment-failed', 'WebhookController@handleInvoicePaymentFailed');
In which case I get the following 500 error
Argument 1 passed to WebhookController::handleInvoicePaymentFailed() must be of the type array, none given
Any advice welcome, im out of ideas now.
Thanks.