30 lines
895 B
PHP
30 lines
895 B
PHP
<?php
|
|
|
|
// Optionally, handle webhooks from Stripe
|
|
// This allows Stripe to notify your server when certain events occur (e.g., payment successful, chargeback, etc.).
|
|
|
|
$endpoint_secret = 'your_webhook_secret'; // You get this from the Stripe Dashboard
|
|
|
|
$input = @file_get_contents('php://input');
|
|
$sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
|
|
|
|
try {
|
|
$event = \Stripe\Webhook::constructEvent($input, $sig_header, $endpoint_secret);
|
|
|
|
switch ($event->type) {
|
|
case 'payment_intent.succeeded':
|
|
$paymentIntent = $event->data->object;
|
|
// Handle successful payment here
|
|
break;
|
|
// Handle other events
|
|
}
|
|
} catch(\UnexpectedValueException $e) {
|
|
// Invalid payload
|
|
http_response_code(400);
|
|
exit();
|
|
} catch(\Stripe\Exception\SignatureVerificationException $e) {
|
|
// Invalid signature
|
|
http_response_code(400);
|
|
exit();
|
|
}
|