#ulrikeskygate
1 messages ยท Page 1 of 1 (latest)
hi! I don't that's expected no. What version of stripe-php are you using? What does your exact code look like?
Hang on...
stripe/stripe-php is v10.21.0
For code I need a moment
$invoice = $this->client->invoices->retrieve('in_1OcUpdCptbWmAJMvCCNvMJQZ', ['expand' => ['lines.data.price.product']]);
foreach ($invoice->lines->autoPagingIterator() as $item) {
echo "<pre>";
print_r($item->price);
echo "</pre>";
}
die();
The first ten entries have the product expanded, the other four on "page two" do not.
I see now, that the lib is quite outdated. No Idea why it installed an old version to be honest...
yeah I think the way I would write that code instead is
$lines = $stripe->invoices->allLines($invoiceId, ["expand"=>["data.price.product"]]);
foreach ($lines->autoPagingIterator() as $line) {
...
}
That does the trick ๐
As the original behaviour would still not be ideal, I'll quickly try and update to a newer version of the lib and check if it's working correctly there and let you know. Stand by...
I don't think it would change anything
it's because for the first 10 items the iterator uses the lines embedded in the local Invoice object and then after that, it makes API calls, but it doesn't inherit the expand parameters(that would be tricky to do)
it's a quirk but I don't see it changing, we're actively trying to move away from embedded lists like lines inside Invocie in favour of direct separate endpoints for various reasons
Ah ok. I encountered that behavior at another place in the code, but I don't remember where exactly of the top of my head. I had to check for string key or object and call the api accordingly. So I understand, autoPaginator + expand is generally a bad idea going forward? Could you maybe update the docs to reflect that? I think a few others will probably run into that same issue ๐ I'll update to the code you provided with allLines and check the other instances as well.
well to be clear it's a good idea and it generally works fine
it's only here where the thing you're iterating is the embedded list on an object (lines on an Invoice is a full List object with the parameters for data and has_more and stuff) and that introduces complexities
Oh yeah, it's a great feature in general. No doubt about that and I use it a lot for non-iteration things ๐ I meant only in comibination with the expanded properties.
The allLines Feature is also really cool ๐ Somtimes I'm a bit lost the many different ways of retreiving thing and the intricacies of what data is where (like the invoiceItems endpoint giving me the item id (ii_...) but not the line item id (li_...)). So I might have to annoy you guys with questions here and there.
In any case, thank you for the info and the help ๐
no worries, it's all pretty complex
Yeah, I'm glad our shop is simple enough. The complex questions I read on here sometimes and the features Stripe provides are astonishing. You guys do a bang up job and you have fantastic customer service! Thank you again and I really appreciate it!