I use spatie/laravel-stripe-webhook for handle the webhook sending from stripe. I use stripe CLI for test with the following command :
stripe listen --events checkout.session.completed --forward-to localhost:8000/api/webhook/checkout
Everything going well and I have this response in my console :
> Ready! Your webhook signing secret is whsec_mSz72pLPb4B******rfvvYajj641iqZ7 (^C to quit)
2020-06-10 14:12:07 --> \checkout.session.completed\ [\evt_1GsSmjLG****Fak7OpFNC8c2\]
2020-06-10 14:12:07 <-- [200] POST http://localhost:8000/api/webhook/checkout [\evt_1GsSmj*****OFak7OpFNC8c2\]
but... nothing happened... I have no error in my laravel.log, anything...
I following all the readme file in github Spatie and I doing that :
Routes/api.php :
Route::stripeWebhooks('webhook/checkout');
App/Providers/EventServiceProvider.php :
protected $listen = [
Registered::class => [
SendEmailVerificationNotification::class,
],
'stripe-webhooks::checkout.session.completed' => [
App\Listeners\HandleSubscriptions::class
]
];
I have to disabled :
Parent::boot();
because if enabled this one, I have a throw exceptions :
[object] (ReflectionException(code: -1): Class App\\Providers\\App\\Listeners\\HandleSubscriptions does not exist at /var/www/private/bnb-v2/bnb-back/vendor/laravel/framework/src/Illuminate/Container/Container.php:803)
and I can't handle the stripeWebhook.
App/Listeners/HandleSubscriptions.php :
class HandleSubscriptions implements ShouldQueue
{
/**
* Handle the event.
*
* @param object $event
* @return void
*/
public function handle(WebhookCall $webhookCall)
{
// you can access the payload of the webhook call with `$webhookCall->payload`
$payload = $webhookCall->payload;
// // Handle the event
switch ($payload->type) {
case 'checkout.session.completed':
$sessions = $payload->data->object;
SubscriptionController::handle_checkout_session($sessions);
break;
case 'checkout.session.async_payment_succeeded':
$paymentSuccess = $payload->data->object; // contains a \Stripe\PaymentMethod
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached($paymentMethod);
break;
case 'customer.created':
$customer = $payload->data->object;
break;
// ... handle other event types
default:
// Unexpected event type
http_response_code(400);
exit();
}
http_response_code(200);
}
}
If someone have a idea...