invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 41 forks source link

Getting ID of product from recurring invoice #36

Closed Taronyuu closed 6 years ago

Taronyuu commented 6 years ago

Is there a way to get the ID of a product used in a recurring invoice after it has been created? Because as far as I know, no ID is returned when retrieving the recurring invoice.

Example:

Get all the plans:

$products = Product::all();

Get a recurring subscription that uses a plan:

// Lets assume this invoice is a recurring one
$recurringInvoice = Invoice::find(1);

I can loop through all the invoice items and there is no way to relate them.

foreach($recurringInvoice->invoice_items as $invoiceItem){
    $invoiceItem->id; // Doesn't exist
}

However, the $products do have the IDs included:

foreach($products as $product){ 
    $product->id; // Works
}

At this point I'm using the product key to match them, but obviously this will fail if the product ever gets renamed. Am I missing something or is this indeed not possible?

hillelcoren commented 6 years ago

Subscriptions aren't recurring invoices, they're web hooks.

Taronyuu commented 6 years ago

I don't know why... but at the time of developing this there was a situation when the invoice item did not include the product id. However I just tested it and it works as expected. Is there any situation where this might occur?

My apologies for making this useless issue, thank you! :)

hillelcoren commented 6 years ago

Not that I'm aware of.

Taronyuu commented 6 years ago

I found the issue that was actually occurring, I'm hoping this makes a bit more sense.

This is a screenshot of the data from the invoice item that is taken from a recurring invoice:

screenshot 2018-10-01 at 20 41 00

This is a screenshot of the actual product used when creating the recurring invoice:

screenshot 2018-10-01 at 20 42 32

As you can see the IDs are different, I assume this is because you should be able to modify the product used in a recurring invoice without editing the original product. However, at this point there is no way to tell what was the original product from the API. Is it even possible to get the original product used here without keeping track of that by my own application?

hillelcoren commented 6 years ago

We use the product_key field to match products

Taronyuu commented 6 years ago

That is indeed what I'm doing at this point, I was just hoping that there was a better way. I'm afraid not.

Thank you for your quick responses and my apologies for screwing it up at the start! :)