From facc1c9eb5b43bfd7d1c21cc1e022a9a3717a56b Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:00:33 +0100 Subject: [PATCH] allow to ignore cached tokens --- src/Core/Onboarding/Webhook.php | 7 ++++++- src/Core/ServiceFactory.php | 8 +++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index b56cee558..b6738a441 100644 --- a/src/Core/Onboarding/Webhook.php +++ b/src/Core/Onboarding/Webhook.php @@ -16,6 +16,7 @@ use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; +use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; class Webhook @@ -119,7 +120,11 @@ public function getAllRegisteredWebhooks(): array { /** @var GenericService $notificationService */ $webhookService = Registry::get(ServiceFactory::class)->getWebhookService(); - $result = $webhookService->request('GET'); + try { + $result = $webhookService->request('GET'); + } catch (ApiException $e) { + $result = []; + } return $result['webhooks'] ?? []; } diff --git a/src/Core/ServiceFactory.php b/src/Core/ServiceFactory.php index 368868807..8e26fb071 100644 --- a/src/Core/ServiceFactory.php +++ b/src/Core/ServiceFactory.php @@ -70,7 +70,7 @@ public function getWebhookService(string $uri = ''): GenericService { return oxNew( GenericService::class, - $this->getClient(), + $this->getClient(false), '/v1/notifications/webhooks' . $uri ); } @@ -125,7 +125,7 @@ public function getIdentityService(): IdentityService * * @return Client */ - private function getClient(): Client + private function getClient(bool $useToken = true): Client { if ($this->client === null) { /** @var Config $config */ @@ -142,12 +142,14 @@ private function getClient(): Client $paymentId = $session->getVariable('paymentid'); $actionHash = md5($sessionId . $basketId . $paymentId); + $sTokenCacheFileName = $useToken ? $config->getTokenCacheFileName() : ''; + $client = new Client( $logger, $config->isSandbox() ? Client::SANDBOX_URL : Client::PRODUCTION_URL, $config->getClientId(), $config->getClientSecret(), - $config->getTokenCacheFileName(), + $sTokenCacheFileName, $actionHash, // must be empty. We do not have the merchant's payerid //and confirmed by paypal we should not use it for auth and