1. Go to this page and download the library: Download grim-reapper/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/ */
grim-reapper / xero example snippets
// To use this package you have to extend it, create your own PHP class and extend this.
class YourClassName extends \GrimReapper\Xero\Xero{
// then override it constructor
public function __construct(array $params)
{
if(!empty($params)) {
parent::__construct($params['client_id'], $params['client_secret'], $params['redirect_uri']);
}
}
// that's it
}
$object = new YourClassName();
$data = $object->getAuthorizeURL();
// it will return array containing URL and State Code
$state = $data['state']; // this is used to verify state after api redirect to prevent xss
$url = $data['url']; // use this url to redirect to Xero website for Authentication
$object->setScopes(['scope1','scope2']);
$code = $_GET['code']; // get code param from url and pass it to function
$accessToken = $object->getAccessToken($code);