#jovial_guava_12592
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- jovial_guava_12592, 18 minutes ago, 13 messages
hi! once you have the session ID you can retrieve it from the API and get information like what Prices were in the line_items so you know what was bought.
https://dev.to/stripe/purchase-fulfilment-with-checkout-or-wait-what-was-i-paid-for-335d
ok let's try this, thank you !
hum hum
I would like to put in my sessions an id of my product and get it back once the paiment has been done in my success page
in 'product_data' I can add 'name' but not 'MyProductID'
product_data[metadata] would let you pass whatever extra information you'd like (https://stripe.com/docs/api/metadata)
well, it doesn't work, am I missing something ?
$checkout_session = \Stripe\Checkout\Session::create([
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/success.php?sid={CHECKOUT_SESSION_ID}',
'line_items' => [
[
'quantity' => 1,
'price_data' => [
'currency' =>'eur',
'unit_amount'=>2000,
'product_data'=> [
'name'=>'20 goals'
]
],
],
],
'metadata'=>[
'product_id' =>'MYPRODUCTID'
] ,
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
'automatic_tax' => [
'enabled' => true,
]
]);
I can't see MYPRODUCTID when I come back on my success page
what code do you use to look for it?
in that code you've attached it to the line_items->data[0] object so that's where it would be found
try {
$session = $stripe->checkout->sessions->retrieve($_GET['sid']);
// $customer = $stripe->customers->retrieve($session->customer);
$toto = $stripe->checkout->sessions->allLineItems(
$_GET['sid'],
[]
);
var_dump($toto);
exit;
it's not in the response
what's the ID cs_test_xxx in question that you're testing with?
cs_test_a1nugUwJcXeyTL1thKVsURql9bnrq0Gt9ZnJPhrxa9rNMDUgwDxLvlG8xF
ah right, you didn't pass it on the line item, you passed it at the top level.
so it's in $session->metadata
awesome!
but...
when I try to put metadat in line_items, it crashes
Fatal error: Uncaught Error sending request to Stripe: (Status 400) (Request req_qjRMdJ38BHFOUX) Received unknown parameter: line_items[0][price_data][metadata]
yeah unfortauntely not everything is supported via price_data
'line_items' => [
[
'quantity' => 1,
'price_data' => [
'currency' =>'eur',
'unit_amount'=>2000,
'product_data'=> [
'name'=>'20 goals'
],
'metadata'=>[
'product_id' =>'MYPRODUCTIDIN#2'
]
]
],
ah ok
so instead if you want metadata on the Price you have to create the Price separately (via $price = $stripe->prices->create(...) and then pass the ID of the resulting object as price to the CheckoutSession instead of using the price_data 'shortcut'
but really it depends, and the Session-level metadata is probably enough for your use case?