#Gamx

1 messages Β· Page 1 of 1 (latest)

sonic forgeBOT
swift folio
#

Hi let's break down your question a little bit

#
  1. I believe it should be possible by just 1 call Retrieve Checkout Session API, expanding all the fields you need
#
  1. That request seems to retrieve a Checkout Session, but passing in a Payout object id (po_xxx) so it's expected to error
signal kayak
#

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"

swift folio
signal kayak
#

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

swift folio
#

What does it give you with that var_dump?

signal kayak
#

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']]*****

swift folio
#

Hmm so you have multiple line items but it will always returns the first one?

#

no matter of pagination?

signal kayak
#

Nope, it returns everything, i just showed you the first line, same for each line

swift folio
#

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)

signal kayak
#

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 πŸ˜„

swift folio
#

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

signal kayak
#

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']

                        ]
                    ]
                ]
            ];
swift folio
#

Okie. and you notice this different between a Checkout Session in your own account, vs. a Checkout Session in a Connected Account?

signal kayak
#

yes

swift folio
#

Like in your own account you were able to expand?

signal kayak
#

in my platform account i get everything directly using ->allLineItems , not even had to use expand at all

swift folio
#

Okie this sounds like a legitimate bug. Gimme sometimes to reproduce

signal kayak
#

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

swift folio
#

I expanded 'data.price.product' and yes I do see the result

signal kayak
#

can you show me your code please ?

swift folio
#

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
signal kayak
#

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 πŸ˜„

swift folio
#

find by time or req_xxx

#

Or I can quick check the Checkout Session Id cs_xxx if you paste

signal kayak
#

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

swift folio
#

lol I am just glad enough to see you figured it out

#

np and good luck!

signal kayak
#

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 πŸ˜„