Laravel Xero

Introduction

A Laravel package for working with Xero.

https://github.com/dcblogdev/laravel-xero

Box API documentation can be found at: https://developer.xero.com/documentation/

Usage

A routes example:

Route::group(['middleware' => ['web', 'auth']], function(){
    Route::get('xero', function(){

        if (! Xero::isConnected()) {
            return redirect('xero/connect');
        } else {
            //display your tenant name
            return Xero::getTenantName();
        }

    });

    Route::get('xero/connect', function(){
        return Xero::connect();
    });
});

Or using a middleware route, if the user does not have a token then automatically redirect to get authenticated:

Route::group(['middleware' => ['web', 'XeroAuthenticated']], function(){
    Route::get('xero', function(){
        return Xero::getTenantName();
    });
});

Route::get('xero/connect', function(){
    return Xero::connect();
});

Once authenticated you can call Xero:: with the following verbs:

Xero::get($endpoint, $array = [])
Xero::post($endpoint, $array = [])
Xero::put($endpoint, $array = [])
Xero::patch($endpoint, $array = [])
Xero::delete($endpoint, $array = [])

The second param of array is not always required, its requirement is determined from the endpoint being called, see the API documentation for more details.

These expect the API endpoints to be passed, the URL https://api.xero.com/api.xro/2.0/ is provided, only endpoints after this should be used ie:

Xero::get('contacts');

Copyright © 2006 - 2024 DC Blog - All rights reserved.