Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInvoice returns an Invoices model instead of Invoice #92

Closed
Drewyn opened this issue Apr 2, 2020 · 2 comments
Closed

getInvoice returns an Invoices model instead of Invoice #92

Drewyn opened this issue Apr 2, 2020 · 2 comments

Comments

@Drewyn
Copy link

Drewyn commented Apr 2, 2020

It'd be nice if there weren't extra steps to get to the specified invoice when calling getInvoice.

AFAIK this function should never return multiple invoices (that would be what getInvoices is for), but to get to the requested Invoice your code has to look a bit cluttered:

$invoicesResponse = $apiInstance->getInvoice(
	$record['tenant_id'],
	$guid
);

if (!empty($invoicesResponse)) {
	$invoices = $invoicesResponse->getInvoices();

	if (count($invoices) > 0) {
		return $invoices[0];
	}
}

Whereas it could be:

$invoice = $apiInstance->getInvoice(
	$record['tenant_id'],
	$guid
);

if (!empty($invoice)) {
	return $invoice;
}
@SidneyAllen
Copy link
Contributor

Hi @Drewyn,

Thank you for feedback. I hear what you're saying about looking for ways to simplify the code needed to utilize the SDK. We generate our SDKs from our OpenAPI specs, so this enhancement would need to happen in the templates we use to generate the SDKs.

To clarify, calling for a single object using a guid returns an array of invoices.

{
   "Invoices":[
      {
         "Type":"ACCREC",
         "InvoiceID":"a03ffcd2-5d91-4c7e-b483-318584e9e439",
         "InvoiceNumber":"INV-0006",
         "Reference":"Tour"
        --- MANY more properties :-) --
      }
   ]
}

We could explore adding method(s) to encapsulate some of the code you are writing.

At this point, these enhancements are a lower priority over adding support for additional API endpoints. But I will leave this issue open to remind us about this improvement request.

But if you provide example of method(s) you'd like incorporated that could move this along.

@SidneyAllen
Copy link
Contributor

@Drewyn - we have release version 1.6.2 of xero-php-oauth2 SDK

We've done this enhancement
#63

Now you can use this code to get the single invoice object returned.

if($result->count())
{
return $result[0];
}

Not exactly what you had requested, but an improvement I thought you'd be interested in.

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants