Exception
GuzzleHttp\Exception\ClientException: Client error: `POST https://start.exactonline.nl/api/oauth2/token` resulted in a `400 Bad Request` response:
{"error":"invalid_request"}
in /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\Exception\RequestException::create()
#1 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}()
#2 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler()
#3 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run()
#5 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn()
#6 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending()
#7 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList()
#8 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/promises/src/Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending()
#9 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/guzzle/src/Client.php(187): GuzzleHttp\Promise\Promise->wait()
#10 /home/forge/staging.app.com/releases/561/vendor/guzzlehttp/guzzle/src/ClientTrait.php(95): GuzzleHttp\Client->request()
#11 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(522): GuzzleHttp\Client->post()
#12 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(228): Picqer\Financials\Exact\Connection->acquireAccessToken()
#13 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(261): Picqer\Financials\Exact\Connection->createRequest()
#14 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Me.php(86): Picqer\Financials\Exact\Connection->get()
#15 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(463): Picqer\Financials\Exact\Me->find()
#16 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(597): Picqer\Financials\Exact\Connection->getCurrentDivisionNumber()
#17 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(258): Picqer\Financials\Exact\Connection->formatUrl()
#18 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Query/Findable.php(109): Picqer\Financials\Exact\Connection->get()
#19 /home/forge/staging.app.com/releases/561/app/Jobs/Exact/SyncOrderJob.php(45): Picqer\Financials\Exact\Account->filter()
#20 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Jobs\Exact\SyncOrderJob->handle()
#21 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#22 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#23 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#24 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\Container\BoundMethod::call()
#25 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#26 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#27 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#28 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#29 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\Bus\Dispatcher->dispatchNow()
#30 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#31 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#32 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#33 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#34 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#35 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(414): Illuminate\Queue\Jobs\Job->fire()
#36 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(364): Illuminate\Queue\Worker->process()
#37 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): Illuminate\Queue\Worker->runJob()
#38 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\Queue\Worker->daemon()
#39 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker()
#40 /home/forge/staging.app.com/releases/561/vendor/laravel/horizon/src/Console/WorkCommand.php(51): Illuminate\Queue\Console\WorkCommand->handle()
#41 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Laravel\Horizon\Console\WorkCommand->handle()
#42 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#43 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#44 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#45 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\Container\BoundMethod::call()
#46 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#47 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Command/Command.php(288): Illuminate\Console\Command->execute()
#48 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#49 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(974): Illuminate\Console\Command->run()
#50 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(291): Symfony\Component\Console\Application->doRunCommand()
#51 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun()
#52 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\Component\Console\Application->run()
#53 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#54 /home/forge/staging.app.com/releases/561/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#55 {main}
Next Picqer\Financials\Exact\ApiException: Could not acquire or refresh tokens [http 400] in /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php:539
Stack trace:
#0 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(228): Picqer\Financials\Exact\Connection->acquireAccessToken()
#1 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(261): Picqer\Financials\Exact\Connection->createRequest()
#2 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Me.php(86): Picqer\Financials\Exact\Connection->get()
#3 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(463): Picqer\Financials\Exact\Me->find()
#4 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(597): Picqer\Financials\Exact\Connection->getCurrentDivisionNumber()
#5 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php(258): Picqer\Financials\Exact\Connection->formatUrl()
#6 /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Query/Findable.php(109): Picqer\Financials\Exact\Connection->get()
#7 /home/forge/staging.app.com/releases/561/app/Jobs/Exact/SyncOrderJob.php(45): Picqer\Financials\Exact\Account->filter()
#8 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): App\Jobs\Exact\SyncOrderJob->handle()
#9 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#10 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#11 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#12 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\Container\BoundMethod::call()
#13 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(128): Illuminate\Container\Container->call()
#14 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Bus\Dispatcher->Illuminate\Bus\{closure}()
#15 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Bus/Dispatcher.php(132): Illuminate\Pipeline\Pipeline->then()
#17 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(120): Illuminate\Bus\Dispatcher->dispatchNow()
#18 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Queue\CallQueuedHandler->Illuminate\Queue\{closure}()
#19 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(122): Illuminate\Pipeline\Pipeline->then()
#21 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedHandler.php(70): Illuminate\Queue\CallQueuedHandler->dispatchThroughMiddleware()
#22 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Jobs/Job.php(98): Illuminate\Queue\CallQueuedHandler->call()
#23 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(414): Illuminate\Queue\Jobs\Job->fire()
#24 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(364): Illuminate\Queue\Worker->process()
#25 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(158): Illuminate\Queue\Worker->runJob()
#26 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(117): Illuminate\Queue\Worker->daemon()
#27 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(101): Illuminate\Queue\Console\WorkCommand->runWorker()
#28 /home/forge/staging.app.com/releases/561/vendor/laravel/horizon/src/Console/WorkCommand.php(51): Illuminate\Queue\Console\WorkCommand->handle()
#29 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Laravel\Horizon\Console\WorkCommand->handle()
#30 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#31 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\Container\Util::unwrapIfClosure()
#32 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\Container\BoundMethod::callBoundMethod()
#33 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Container/Container.php(614): Illuminate\Container\BoundMethod::call()
#34 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\Container\Container->call()
#35 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Command/Command.php(288): Illuminate\Console\Command->execute()
#36 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\Component\Console\Command\Command->run()
#37 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(974): Illuminate\Console\Command->run()
#38 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(291): Symfony\Component\Console\Application->doRunCommand()
#39 /home/forge/staging.app.com/releases/561/vendor/symfony/console/Application.php(167): Symfony\Component\Console\Application->doRun()
#40 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Console/Application.php(92): Symfony\Component\Console\Application->run()
#41 /home/forge/staging.app.com/releases/561/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\Console\Application->run()
#42 /home/forge/staging.app.com/releases/561/artisan(37): Illuminate\Foundation\Console\Kernel->handle()
#43 {main}
Next Picqer\Financials\Exact\ApiException: Could not acquire or refresh tokens [http 400] in /home/forge/staging.app.com/releases/561/vendor/picqer/exact-php-client/src/Picqer/Financials/Exact/Connection.php:666
Last active
June 20, 2021 03:45
-
-
Save jasperf/d25d3fa798ed1afe3e09cf8c4834ef0e to your computer and use it in GitHub Desktop.
Exact Picquer PHP API Package Error on running Laravel Job: Could not acquire or refresh tokens [http 400]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Jobs\Exact; | |
use App\Order; | |
use Illuminate\Bus\Queueable; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
use Illuminate\Foundation\Bus\Dispatchable; | |
use Illuminate\Queue\InteractsWithQueue; | |
use Illuminate\Queue\SerializesModels; | |
class SyncOrderJob implements ShouldQueue | |
{ | |
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | |
private $order; | |
/** | |
* Create a new job instance. | |
* | |
* @return void | |
*/ | |
public function __construct(Order $order = null) | |
{ | |
$this->order = $order; | |
} | |
/** | |
* Execute the job. | |
* | |
* @return void | |
*/ | |
public function handle() | |
{ | |
$connection = null; | |
try { | |
$connection = app()->make('Exact\Connection'); | |
} catch (\Exception $e) { | |
} | |
if ($this->order && $connection) { | |
// Sync account | |
$account = new \Picqer\Financials\Exact\Account($connection); | |
$account->ID = data_get($account->filter("Email eq '{$this->order->email_address}'"), '0.ID', null); | |
$account->City = $this->order->city; | |
$account->Country = $this->order->country; | |
$account->IsSales = 'true'; | |
$account->Name = $this->order->initials.' '.$this->order->last_name; | |
$account->Postcode = $this->order->zipcode; | |
$account->Email = $this->order->email_address; | |
$account->VATNumber = $this->order->vat_number; | |
$account->Status = 'C'; | |
$account->save(); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Services\ExactOnline; | |
use Illuminate\Support\ServiceProvider; | |
/** | |
* Exact Online Service Provider. Using the Exact Online Service or helper this provider loads all that is needed to interact | |
* with Exact Online accounting services. | |
*/ | |
class ExactOnlineServiceProvider extends ServiceProvider | |
{ | |
/** | |
* Register services. | |
* | |
* @return void | |
*/ | |
public function register() | |
{ | |
// $this->publishes([ | |
// __DIR__ . '/../views' => base_path('resources/views/vendor/laravelexactonline'), | |
// __DIR__ . '/../exact.api.json' => storage_path('exact.api.json'), | |
// __DIR__ . '/../config/laravel-exact-online.php' => config_path('laravel-exact-online.php') | |
// ]); | |
} | |
/** | |
* Bootstrap services. | |
* | |
* This method is called after all other service providers have been registered, meaning you have access | |
* to all other services that have been registered by the framework. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->app->alias(ExactOnline::class, 'laravel-exact-online'); | |
$this->app->singleton('Exact\Connection', function () { | |
$config = ExactOnline::loadConfig(); | |
$connection = new \Picqer\Financials\Exact\Connection(); | |
$connection->setRedirectUrl(route('admin.exact.callback')); | |
$connection->setExactClientId(config('services.exact.client_id')); | |
$connection->setExactClientSecret(config('services.exact.secret')); | |
$connection->setBaseUrl('https://start.exactonline.nl'); | |
if (isset($config->exact_authorisationCode)) { | |
$connection->setAuthorizationCode($config->exact_authorisationCode); | |
} | |
if (isset($config->exact_accessToken)) { | |
$connection->setAccessToken(unserialize($config->exact_accessToken)); | |
} | |
if (isset($config->exact_refreshToken)) { | |
$connection->setRefreshToken($config->exact_refreshToken); | |
} | |
if (isset($config->exact_tokenExpires)) { | |
$connection->setTokenExpires($config->exact_tokenExpires); | |
} | |
$connection->setTokenUpdateCallback('\PendoNL\LaravelExactOnline\LaravelExactOnline::tokenUpdateCallback'); | |
try { | |
if (isset($config->exact_authorisationCode)) { | |
$connection->connect(); | |
} | |
} catch (\GuzzleHttp\Exception\RequestException $e) { | |
$connection->setAccessToken(null); | |
$connection->setRefreshToken(null); | |
$connection->connect(); | |
} catch (\Exception $e) { | |
throw new \Exception('Could not connect to Exact: '.$e->getMessage()); | |
} | |
$config->exact_accessToken = serialize($connection->getAccessToken()); | |
$config->exact_refreshToken = $connection->getRefreshToken(); | |
$config->exact_tokenExpires = $connection->getTokenExpires(); | |
ExactOnline::storeConfig($config); | |
return $connection; | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://github.com/picqer/exact-php-client/issues/300#issuecomment-690268580 | |
namespace App\Exact; | |
use App\Models\Exact; | |
use App\Models\Match; | |
use App\Models\Package; | |
use App\Models\ProfBudget; | |
use App\Models\Professional; | |
use App\Models\Transaction; | |
use Carbon\Carbon; | |
use GuzzleHttp\Client; | |
use Illuminate\Support\Collection; | |
use Illuminate\Support\Facades\DB; | |
use Illuminate\Support\Facades\Log; | |
use Illuminate\Support\Facades\Storage; | |
use Illuminate\Support\Facades\Validator; | |
use Picqer\Financials\Exact\Account; | |
use Picqer\Financials\Exact\Bank; | |
use Picqer\Financials\Exact\Connection; | |
use Picqer\Financials\Exact\DocumentAttachment; | |
use Picqer\Financials\Exact\Item; | |
use Picqer\Financials\Exact\PrintedSalesInvoice; | |
use Picqer\Financials\Exact\SalesInvoice; | |
use Picqer\Financials\Exact\SalesInvoiceLine; | |
class ExactOnline | |
{ | |
protected $client; | |
protected $exact; | |
protected $connection; | |
protected $exact_client; | |
public function __construct($setup = true) | |
{ | |
$this->client = new Client(); | |
$this->exact = Exact::latest('id')->first(); | |
if($setup) | |
{ | |
$this->setup(); | |
} | |
} | |
public function setup() | |
{ | |
$this->connection = new Connection(); | |
$this->connection->setRedirectUrl(config('exact.callback')); | |
$this->connection->setExactClientId(config('exact.client.id')); | |
$this->connection->setExactClientSecret(config('exact.client.secret')); | |
if($this->getCode()) | |
{ | |
$this->connection->setAuthorizationCode($this->getCode()); | |
} | |
$this->connection->setAccessToken($this->getAccessToken()); | |
$this->connection->setRefreshToken($this->getRefreshToken()); | |
$this->connection->setTokenExpires($this->getExpiresIn()); | |
$this->connection->setTokenUpdateCallback("App\Exact\ExactOnline::tokenUpdateCallback"); | |
$this->exact_client = $this->connection->connect(); | |
$this->exact->refresh_token = $this->connection->getRefreshToken(); | |
$this->exact->access_token = $this->connection->getAccessToken(); | |
$this->exact->save(); | |
} | |
public function getCode() | |
{ | |
return $this->exact->code; | |
} | |
public function getToken($code) | |
{ | |
$response = $this->client->post(config('exact.oauth.token.url'),[ | |
'form_params' => [ | |
'grant_type' => 'authorization_code', | |
'code' => $code, | |
'client_id' => config('exact.client.id'), | |
'client_secret' => config('exact.client.secret'), | |
'redirect_uri' => config('exact.callback') | |
] | |
]); | |
return $response; | |
} | |
public function refreshToken() | |
{ | |
$this->exact = Exact::latest('id')->first(); | |
$response = $this->client->post(config('exact.oauth.token.url'),[ | |
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'], | |
'form_params' => [ | |
'refresh_token' => $this->exact->refresh_token, | |
'grant_type' => 'refresh_token', | |
'client_id' => config('exact.client.id'), | |
'client_secret' => config('exact.client.secret') | |
] | |
]); | |
return $response; | |
} | |
public function getRefreshToken() | |
{ | |
return $this->exact->refresh_token; | |
} | |
public function getAccessToken() | |
{ | |
return $this->exact->access_token; | |
} | |
public function getExpiresIn() | |
{ | |
return Carbon::parse($this->exact->next_update)->subSeconds(10)->timestamp; | |
} | |
public function validate($data) | |
{ | |
$check = Validator::make($data, [ | |
'access_token' => 'required', | |
'token_type' => 'required', | |
'expires_in' => 'required', | |
'refresh_token' => 'required' | |
]); | |
if($check->failed()) | |
{ | |
throw new \Exception("Validation failed"); | |
} | |
return true; | |
} | |
public function createDebtor($professional) | |
{ | |
} | |
public function updateDebtor(Professional $professional) | |
{ | |
} | |
public function createInvoice($professional) | |
{ | |
} | |
public function createInvoiceFile($id) | |
{ | |
} | |
public static function tokenUpdateCallback(Connection $connection) | |
{ | |
} | |
public function createBank($professional) | |
{ | |
} | |
public function getInvoices($id) | |
{ | |
} | |
public function getInvoiceLines($InvoiceID) | |
{ | |
} | |
public function getInvoiceFile($id, $professional) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment