Skip to content

Commit

Permalink
Merge pull request #482 from CiviCooP/check_and_aquire_refresh_token
Browse files Browse the repository at this point in the history
Fix for #481
  • Loading branch information
casperbakker authored Jul 1, 2021
2 parents 4669343 + 4db47f7 commit 98aea2a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/Picqer/Financials/Exact/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,26 @@ public function connect()
$this->redirectForAuthorization();
}

// If access token is not set or token has expired, acquire new token
if (empty($this->accessToken) || $this->tokenHasExpired()) {
$this->acquireAccessToken();
}
$this->checkOrAcquireAccessToken();

$client = $this->client();

return $client;
}

/**
* Checks whether the access token is still valid.
*
* @throws \Picqer\Financials\Exact\ApiException
*/
public function checkOrAcquireAccessToken()
{
// If access token is not set or token has expired, acquire new token
if (empty($this->accessToken) || $this->tokenHasExpired()) {
$this->acquireAccessToken();
}
}

/**
* @param string $method
* @param string $endpoint
Expand Down Expand Up @@ -259,6 +269,7 @@ public function get($url, array $params = [], array $headers = [])

try {
$request = $this->createRequest('GET', $url, null, $params, $headers);
$this->checkOrAcquireAccessToken();
$response = $this->client()->send($request);

return $this->parseResponse($response, $url != $this->nextUrl);
Expand All @@ -281,6 +292,7 @@ public function post($url, $body)

try {
$request = $this->createRequest('POST', $url, $body);
$this->checkOrAcquireAccessToken();
$response = $this->client()->send($request);

return $this->parseResponse($response);
Expand All @@ -303,6 +315,7 @@ public function put($url, $body)

try {
$request = $this->createRequest('PUT', $url, $body);
$this->checkOrAcquireAccessToken();
$response = $this->client()->send($request);

return $this->parseResponse($response);
Expand All @@ -324,6 +337,7 @@ public function delete($url)

try {
$request = $this->createRequest('DELETE', $url);
$this->checkOrAcquireAccessToken();
$response = $this->client()->send($request);

return $this->parseResponse($response);
Expand Down

0 comments on commit 98aea2a

Please sign in to comment.