From 33088b74e8dd237ad705b5dc9fe03d80d2624c23 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 13 Nov 2024 14:06:24 +0100 Subject: [PATCH 1/4] Fatal error fix --- src/Service/Payment.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Service/Payment.php b/src/Service/Payment.php index de63da9b0..659524e51 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -682,7 +682,11 @@ public function fetchOrderFields(string $paypalOrderId, string $fields = ''): Ap { return $this->serviceFactory ->getOrderService() - ->showOrderDetails($paypalOrderId, $fields); + ->showOrderDetails( + $paypalOrderId, + $fields, + Constants::PAYPAL_PARTNER_ATTRIBUTION_ID_PPCP + ); } /** From 94f64f594f5f047aa7888d424571a044fda04831 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:10:07 +0100 Subject: [PATCH 2/4] allow to ignore cached tokens --- CHANGELOG.md | 4 ++++ composer.json | 2 +- src/Core/Onboarding/Webhook.php | 14 ++++++++++++-- src/Core/ServiceFactory.php | 14 +++++++++++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 22e69e162..b12d76e71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.3.12] - 2024-??-?? + +- add possibility to ignore cached tokens. It helps e.g. for webhook registration + ## [1.3.11] - 2024-09-12 - Provide BN codes even to previously overlooked API calls diff --git a/composer.json b/composer.json index 15fd51558..754866bf7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "giggsey/libphonenumber-for-php": "^8.12", "viison/address-splitter": "^0.3.4", "webmozart/path-util": "^2.3.0", - "oxid-solution-catalysts/paypal-client": "v1.0.11" + "oxid-solution-catalysts/paypal-client": "v1.0.12" }, "require-dev": { "oxid-esales/oxideshop-ce": "^v6.3.0", diff --git a/src/Core/Onboarding/Webhook.php b/src/Core/Onboarding/Webhook.php index 089e3e1a0..b0b3ff05e 100644 --- a/src/Core/Onboarding/Webhook.php +++ b/src/Core/Onboarding/Webhook.php @@ -15,6 +15,7 @@ use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings; use OxidSolutionCatalysts\PayPal\Exception\OnboardingException; +use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Service\GenericService; class Webhook @@ -32,7 +33,12 @@ public function ensureWebhook(): string $hook = $this->getHookForUrl($endpoint); $webhookId = isset($hook['id']) ? $hook['id'] : ''; $registeredEvents = $this->getEnabledEvents($hook); - if (array_diff($this->getAvailableEventNames(), $registeredEvents)) { + if ( + array_diff( + array_column($this->getAvailableEventNames(), "name"), + array_column($registeredEvents, "name") + ) + ) { $this->removeWebhook($webhookId); $webhookId = $this->registerWebhooks(); } @@ -113,7 +119,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 a82069f2a..dc75515fd 100644 --- a/src/Core/ServiceFactory.php +++ b/src/Core/ServiceFactory.php @@ -67,7 +67,7 @@ public function getWebhookService(string $uri = ''): GenericService { return oxNew( GenericService::class, - $this->getClient(), + $this->getClient(false), '/v1/notifications/webhooks' . $uri ); } @@ -111,19 +111,27 @@ public function getIdentityService(): IdentityService * * @return Client */ - private function getClient(): Client + private function getClient(bool $useToken = true): Client { if ($this->client === null) { /** @var Config $config */ $config = oxNew(Config::class); $logger = new PayPalLogger(); + // prepare a unique action hash + $session = Registry::getSession(); + $sessionId = $session->getId(); + $basketId = $session->getVariable('sess_challenge'); + $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 //so not ask for it on the configuration page From f859e5582aa7e1f71c1904fdf0596a6bcb766e36 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:11:12 +0100 Subject: [PATCH 3/4] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b12d76e71..1b5be1c2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [1.3.12] - 2024-??-?? - add possibility to ignore cached tokens. It helps e.g. for webhook registration +- Update Client Version v1.0.12 ## [1.3.11] - 2024-09-12 From 6a2d5c476acd707c68c234640b9dde374c02e058 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:12:49 +0100 Subject: [PATCH 4/4] change Version Number --- metadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.php b/metadata.php index 63aa35aad..1bb57fd8e 100644 --- a/metadata.php +++ b/metadata.php @@ -58,7 +58,7 @@ 'en' => 'Use of the online payment service from PayPal. Documentation: PayPal Checkout' ], 'thumbnail' => 'out/img/paypal.png', - 'version' => '1.3.11', + 'version' => '1.3.12-rc.1', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com',