I’m getting:
warning Undefined array key “HTTP_STRIPE_SIGNATURE”
When I visit https:/example.com/webhook.php. That is the page where I have this code:
<?php
require "..../stripe-php-11.0.0/init.php";
// Your Stripe webhook endpoint secret
$webhook_secret = "whsec_...";
// Initialize Stripe with your secret API key
StripeStripe::setApiKey("sk_test_....");
// Get the raw request body and Stripe signature header
$payload = file_get_contents("php://input");
$sig_header = $_SERVER["HTTP_STRIPE_SIGNATURE"];
try {
// Verify the signature
$event = StripeWebhook::constructEvent(
$payload,
$sig_header,
$webhook_secret,
);
} catch (Exception $e) {
// Invalid signature or other error
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case "checkout.session.completed":
$session = $event->data->object;
// Process the 'checkout.session.completed' event here
// You can retrieve information about the completed session in $session
// Example: Send a confirmation email to the customer
// mail($session->customer_email, 'Order Confirmation', 'Thank you for your purchase!');
$sessionId = $session->id;
// Implement your logic to initiate the file download here
http_response_code(200); // Acknowledge receipt of the event
break;
// Add more cases to handle other types of events as needed
// case 'invoice.paid':
// // Handle invoice paid event
// break;
default:
// Unknown event type
http_response_code(200);
break;
}
I have already configured the webhook to point to the webhook URL and I checked and a successful stripe-signature was there after a successful checkout event. It’s just not verifying it when I go to the site manually. I’ve already had events sent there I can see it on the dashboard. I obviously replaced all the '...'
in my code with the correct stuff. How do I fix this?