%} %}

Laravel & Xero — A dream combo

Sprint Digital 26 Feb, 2020

Working with 3rd party APIs can always be a hassle but one particular platform we absolutely love working with. It’s developer friendly endpoints, clean interfaces and expressive syntax make working with this platform a dream. 

Xero has an established PHP Package by the great Calcinai so we thought we would use this post to document the way that we usually leverage Laravel to send invoices to Xero — which is a usual request in our day to day business. 

Set up the invoice 

The first step above is to initialise the invoice with all the data you (ideally) have saved from the Invoice create process. Next up you add all the line items associated with the invoice. 

Adding line items 

Finally, the next step is to save. But in some instances, you want to generate a PDF on the system’s end instead of using Xero’s own PDF send & save. This was a particular requirement for us as the invoice PDF that needed to generate required a bunch of information that wasn’t readily available in Xero to edit.

So we used Spatie’s amazing Browsershot to create a PDF of the invoice, and add that as an attachment to the invoice.  

Save the invoice, upload the PDF

Now that that’s done, your invoice is safely in Xero along with the PDF for reference so you can go ahead and delete the file the Browsershot created. 

And it’s as easy as that. The usual way we’ll send invoices to Xero with Laravel Jobs, see the gist here

Read more