#jovial_guava_12592

1 messages · Page 1 of 1 (latest)

robust juniperBOT
#

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.

fluid linden
sullen kelp
#

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'

fluid linden
sullen kelp
#

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

fluid linden
#

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

sullen kelp
#

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

fluid linden
#

what's the ID cs_test_xxx in question that you're testing with?

sullen kelp
#

cs_test_a1nugUwJcXeyTL1thKVsURql9bnrq0Gt9ZnJPhrxa9rNMDUgwDxLvlG8xF

fluid linden
#

ah right, you didn't pass it on the line item, you passed it at the top level.

#

so it's in $session->metadata

sullen kelp
#

ok let's try

#

all right, it's working !

#

thank you very much !

fluid linden
#

awesome!

sullen kelp
#

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]

fluid linden
#

yeah unfortauntely not everything is supported via price_data

sullen kelp
#

'line_items' => [
[
'quantity' => 1,
'price_data' => [
'currency' =>'eur',
'unit_amount'=>2000,
'product_data'=> [
'name'=>'20 goals'
],
'metadata'=>[
'product_id' =>'MYPRODUCTIDIN#2'
]
]

],
#

ah ok

fluid linden
#

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?