Coder Social home page Coder Social logo

yii2-xero's Introduction

Xero API for Yii2

An extension for using the Xero API from within Yii2.

This extension is based on Xero's XeroOAuth-PHP code at https://github.com/XeroAPI/XeroOAuth-PHP

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist slightlydiff/yii2-xero "*"

or add

"slightlydiff/yii2-xero": "*"

to the require section of your composer.json file.

Configuration

Add the following to your application conmfiguration file:

        'xeroApi' => [
            'class' => 'slightlydiff\xero\XeroApi',
            'rsa_public_key' => '@app/config/certs/xero_publickey.cer',
            'rsa_private_key' => '@app/config/certs/xero_privatekey.pem',
            'consumer_key' => 'yourconsumerkey',
            'shared_secret' => 'yoursharedsecret',
            'useragent' => 'XeroOAuth-PHP'
        ],

modifying the above for your own Xero consumer key, shared secret and the path to you public / private key pair.

Usage

For a GET request:

  • The first parameter is the only required parameter and must be 'GET', 'POST', 'PUT' or 'DELETE'
  • The second parameter can be FALSE or a string ID if you want to get a single record by ID
  • The third parameter can be a date/time, in any format, if you want to fetch all records modified since that date
  • The fourth parameter can be an array of filters as described at https://developer.xero.com/documentation/getting-started/http-requests-and-responses/. This allows you to filter the query and order the returned data.

All parameters are optional except the first. If not parameters are passed then all records of the requested type will be returned

For a POST or PUT request:

  • The first parameter must be the method, as above, and the second param must be a multidimensional array of the data being passed as in the examples below.

To create a contact see https://developer.xero.com/documentation/api/contacts/ for the format and apply as follows:

$new_contact = array(
    array(
        "Name" => "Joe Bloggs",
        "FirstName" => "Joe",
        "LastName" => "Bloggs",
        "Addresses" => array(
            "Address" => array(
                array(
                    "AddressType" => "POSTAL",
                    "AddressLine1" => "123 Anystreet",
                    "City" => "Anytown",
                    "PostalCode" => "1234"
                ),
                array(
                    "AddressType" => "STREET",
                    "AddressLine1" => "123 Anystreet",
                    "City" => "Anytown",
                    "PostalCode" => "1234"
                )
            )
        )
    )
);
$result = $xero->Contacts('POST', $new_invoice);

To create a invoice or credit note see https://developer.xero.com/documentation/api/invoices/ for the format and apply as follows:

$new_invoice = array(
    array(
        "Type"=>"ACCREC",
        "Contact" => array(
            "ContactID" => "[contact id]"
        ),
        "Date" => "2016-08-01",
        "DueDate" => "2016-08-30",
        "Status" => "SUBMITTED",
        "LineAmountTypes" => "Exclusive",
        "LineItems"=> array(
            "LineItem" => array(
                array(
                    "Description" => "Some product description",
                    "Quantity" => "1.0000",
                    "UnitAmount" => "123.00",
                    "AccountCode" => "200"
                )
            )
        )
    )
);
$result = $xero->Invoices('POST', $new_invoice);

To create a payment see https://developer.xero.com/documentation/api/payments/ for the format and apply as follows:

$new_payment = array(
    array(
        "Invoice" => array(
            "InvoiceNumber" => "INV-1234"
        ),
        "Account" => array(
            "Code" => "[account code]"
        ),
        "Date" => "2016-08-30",
        "Amount"=>"123.00",
    )
);
$result = $xero->Payments('POST', $new_payment);

To get details of an account with the name "Joe Bloggs"

$result = $xero->Accounts('GET', false, false, array("Name"=>"Joe Bloggs") );

See https://developer.xero.com/documentation/api/accounts/ for a list of all parameters.

To get details of all contacts

$result = $xero->Contacts;

To get details of all contacts modified in the last 24 hours

$result = $xero->Contacts('GET', false, gmdate("M d Y H:i:s", (time() - (1 * 24 * 60 * 60))), false);

To get details of a contact by ID

$result = $xero->Contacts('GET', 'contact id here', false, false);

To get details of all contacts whos name contains "Bloggs" and order the results by Name

$result = $xero->Contacts('GET', false, false, ['where' => 'Name.Contains("Bloggs")', 'order' => 'Name DESC']);

yii2-xero's People

Contributors

drewbroadley avatar elliotchance avatar fenixter avatar iansimpson avatar lloydhazlett avatar matthealy avatar mradcliffe avatar ronanq avatar slightlydiff avatar tarasdryanih avatar tomcastleman avatar torohill avatar

Watchers

 avatar  avatar

Forkers

tarasdryanih

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.