<?php
// src/Service/UserService.php
namespace App\Service\Xero;
use App\Service\ApiService;
use GuzzleHttp\Client;
use App\Authenticator\XeroAuthenticator;
use XeroAPI\XeroPHP\Configuration;
use XeroAPI\XeroPHP\Api\AccountingApi;
abstract class XeroService extends ApiService
{
protected $storage;
protected $xeroTenantId;
protected $xeroAccountingManager;
public function __construct(XeroAuthenticator $xeroAuthenticator)
{
$this->provider = $xeroAuthenticator->getProvider();
$this->storage = $xeroAuthenticator->getStorage();
if ($this->storage) {
$this->xeroAccountingManager = $this->getAccountingApi($this->storage);
$this->xeroTenantId = (string)$this->storage->getTenantId();
}
}
private function getAccountingApi($currentStorage)
{
$config = Configuration::getDefaultConfiguration()->setAccessToken((string)$currentStorage->getAccessToken());
$xeroAccountingManager = new AccountingApi(
new Client(),
$config
);
return $xeroAccountingManager;
}
}