#energetic_chipmunk_58090
1 messages · Page 1 of 1 (latest)
hello
Hi
In general webhook signature fails for two main reasons:
- Using wrong webhook secret
- Changing the body request of the event
i invite you to start a new clean project following this guide:
https://stripe.com/docs/webhooks/quickstart
In order to understand correctly how Stripe Webhook signature works
i also tried the quickstart which generated me the webhook code
exactly the one you sent me
webhook secreet is the one that starts with we_
public function stripe_webhook() {
$endpoint_secret = 'we_1NlUSqGgbXKwgAV1TxypMJx7';
$payload = @file_get_contents('php://input');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
echo '⚠️ Webhook error while parsing basic request.';
http_response_code(400);
exit();
}
if ($endpoint_secret) {
// Only verify the event if there is an endpoint secret defined
// Otherwise use the basic decoded event
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
try {
$event = \Stripe\Webhook::constructEvent(
$payload, $sig_header, $endpoint_secret
);
} catch(\Stripe\Exception\SignatureVerificationException $e) {
// Invalid signature
echo '⚠️ Webhook error while validating signature.';
http_response_code(400);
exit();
}
}
// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
// Then define and call a method to handle the successful payment intent.
// handlePaymentIntentSucceeded($paymentIntent);
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
// Then define and call a method to handle the successful attachment of a PaymentMethod.
// handlePaymentMethodAttached($paymentMethod);
break;
default:
// Unexpected event type
error_log('Received unknown event type');
}
http_response_code(200);
}
Webhook error while validating signature.';
this is my webhook function
i tried multiple times from scratch but no luck
$endpoint_secret = 'we_1NlUSqGgbXKwgAV1TxypMJx7';
This isn't the webhook secret, this is the webhook Id