From 3b786a803920cc728d954487998d55d1da138301 Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Thu, 3 Jun 2021 11:25:34 +0200 Subject: [PATCH 1/2] added function calls for checkOrAquireAccessToken --- src/Picqer/Financials/Exact/Connection.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index fb814b81..f3321870 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -195,16 +195,25 @@ 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 @@ -259,6 +268,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); @@ -281,6 +291,7 @@ public function post($url, $body) try { $request = $this->createRequest('POST', $url, $body); + $this->checkOrAcquireAccessToken(); $response = $this->client()->send($request); return $this->parseResponse($response); @@ -303,6 +314,7 @@ public function put($url, $body) try { $request = $this->createRequest('PUT', $url, $body); + $this->checkOrAcquireAccessToken(); $response = $this->client()->send($request); return $this->parseResponse($response); @@ -324,6 +336,7 @@ public function delete($url) try { $request = $this->createRequest('DELETE', $url); + $this->checkOrAcquireAccessToken(); $response = $this->client()->send($request); return $this->parseResponse($response); From 4db47f7251d43133ce4dceebfa48c0e465ebd36b Mon Sep 17 00:00:00 2001 From: Jaap Jansma Date: Thu, 3 Jun 2021 11:44:25 +0200 Subject: [PATCH 2/2] update --- src/Picqer/Financials/Exact/Connection.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Picqer/Financials/Exact/Connection.php b/src/Picqer/Financials/Exact/Connection.php index f3321870..a61fc2e0 100644 --- a/src/Picqer/Financials/Exact/Connection.php +++ b/src/Picqer/Financials/Exact/Connection.php @@ -207,7 +207,8 @@ public function connect() * * @throws \Picqer\Financials\Exact\ApiException */ - public function checkOrAcquireAccessToken() { + public function checkOrAcquireAccessToken() + { // If access token is not set or token has expired, acquire new token if (empty($this->accessToken) || $this->tokenHasExpired()) { $this->acquireAccessToken();