#Gamx
1 messages Β· Page 1 of 1 (latest)
Hi let's break down your question a little bit
- I believe it should be possible by just 1 call Retrieve Checkout Session API, expanding all the fields you need
- That request seems to retrieve a Checkout Session, but passing in a Payout object id (po_xxx) so it's expected to error
Hello, thanks for your answers, i tried everything with expand, using for example, this call to expand first line_items from the call :
$session = $stripe->checkout->sessions->retrieve(
$session_id,
[],
["stripe_account" => $connected_account_id],
['expand' => ['line_items']]
);
Am I doing a typo error ? If i'm making the call without expand, i don't see the line_items object anyway
That's why i used
$line_items = $stripe->checkout->sessions->allLineItems('cs_test_xxxx', [],
["stripe_account" => $connected_account_id]
);
to get those line_items elements. And now, even with that call, i can't expand data.price.metadata, but i can see the metadata object as "stripe object"
Hmm okie that API is an paginated API. Have you tried auto-pagination? https://stripe.com/docs/api/pagination/auto?lang=php
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
It looks useful, prettier code with it, but same result unfortunately, i can't achieve expanding metadata
$line_items = $stripe->checkout->sessions->allLineItems('cs_test_b1ThQoCls8Qebk8eAZBUjysOotAAaykR5V2bngutgNcG0h8FNleI4jThfu',
[],
["stripe_account" => $connected_account_id],
['expand' => ['price.metadata']]
);
foreach ($line_items->autoPagingIterator() as $line_item) {
var_dump($line_item);
}
metadata is still a stripe object, not usable
What does it give you with that var_dump?
Just showing you one line of the array (one product):
object(Stripe\LineItem)#20 (10) {
["id"]=>
string(27) "li_1Mamk5Ps9ZLUUgGha7TQnGkS"
["object"]=>
string(4) "item"
["amount_discount"]=>
int(0)
["amount_subtotal"]=>
int(2000)
["amount_tax"]=>
int(0)
["amount_total"]=>
int(2000)
["currency"]=>
string(3) "eur"
["description"]=>
string(26) "1 BrΓ»leur et 7 P'tit Cali"
["price"]=>
object(Stripe\Price)#25 (19) {
["id"]=>
string(30) "price_1Mamk5Ps9ZLUUgGh8wiTLniC"
["object"]=>
string(5) "price"
["active"]=>
bool(false)
["billing_scheme"]=>
string(8) "per_unit"
["created"]=>
int(1676235949)
["currency"]=>
string(3) "eur"
["custom_unit_amount"]=>
NULL
["livemode"]=>
bool(false)
["lookup_key"]=>
NULL
["metadata"]=>
object(Stripe\StripeObject)#30 (0) {
}
["nickname"]=>
NULL
["product"]=>
string(19) "prod_NLTh07BAf3Jnju"
["recurring"]=>
NULL
["tax_behavior"]=>
string(11) "unspecified"
["tiers_mode"]=>
NULL
["transform_quantity"]=>
NULL
["type"]=>
string(8) "one_time"
["unit_amount"]=>
int(1000)
["unit_amount_decimal"]=>
string(4) "1000"
}
["quantity"]=>
int(2)
}
['expand' => ['data.price.metadata']]*****
Hmm so you have multiple line items but it will always returns the first one?
no matter of pagination?
Nope, it returns everything, i just showed you the first line, same for each line
ah okie
let's try expanding line_items.price.metadata (I am guessing)
In both API (Retrieve Checkout Session itself, or Retrieve Line Items on a Checkout Session)
Same, nothing at all in trieve checkout session itself, or in retreive line items
Even if i'm not able to expand those metadata directly, should i be able to expand data.price.product ? I know the metada are present in there, this is how i'm getting it
using :
$product = $stripe->products->retrieve(
$itemproductstripeid,
[],
["stripe_account" => $connected_account_id]
);
$itemoptions=$product["metadata"]["item_options"];
i can get for example item_options metadata π
Yeah this should work if you already have the product id, ie. prod_NLTh07BAf3Jnju above
And that's Product's metadata, correct? not Price's metadata
it works when doing the call directly, yep, but not when i'm using that 'expand' stuff, i never got 'expand' to work properly in any call. So i'm getting that product ID from the line_items call, and then in a foreach calling products-> retrieve on that product ID, for each line
yep, when builiding the checkout sessions it looks like so :
$line_items[] = [
'quantity' => $product_in_cart['quantity'],
'price_data' => [
'currency' => stripe_currency,
'unit_amount' => (float)$product_in_cart['final_price'] * 100,
'product_data' => [
'name' => $product_in_cart['meta']['name'].' '.$product_in_cart['options_name'],
'description' => $description,
'metadata' => [
'item_id' => $product_in_cart['id'],
'item_options' => $product_in_cart['options'],
'item_packcontent' => $jsonpackcontent,
'item_shipping' => $product_in_cart['shipping_price'],
'item_img' => $product_in_cart['meta']['img']
]
]
]
];
Okie. and you notice this different between a Checkout Session in your own account, vs. a Checkout Session in a Connected Account?
yes
Like in your own account you were able to expand?
in my platform account i get everything directly using ->allLineItems , not even had to use expand at all
Okie this sounds like a legitimate bug. Gimme sometimes to reproduce
Sure, thanks, i hope i didn't miss something stupid losing your time
when i check my logs in my platform account, when creating a session checkout i can see this directly : {
"metadata": {
"discount_code": "",
"address_street": "22 Pl xxx",
"tel": "0000000000",
"address_country": "France",
"first_name": "Ga",
"shipping_total": "10",
"discount_value": "0",
"account_id": "1",
"address_zip": "0820",
"address_city": "Sed",
"last_name": "GE"
},
"line_items": {
"0": {
"price_data": {
"unit_amount": "600",
"currency": "EUR",
"product_data": {
"description": " / ",
"metadata": {
"item_shipping": "10",
"item_packcontent": "[]",
"item_options": "",
"item_img": "uploads/bruleur.png",
"item_id": "13"
},
"name": "Bruleur rond rouge "
}
},
"quantity": "4"
}
},
"customer_email": "xxx@xxx.fr",
"cancel_url": "https://xxxxt",
"mode": "payment",
"success_url": "https://xxxxxx",
"shipping_options": {
"0": {
"shipping_rate_data": {
"display_name": "Normal",
"type": "fixed_amount",
"fixed_amount": {
"amount": "1000",
"currency": "eur"
},
"delivery_estimate": {
"minimum": {
"value": "3",
"unit": "business_day"
},
"maximum": {
"value": "5",
"unit": "business_day"
}
}
}
}
},
"payment_method_types": {
"0": "card"
}
}
i would like to get an equivalent directly with my connected account
I expanded 'data.price.product' and yes I do see the result
can you show me your code please ?
It's ruby but here you are
line_items = Stripe::Checkout::Session.list_line_items('cs_test_xxx', {
expand: ['data.price.product'],
limit: 10
}, {
stripe_account: 'acct_xxx'
})
p line_items
is there a way to translate it to php just to see if i'm not doing a typo error ? i'm asking too much sorry π
Can you locate your request in your Dashboard log? https://dashboard.stripe.com/test/logs
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
find by time or req_xxx
Or I can quick check the Checkout Session Id cs_xxx if you paste
yep i can locate it,
$line_items = $stripe->checkout->sessions->allLineItems('cs_test_b1ThQoCls8Qebk8eAZBUjysOotAAaykR5V2bngutgNcG0h8FNleI4jThfu',
[],
["stripe_account" => $connected_account_id],
['expand' => ['data.price.product']]
);
cs_test_b1ThQoCls8Qebk8eAZBUjysOotAAaykR5V2bngutgNcG0h8FNleI4jThfu
req_AV0ZzW0VNP1o3G
holy shit, i think i got it ...
$line_items = $stripe->checkout->sessions->allLineItems(
'cs_test_b1ThQoCls8Qebk8eAZBUjysOotAAaykR5V2bngutgNcG0h8FNleI4jThfu',
['expand' => ['data.price.product']],
["stripe_account" => $connected_account_id]
);
it was a typo, stripe_account should be the last line .... Omg so much for this, weird that it was not flagging errors, so sorry for loosing your time π¦
Can i tip you somewhere
Give me your paypal acc, thank you so much for your time ... Let's get back in the code π Just in case you'll know it for the next one π