Level 9
Just need to add exclude route from VerifyCSRFToken
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
My code:
\Stripe\Stripe::setApiKey( env('STRIPE_SECRET_KEY') );
// This is your Stripe CLI webhook secret for testing your endpoint locally.
$endpoint_secret = 'whsec_xxxxxxxxxxxxxxxxxxxx';
$payload = @file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
$event = null;
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'payment_intent.canceled':
$paymentIntent = $event->data->object;
dd($paymentIntent);
case 'payment_intent.payment_failed':
$paymentIntent = $event->data->object;
case 'payment_intent.requires_action':
$paymentIntent = $event->data->object;
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}
http_response_code(200);
I am testing it on local and firing events from stripe cli, however, laravel is throwing 302 error. I have already placed it in public route, and could easily hit the endpoint by accessing in incongito.
Just need to add exclude route from VerifyCSRFToken
Please or to participate in this conversation.