· 5 years ago · Sep 28, 2020, 02:32 PM
1<?php
2
3require 'stripe/Stripe.php';
4
5$publishable_key = "pk_test_uvgVU8wBVjCfon89TYB109Jf00oF84Za19";
6$secret_key = "********************************************";
7
8Stripe::setApiKey($secret_key);
9
10$payload = @file_get_contents('php://input');
11$event = null;
12
13
14try {
15 $event = \Stripe\Event::constructFrom(
16 json_decode($payload, true)
17 );
18} catch(\UnexpectedValueException $e) {
19 // Invalid payload
20 http_response_code(400);
21 exit();
22}
23/*
24// Handle the event
25switch ($event->type) {
26 case 'payment_intent.succeeded':
27 $paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
28 // Then define and call a method to handle the successful payment intent.
29 // handlePaymentIntentSucceeded($paymentIntent);
30 break;
31 case 'payment_method.attached':
32 $paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
33 // Then define and call a method to handle the successful attachment of a PaymentMethod.
34 // handlePaymentMethodAttached($paymentMethod);
35 break;
36 // ... handle other event types
37 default:
38 // Unexpected event type
39 http_response_code(400);
40 exit();
41}
42
43http_response_code(200);
44*/
45?>