I need to create an endpoint to know the status of the oxxo vouchers, since based on this information in my database I will modify when a voucher has already been paid or when it has expired and not been paid. I am using Stripe API as a payment gateway and I am using php.
I have seen the documentation Triggering actions with webhooks but I really can't understand anything.
As a first step I have already created the endpoint webhook, I don't know if the events I add are correct because the documentation does not specify which ones are necessary and which ones are not.
As a second step in the file verifcar.php
I put the first example code that comes in the documentation.
verify.php
<?php
// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('sk_test_API_KEY');
$payload = @file_get_contents('php://input');
$event = null;
try {
$event = \Stripe\Event::constructFrom(
json_decode($payload, true)
);
} catch(\UnexpectedValueException $e) {
// Invalid payload
http_response_code(400);
exit();
}
// Handle the event
switch ($event->type) {
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a StripePaymentIntent
handlePaymentIntentSucceeded($paymentIntent);
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a StripePaymentMethod
handlePaymentMethodAttached($paymentMethod);
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}
http_response_code(200);
?>
This is where I don't know what else to do, I have to necessarily execute some commands in the console that comes in the documentation? Stripe will run the file verificar.php
by the url you specify when creating the endpoint?? In the code that I put as an example, in which line do I get the vouchers to be able to know the status of each one and be able to make the modification in my DB?
I hope you can guide me with this
Of course, now you must generate an event as if you had paid at OXXO. If you use the test emails, you can generate the events without having to go to an OXXO store. For example, if you use [email protected] as the client email, then stripe will send a webhook to elastillar.com/verificar.php immediately.
More details here: https://stripe.com/docs/payments/oxxo/accept-a-payment#test-integration
When creating the payment, you should save the payment intent token, which you get in the webhook payload like this: