#john1219669

1 messages · Page 1 of 1 (latest)

floral estuaryBOT
rotund fossil
#

What do you mean that you can't access the data? Can you elaborate more and what are you trying to access from?

noble kestrel
#

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

rotund fossil
#

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

noble kestrel
#

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);
?>

rotund fossil
#

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

noble kestrel
#

I'm sorry, what do you mean?

rotund fossil
#

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

noble kestrel
#

Ahhhh you were right! I spent all day yesterday trying to get this working, but just not I forgot to 'forward'. Now that the code is outside the case its working

#

Thanks a lot for the help