From effbb46ee8a26ba5ea747af9588bd1dcf1785397 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:37:51 +0100 Subject: [PATCH] allow to ignore cached tokens --- CHANGELOG.md | 3 ++- composer.json | 2 +- src/Core/Onboarding/Webhook.php | 7 ++++++- src/Core/ServiceFactory.php | 7 ++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09fa3956..36913fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - [0007675](https://bugs.oxid-esales.com/view.php?id=7675): fix the possibility to finish order without redirect and login to Paypal - [0007676](https://bugs.oxid-esales.com/view.php?id=7676): If we have a corrupted generated_services.yaml and try to deactivate the module via the admin, we will display a more understandable error message about what happened. - introduce ActionHash to make the PayPal-Request-ID more unique -- use PayPal-Client v3.0.11 +- use PayPal-Client v3.0.12 - [0007588](https://bugs.oxid-esales.com/view.php?id=7588): Improve Error handling for Capture Order Requests (thanks to mount7) - remove Sofort and MyBank, Paymentmethods will soon no longer be accepted via PayPal - fix: Refund only with note to Buyer (required) @@ -32,6 +32,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix PayPalExpress Reauth is necessary if the cart amount (total is greater than before) has changed during the checkout process - [0007666](https://bugs.oxid-esales.com/view.php?id=7666): Fix: Price surcharges on the detail page for selection lists are not taken into account - [0007695](https://bugs.oxid-esales.com/view.php?id=7695): Fix: if DeliverySet is set in Frontend, then do not add any PseudoDeliveryCosts for PPExpress +- add possibility to ignore cached tokens. It helps e.g. for webhook registration ### NEW - PayPal-Request-Id based on serialized body, no extra PayPal-Request-Id necessary anymore diff --git a/composer.json b/composer.json index 08f57d26..167db4c2 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "giggsey/libphonenumber-for-php": "^8.12", "viison/address-splitter": "^0.3.4", "webmozart/path-util": "^2.3.0", - "oxid-solution-catalysts/paypal-client": "v3.0.11" + "oxid-solution-catalysts/paypal-client": "v3.0.12" }, "require-dev": { "codeception/module-rest": "^3.3.0", diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index b56cee55..b6738a44 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 f182421f..ca035798 100644 --- a/src/Core/ServiceFactory.php +++ b/src/Core/ServiceFactory.php @@ -69,7 +69,7 @@ public function getWebhookService(string $uri = ''): GenericService { return oxNew( GenericService::class, - $this->getClient(), + $this->getClient(false), '/v1/notifications/webhooks' . $uri ); } @@ -113,7 +113,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 */ @@ -130,12 +130,13 @@ 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