Skip to content
A Laravel 5 wrapper for Xero's PHP API
Branch: master
Clone or download
amochohan Merge pull request #21 from ziming/patch-1
Auto Register Service Provider
Latest commit 4753077 Nov 9, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
Certificates Initial commit Jun 16, 2015
Facades Create XeroItem.php Apr 4, 2018
.gitignore Initial commit Jun 16, 2015 Add a download counter Dec 9, 2016
composer.json Auto register Service Provider May 20, 2018
config.php Initial commit Jun 16, 2015


Xero Accounting API Laravel 5 Wrapper

A Laravel 5 wrapper for calcinai/xero-php (a custom API for integrating with Xero).

Installation via Composer

Require the package

composer require drawmyattention/xerolaravel "1.0.*"

Add the Service Provider to your config/app.php under providers


**Register the Facades within config/app.php under aliases

'XeroPrivate'=> 'DrawMyAttention\XeroLaravel\Facades\XeroPrivate',

Publish the configuration file

php artisan vendor:publish

This will create a xero/config.php within your config directory. (Note: Ensure that you have generated the necessary tokens and have generated the RSA keys required by Xero for authentication.) Edit the relevant values in the config.php file.

Ensure that the location of the RSA keys matches the required format (file://absolutepath)

Dependencies and Requirements

This Service Provider current wraps the calcinai/xero-php version 1.1.* package.

Additionally, you must have PHP installed with the following extensions:

  • php_curl (7.30+)
  • php_openssl


There are two ways to use the classes: via the IoC container, or via a Facade. They both offer the same functionality, so use each depending on your preference.

Get all invoices


$invoices = XeroPrivate::load('Accounting\\Invoice')->execute();

IoC Container

// Create an instance of the class, resolved out of the IoC container
$xero = $this->app->make('XeroPrivate');
$invoices = $xero->load('Accounting\\Invoice')->execute();

Get a single invoice via GUID or invoice number


$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);

IoC Container

$xero = $this->app->make('XeroPrivate');

$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);

Update an existing invoice


$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);



IoC Container

$xero = $this->app->make('XeroPrivate');

$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);



Creating a new invoice

 * Resolve instances of Xero, XeroInvoice, XeroContact 
 * and XeroInvoiceLine out of the IoC container.
$xero = $this->app->make('XeroPrivate');
$invoice = $this->app->make('XeroInvoice');
$contact = $this->app->make('XeroContact');
$line1 = $this->app->make('XeroInvoiceLine');
$line2 = $this->app->make('XeroInvoiceLine');

// Set up the invoice contact
$contact->setName('Amo Chohan');

// Assign the contact to the invoice

// Set the type of invoice being created (ACCREC / ACCPAY)

$dateInstance = new DateTime();

// Provide an URL which can be linked to from Xero to view the full order


// Create some order lines
$line1->setDescription('Blue tshirt');

$line1->setDiscountRate(0); // Percentage

// Add the line to the order

// Repeat for all lines...


Creating Attachments

$xero = $this->app->make('XeroPrivate');

$attachment = $this->app->make('XeroAttachment')
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'AMO-00002');
You can’t perform that action at this time.