#xfechx-invoice-req
1 messages · Page 1 of 1 (latest)
hello
yes
$invoice = \Stripe\Invoice::retrieve($event->data->object->id, $connected_account);
foreach($invoice->lines->data as $index){
$subscription_id = $index->id;
echo ' --- [' . $index->id . '] => ' . $subscription_id;
??
@solar lily can you elaborate on the problem exactly? what part of what you see is different from what you expect?
I expect to get a il_, and I get a ii_**
I see, and why is that important?Why do you want an ID that looks like il_xxx exactly?
also I assume we are talking about something related to https://stripe.com/docs/upgrades#2019-12-03 . So knowing your API version would be helpful! (if you share the acct_xxx ID of that $connected_account I could find that out).
Because I retrieve subscriptions with it
some invoices work and some don't. For an example comparison, I have two different invoices One doesn't have invoice_item on it, the other one does. The one that works (i.e I don't get an error about trying to retrieve a subscription) is the one that doesn't have that property.
can you expand on that?
you get $index->id and then try to call \Stripe\Subscrption::retrieve with it?
$invoice = \Stripe\Invoice::retrieve($event->data->object->id, $connected_account);
foreach($invoice->lines->data as $index){
$subscription_id = $index->id;
echo ' --- [' . $index->id . '] => ' . $subscription_id;
then $StripeSub = \Stripe\Subscription::retrieve($subscription_id, $connected_account);
that doesn't work on current API versions (since https://stripe.com/docs/upgrades#2019-12-03 )
you call it $subscription_id but that's not what it is. It is the ID of the invoice line item.
the safe way to do this is :
- check if
$index->type == "subscription" - if so,
$subscription_id = $index->subscription
https://stripe.com/docs/api/invoices/line_item?lang=php#invoice_line_item_object-type
https://stripe.com/docs/api/invoices/line_item?lang=php#invoice_line_item_object-subscription
yes, thanks. Then the case with the line_item - how can I obtain the il**
if quoting for the id retrieves the ii
I don't understand the question, I'm sorry.
if you get ii_xxx that is the ID of the item you're looking at. It doesn't have an il_xxx ID
in any case, thinking about the IDs is not the right way to think about this.
you should look at the ->type field of the item(I linked the reference above) and that's how you decide what you might do. If it's type:subscription then the invoice line item is the one for the recurring element of a subscription and you can get the related Subscription object as mentioned above. If it's not, then it's something else(like a line item for a proration item, or it's a one-off invoice with no connection to a subscription).
My specific question is why quoting for the id (with same code gives me id on other cases) in this case, gets me invoice_item: "ii_***"
*invoice_item
or looked otherwise, how to get the line_item id in case it is of that type
(the invoice)
then it's something else(like a line item for a proration item, or it's a one-off invoice with no connection to a subscription
are you on an old API version?
if so, try looking at $index->unique_id for the il_xxx ID?
but what are you going to do with the ID out of curiosity? Like why do you want it?