Skip to content

Commit

Permalink
Merge pull request PendoNL#6 from websmurf/master
Browse files Browse the repository at this point in the history
Added hook for tokenUpdateCallback
  • Loading branch information
joshuadegier authored Nov 22, 2019
2 parents e1495c8 + 0ac4210 commit d41e835
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/LaravelExactOnline.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use File;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Picqer\Financials\Exact\Connection;

class LaravelExactOnline
{
Expand Down Expand Up @@ -50,6 +51,16 @@ public function __call($method, $arguments)

}

public static function tokenUpdateCallback (Connection $connection) {
$config = self::loadConfig();

$config->exact_accessToken = serialize($connection->getAccessToken());
$config->exact_refreshToken = $connection->getRefreshToken();
$config->exact_tokenExpires = $connection->getTokenExpires();

self::storeConfig($config);
}

public static function loadConfig()
{
if(config('laravel-exact-online.exact_multi_user')) {
Expand Down
2 changes: 2 additions & 0 deletions src/Providers/LaravelExactOnlineServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function register()
$connection->setTokenExpires($config->exact_tokenExpires);
}

$connection->setTokenUpdateCallback('\PendoNL\LaravelExactOnline\LaravelExactOnline::tokenUpdateCallback');

try {
if (isset($config->exact_authorisationCode)) {
$connection->connect();
Expand Down

0 comments on commit d41e835

Please sign in to comment.