PHP code example of dcblogdev / laravel-xero

1. Go to this page and download the library: Download dcblogdev/laravel-xero library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dcblogdev / laravel-xero example snippets


Route::group(['middleware' => ['web', 'XeroAuthenticated'], function()

use Dcblogdev\Xero\Models\XeroToken;

setTenantId($tenant_id)

protected function schedule(Schedule $schedule)
{
    $schedule->command('xero:keep-alive')->everyFiveMinutes();
}

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();
    });
});

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

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

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

Xero::get('contacts')

if (! Xero::isConnected()) {
    return redirect('xero/connect');
}

Xero::disconnect();

if (Xero::isConnected()) {
    Xero::disconnect();
}

Xero::contacts()

Xero::contacts()->get(int $page = 1, string $where = null)

Xero::contacts()->get(1, 'Name="ABC limited"')

Xero::contacts()->get(1, 'EmailAddress="[email protected]"')

Xero::contacts()->get(1, 'AccountNumber="ABC-100"')

Xero::contacts()->find(string $contactId)

Xero::contacts()->store($data)

Xero::contacts()->update($contactId, $data);

Xero::invoices()

Xero::invoices()->get(int $page = 1, string $where = null)

Xero::invoices()->get(1, 'Status="AUTHORISED"')

Xero::invoices()->get(1, 'Contact.ContactID=guid("96988e67-ecf9-466d-bfbf-0afa1725a649")')

Xero::invoices()->get(1, 'Contact.ContactNumber="ID001"')

Xero::invoices()->get(1, 'Reference="INV-0001"')

Xero::invoices()->get(1, 'Date=DateTime(2020, 01, 01)')

Xero::invoices()->get(1, 'Type="ACCREC"')

Xero::invoices()->find(string $invoiceId)

Xero::invoices()->onlineUrl($invoiceId)

Xero::invoices()->store($data)

Xero::invoices()->update($invoiceId, $data);

$pdfInvoice = Xero::get("invoices/{$invoiceId}", null, true, 'application/pdf');
$pdfInvoice['body']; // will be the pdf as a pdf string for you to write out to storage etc.

php artisan vendor:publish --provider="Dcblogdev\Xero\XeroServiceProvider" --tag="config"

php artisan vendor:publish --provider="Dcblogdev\Xero\XeroServiceProvider" --tag="migrations"

php artisan migrate

php artisan xero:keep-alive