Extension linking Yii up to the Xero Accounting System

Extension for the Yii Framework to link apps up to the Xero accounting system.

There is a model class (extending XeModel) for each entity in the Xero System, e.g. Contact, Invoice etc.

Currently only Invoices & Contacts are fully coded, and the extension only supports 'private' app types.


Yii 1.1.13 or above


To use, add the component to your config file as follows:

'xero' => array(
  'class' => 'ext.yii-xero.components.Xero',
  'appType' => 'private',
   'oAuthCallback' => 'http://localhost/xero/xero/auth', //oauth callback field - not needed for private apps
    'signatures' =>  array(
    // local
    'consumer_key' => (consumer key),
    'shared_secret' => (shared secret),
    'rsa_private_key' => (private key),
    'rsa_public_key'    => (public key),

Here is an example of how to create a contact using the component:


$contact = new XeContact();
//add org details first
$contact->contactNumber = $this->id;
$contact->name = $this->org_name;
$contact->taxNumber = $this->vat_number;
//add address
$address = new XeAddress();
$address->addressType = XeAddress::AT_POBOX; //billing address
$address->addressLine1 = $user->address1;
$address->addressLine1 = $user->address1;
$address->addressLine2 = $user->address2;
$address->city = $user->town;
$address->region = $user->county;
$address->postalCode = $user->postcode;
//add phone if present, splitting into area code and number
$phone = new XePhone();
$phoneList = explode(' ', $user->phone_number, 2);
  $phone->phoneCountryCode = '+44';
  $phone->phoneAreaCode = $phoneList[0];
  $phone->phoneNumber = $phoneList[1];
    $phone->phoneCountryCode = '+43';
    $phone->phoneNumber = $phoneList[0];
//add user details
$contact->firstName = $user->first_name;
$contact->lastName = $user->last_name;
$contact->emailAddress = $user->email;


This project is hosted on Github, you can clone it and fork it here:

Total 2 comments

#17663 report it
IainG at 2014/07/12 07:59pm
Example code

Hi James,

I have added example code from a project I created using the extension to the github repo. You can see the code here: https://github.com/iaingray/yii-xero/tree/master/example-code

Hopefully that should help - I have had it working with both sales & purchase invoices using the linked code.


#17646 report it
JamesBranton at 2014/07/10 08:02am

Hi there,

Firstly - thanks for a great extension!

I have the functionality working for the adding of a contact to Xero, but i'm struggling to add a new purchase invoice/bill. It would be massively appreciated if you could post some example code as per the 'contact' example code - would that be possible?

Regardless of whether I set the type to TYPE_PAYABLE or TYPE_RECEIVABLE, it always displays in Xero as a payable invoice.

Thanks, James

Leave a comment

Please to leave your comment.

Create extension