#kqtipow - Checkout Session metadata
1 messages ยท Page 1 of 1 (latest)
Hello ๐
You can do this by having your server retrieve the Checkout Session by the session_id that you get in the success URL
So when the user completes their payment, they will be directed to a URL like
http://localhost/test/success.php?session_id=cs_test_123
You can then retrieve the Session with a call to retrieve and then the metadata will be right on the object:
'cs_test_123',
[]
);```
Yes, i have retieved succesfully
but wondering how to access that variable metadata
I think it will look something like
$order_id = $session->metadata["order_id"]
Have you tried that or just accessing $session->metadata to see what is in there?
Do you have the ID of the checkout session that that is for?
$checkout_session = \Stripe\Checkout\Session::retrieve($session_id); I have it this way
Brilliant!
your answer helped me!
thanks a lot
$order_id = $session->metadata["order_id"]
that did the magix
Nice! What was your code for that before out of curiosity?
$paymentIntent = \Stripe\PaymentIntent::retrieve($checkout_session->payment_intent);
$metadata = $paymentIntent->metadata['order_id'];
Maybe i was tried to access data inside on Stripe side
Ah yeah, the PaymentIntent has seperate metadata. You can set that metadata when creating the Checkout Session if you want https://stripe.com/docs/api/checkout/sessions/create?lang=php#create_checkout_session-payment_intent_data
You mean I can set customer name/email at PHP snippet, when I created session ID?
sorry, session*
My link there was just about setting the metadata on the payment intent instead of just the Checkout Session
You can set the Customer email when creating the Checkout Session https://stripe.com/docs/api/checkout/sessions/create?lang=php#create_checkout_session-customer_email
To set the name, you would have to create a Customer object beforehand with the name and email you want, then you can pass that Customer's ID to the create call's customer parameter https://stripe.com/docs/api/checkout/sessions/create?lang=php#create_checkout_session-customer
Of course, good luck! Just let us know if you run in to anything else
Thanks!