Skip to content

Commit a19ba53

Browse files
authored
feat: add compat with account v8 (#446)
1 parent af472c9 commit a19ba53

File tree

5 files changed

+22
-33
lines changed

5 files changed

+22
-33
lines changed

src/Api/CloudSyncClient.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright since 2007 PrestaShop SA and Contributors
45
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
@@ -97,7 +98,7 @@ public function __construct(
9798
PsAccountsAdapterService $psAccountsAdapterService
9899
) {
99100
$this->module = $module;
100-
$this->jwt = $psAccountsAdapterService->getOrRefreshToken();
101+
$this->jwt = $psAccountsAdapterService->getShopToken();
101102
$this->shopId = $psAccountsAdapterService->getShopUuid();
102103

103104
$this->collectorApiUrl = $collectorApiUrl;

src/Service/ApiAuthorizationService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function authorize($jobId, $isHealthCheck)
8181
}
8282

8383
try {
84-
$token = $this->psAccountsAdapterService->getOrRefreshToken();
84+
$token = $this->psAccountsAdapterService->getShopToken();
8585
} catch (\Exception $exception) {
8686
throw new FirebaseException($exception->getMessage());
8787
}

src/Service/ApiHealthCheckService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright since 2007 PrestaShop SA and Contributors
45
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
@@ -103,7 +104,7 @@ public function getHealthCheck($jobId)
103104
$isAuthentified = $this->apiAuthorizationService->authorize($jobId, true);
104105

105106
try {
106-
$token = $this->psAccountsAdapterService->getOrRefreshToken();
107+
$token = $this->psAccountsAdapterService->getShopToken();
107108
if ($token) {
108109
$psAccount = \Module::getInstanceByName('ps_accounts');
109110

src/Service/PresenterService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright since 2007 PrestaShop SA and Contributors
45
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
@@ -70,7 +71,7 @@ public function expose(\ModuleCore $module, $requiredConsents = [], $optionalCon
7071
}
7172

7273
return [
73-
'jwt' => $this->psAccountsAdapterService->getOrRefreshToken(),
74+
'jwt' => $this->psAccountsAdapterService->getShopToken(),
7475
'requiredConsents' => $requiredConsents,
7576
'optionalConsents' => $optionalConsents,
7677
'module' => array_merge([

src/Service/PsAccountsAdapterService.php

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Copyright since 2007 PrestaShop SA and Contributors
45
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
@@ -76,7 +77,7 @@ public function getModule()
7677
*
7778
* @return mixed
7879
*/
79-
public function getService()
80+
public function getAccountService()
8081
{
8182
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts')) {
8283
return false;
@@ -94,42 +95,19 @@ public function getService()
9495
}
9596
}
9697

97-
/**
98-
* Get presenter from psAccounts, or null if module is'nt ready
99-
*
100-
* @return mixed
101-
*/
102-
public function getPresenter()
103-
{
104-
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
105-
return false;
106-
}
107-
108-
try {
109-
return $this->psAccountModule->getService('PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter');
110-
} catch (\Exception $e) {
111-
$this->errorHandler->handle(
112-
new \PrestaShopException('Failed to load PsAccountsPresenter', 0, $e),
113-
true
114-
);
115-
116-
return false;
117-
}
118-
}
119-
12098
/**
12199
* Get shopUuid from psAccounts, or null if module is'nt ready
122100
*
123101
* @return string
124102
*/
125103
public function getShopUuid()
126104
{
127-
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
105+
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getAccountService()) {
128106
return '';
129107
}
130108

131109
try {
132-
return $this->getService()->getShopUuid();
110+
return $this->getAccountService()->getShopUuid();
133111
} catch (\Exception $e) {
134112
$this->errorHandler->handle(
135113
new \PrestaShopException('Failed to get shop uuid from ps_account', 0, $e),
@@ -145,14 +123,22 @@ public function getShopUuid()
145123
*
146124
* @return string
147125
*/
148-
public function getOrRefreshToken()
126+
public function getShopToken()
149127
{
150-
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getService()) {
128+
if (!$this->moduleHelper->isInstalledAndActive('ps_accounts') || !$this->getAccountService()) {
129+
return '';
130+
}
131+
132+
if ($this->psAccountModule == false) {
151133
return '';
152134
}
153135

154136
try {
155-
return $this->getService()->getOrRefreshToken();
137+
if (version_compare($this->psAccountModule->version, '7.1.1', '>=')) {
138+
return $this->getAccountService()->getShopToken();
139+
} else {
140+
return $this->getAccountService()->getOrRefreshToken();
141+
}
156142
} catch (\Exception $e) {
157143
$this->errorHandler->handle(
158144
new \PrestaShopException('Failed to get refresh token from ps_account', 0, $e),

0 commit comments

Comments
 (0)