#john1219669
1 messages · Page 1 of 1 (latest)
What do you mean that you can't access the data? Can you elaborate more and what are you trying to access from?
Sorry, the data sent back via the webhook. I assumed $testing = $event->data->object->id; would access the stripe payment id and that I could access all the other information so I can store it in the database and process it etc? I can see this data with CLI whilst fomatting in JSON I just don't seem to be able to access it on my local webhook processing code
This is from CLI
This is the data I want to access from within the webhook handler
Thanks for sharing! Can you do $testing = $event->data->object->id outside of the switch? It is likely that $testing = $event->data->object->id isn't hit within switch type
No, the first value is not updated in the database now so that hasn't worked. Here is the code and the CLI again
<?php
require_once '../core/init.php';
require_once 'stripe/init.php';
require_once 'stripe/stripe_secret.php';
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
\Stripe\Stripe::setApiKey('whsec_8a2f032a6fc8b85c8c84041fad803d69638475aaaac5fad418178c2374f7e196');
$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();
}
$testing = $event->data->object->id;
// Handle the event
switch ($event->type) {
case 'checkout.session.completed':
//THIS WORKS SO I KNOW THERE IS SOME DATA THERE
$db->query("UPDATE webhook SET worked = 3 WHERE webhook_id = 1");
//THIS DOESN'T WORK. I CANNOT GET ACCESS TO ANY INFORMATION FROM WITHIN THE OBJECT
$db->query("INSERT INTO stripe_charges (`booking_code`) VALUES ('$testing')");
break;
case 'payment_intent.succeeded':
$paymentIntent = $event->data->object; // contains a \Stripe\PaymentIntent
break;
case 'payment_method.attached':
$paymentMethod = $event->data->object; // contains a \Stripe\PaymentMethod
break;
// ... handle other event types
default:
echo 'Received unknown event type ' . $event->type;
}
http_response_code(200);
?>
Where did you print the request body? I don't see it in your code. If you're able to print, you should be able to retrieve the object
I'm sorry, what do you mean?
In your CLI, the request body was printed. How did you print it? I don't see it in your code here. If you're able to print the JSON body, its fields should be retrievable