A Laravel 5 wrapper for Xero's PHP API forked from drawmyattention/xerolaravel
adman9000/laravel-xero is a Laravel package for a laravel 5 wrapper for xero's php api forked from drawmyattention/xerolaravel.
It currently has 0 GitHub stars and 7 downloads on Packagist (latest version v2.2).
Install it with composer require adman9000/laravel-xero.
Discover more Laravel packages by adman9000
or browse all Laravel packages to compare alternatives.
Last updated
DEPRECATED — This package no longer works.
Xero permanently retired OAuth 1.0a on 30 September 2021. This package relies exclusively on OAuth 1.0a (RSA certificate / Private application authentication), so it cannot authenticate with the Xero API at all. No API calls will succeed.
Recommended replacement:
webfox/laravel-xero-oauth2— a Laravel wrapper for Xero's official OAuth 2.0 SDK (xeroapi/xero-php-oauth2), actively maintained by both Xero and the community.
A Laravel 5 wrapper for calcinai/xero-php (a custom API for integrating with Xero).
Require the package
composer require adman9000/laravel-xero
Add the Service Provider to your config/app.php under providers
'adman9000\LaravelXero\Providers\XeroServiceProvider',
**Register the Facades within config/app.php under aliases
'XeroPrivate'=> 'adman9000\LaravelXero\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)
This Service Provider current wraps the calcinai/xero-php version 1.1.* package.
Additionally, you must have PHP installed with the following extensions:
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.
Facade
$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();
Facade
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);
IoC Container
$xero = $this->app->make('XeroPrivate');
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);
Facade
$invoice = XeroPrivate::loadByGUID('Accounting\\Invoice', 'inv-0004);
$invoice->setStatus('Paid');
XeroPrivate::save($invoice);
IoC Container
$xero = $this->app->make('XeroPrivate');
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'inv-0004);
$invoice->setStatus('Paid');
$xero->save($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->setAccountNumber('DMA01');
$contact->setContactStatus('ACTIVE');
$contact->setName('Amo Chohan');
$contact->setFirstName('Amo');
$contact->setLastName('Chohan');
$contact->setEmailAddress('[email protected]');
$contact->setDefaultCurrency('GBP');
// Assign the contact to the invoice
$invoice->setContact($contact);
// Set the type of invoice being created (ACCREC / ACCPAY)
$invoice->setType('ACCREC');
$dateInstance = new DateTime();
$invoice->setDate($dateInstance);
$invoice->setDueDate($dateInstance);
$invoice->setInvoiceNumber('DMA-00001');
$invoice->setReference('DMA-00001');
// Provide an URL which can be linked to from Xero to view the full order
$invoice->setUrl('http://yourdomain/fullpathtotheorder');
$invoice->setCurrencyCode('GBP');
$invoice->setStatus('Draft');
// Create some order lines
$line1->setDescription('Blue tshirt');
$line1->setQuantity(1);
$line1->setUnitAmount(99.99);
$line1->setTaxAmount(0);
$line1->setLineAmount(99.99);
$line1->setDiscountRate(0); // Percentage
// Add the line to the order
$invoice->addLineItem($line1);
// Repeat for all lines...
$xero->save($invoice);
$xero = $this->app->make('XeroPrivate');
$attachment = $this->app->make('XeroAttachment')
->createFromLocalFile(storage_path('your_file.pdf'));
$invoice = $xero->loadByGUID('Accounting\\Invoice', 'AMO-00002');
$invoice->addAttachment($attachment);