A PHP script that handles Stripe webhook events to process payment notifications like completed checkout sessions.
// Source: https://github.com/stripe-samples/accept-a-payment | License: MIT | Copyright 2019- Stripe, Inc. (https://stripe.com)
// Provided via justclaw.it.com; keep this notice with the code.
<?php
require_once '../vendor/autoload.php';
require_once '../secrets.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
http_response_code(405);
exit();
}
$stripe = new \Stripe\StripeClient([
"api_key" => $stripeSecretKey,
]);
$payload = file_get_contents('php://input');
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'] ?? '';
$webhook_secret = getenv('STRIPE_WEBHOOK_SECRET');
if ($webhook_secret) {
try {
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $webhook_secret);
} catch (Exception $e) {
echo 'Webhook signature verification failed.';
http_response_cod
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key