PHP code example of cakephp-biztech / cakephp-xero-oauth2

1. Go to this page and download the library: Download cakephp-biztech/cakephp-xero-oauth2 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/ */

    

cakephp-biztech / cakephp-xero-oauth2 example snippets


    Plugin::load('XeroOauth2', ['routes' => true]);
    

    

    return [
        'XeroOauth2' => [
            'clientId' => 'your-client-id',
            'clientSecret' => 'your-client-secret',
            'baseUri' => 'https://example.com',
            'scope' => [
                'openid',
                'email',
                'profile',
                'offline_access',
                'accounting.settings',
                'accounting.contacts',
                // Any other scopes needed for your application goes here
            ],
            'successUrl' => 'http://example.com/success'
        ]
    ];
    

    Configure::load('xero_config', 'default');
    

$this->loadComponent('XeroOauth2.XeroOauth');
$accountingApi = $this->XeroOauth->accountingApi();

$this->loadComponent('XeroOauth2.Storage');
$tenantId = $this->Storage->getXeroTenantId();


namespace App\Controller;

class ContactsController extends AppController
{
    public function index()
    {
        $this->loadComponent('XeroOauth2.Storage');
        $this->loadComponent('XeroOauth2.XeroOauth');

        $tenantId = $this->Storage->getXeroTenantId();
        $accountingApi = $this->XeroOauth->accountingApi();

        foreach ($accountingApi->getContacts($tenantId)->getContacts() as $contact) {
            debug([
                'id' => $contact->getContactId(),
                'name' => $contact->getName(),
                'email' => $contact->getEmailAddress(),
            ]);
        }
    }
}