#xfechx-invoice-req

1 messages · Page 1 of 1 (latest)

limpid oak
#

Hey! Can you share your API call/code?

solar lily
#

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
#

??

viral meadow
#

@solar lily can you elaborate on the problem exactly? what part of what you see is different from what you expect?

solar lily
#

I expect to get a il_, and I get a ii_**

viral meadow
#

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).

solar lily
#

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.

viral meadow
#

you get $index->id and then try to call \Stripe\Subscrption::retrieve with it?

solar lily
#

$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);

viral meadow
#

you call it $subscription_id but that's not what it is. It is the ID of the invoice line item.

solar lily
#

yes, thanks. Then the case with the line_item - how can I obtain the il**

#

if quoting for the id retrieves the ii

viral meadow
#

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).

solar lily
#

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)

viral meadow
solar lily
#

ok, yes - but how to obtain the line_item ?

#

id

viral meadow
#

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?