Initial
This commit is contained in:
29
Stripe/payments/webhooks.php
Normal file
29
Stripe/payments/webhooks.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?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();
|
||||
}
|
||||
Reference in New Issue
Block a user