From 83cdb35d8513b84b8002a38286bba8c81eed442f Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Fri, 6 Dec 2024 07:19:26 +0100 Subject: [PATCH 01/10] CustomId field extended and now contains: - ordernr - shop version - module version --- src/Service/Payment.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 5b3d10de7..d22995682 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -24,6 +24,7 @@ use OxidSolutionCatalysts\PayPal\Exception\PayPalException; use OxidSolutionCatalysts\PayPal\Exception\UserPhone as UserPhoneException; use OxidSolutionCatalysts\PayPal\Model\PayPalOrder as PayPalOrderModel; +use OxidSolutionCatalysts\PayPal\Module; use OxidSolutionCatalysts\PayPal\Service\ModuleSettings as ModuleSettingsService; use OxidSolutionCatalysts\PayPal\Traits\ServiceContainer; use OxidSolutionCatalysts\PayPalApi\Exception\ApiException; @@ -128,7 +129,7 @@ public function doCreatePayPalOrder( $basket, $intent, $userAction, - $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null, + null, //customId is patched in doCapturePayPalOrder (ordernr is unavailable at this point) $processingInstruction, $paymentSource, null, @@ -309,10 +310,8 @@ public function doCapturePayPalOrder( } elseif ($payPalOrder->status !== Constants::PAYPAL_STATUS_COMPLETED) { $request = new OrderCaptureRequest(); //order number must be resolved before order patching - $shopOrderId = $order->getFieldData('oxordernr'); - if (!$shopOrderId) { + if (!$order->hasOrderNumber()){ $order->setOrderNumber(); - $shopOrderId = $order->getFieldData('oxordernr'); } try { @@ -320,7 +319,7 @@ public function doCapturePayPalOrder( $this->doPatchPayPalOrder( Registry::getSession()->getBasket(), $checkoutOrderId, - $shopOrderId + $this->getCustomIdParameterJSON($order) ); /** @var $result ApiOrderModel */ @@ -808,4 +807,21 @@ private function displayErrorIfInstrumentDeclined(?string $issue): void ); } } + + /** + * @param \OxidEsales\Eshop\Application\Model\Order|null $order + * @return mixed|null + */ + public function getCustomIdParameterJSON(?EshopModelOrder $order) + { + $module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class); + $module->load(Module::MODULE_ID); + $customID = [ + 'oxordernr' => $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null, + 'moduleVersion' => $module->getInfo('version'), + 'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion() + ]; + + return json_encode($customID); + } } From 6ce87604ca3cafdb78b9c06bdc7a05b5fd7d4d07 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Fri, 6 Dec 2024 08:22:34 +0100 Subject: [PATCH 02/10] CustomId field backward compatibility support - added configuration for simple and structural custom id value --- metadata.php | 6 +++++ .../Admin/PayPalConfigController.php | 3 +++ src/Core/Config.php | 5 ++++ src/Service/ModuleSettings.php | 6 +++++ src/Service/Payment.php | 24 ++++++++++++------- views/admin/de/admin_lang.php | 3 +++ views/admin/en/admin_lang.php | 3 +++ views/admin/tpl/oscpaypalconfig.tpl | 22 +++++++++++++++++ 8 files changed, 64 insertions(+), 8 deletions(-) diff --git a/metadata.php b/metadata.php index 437c1bfb4..f22bef1d4 100755 --- a/metadata.php +++ b/metadata.php @@ -570,5 +570,11 @@ 'value' => 3.5, 'group' => null ], + [ + 'name' => 'oscPayPalUseStructuralCustomIdSchema', + 'type' => 'bool', + 'value' => false, + 'group' => null + ], ], ]; diff --git a/src/Controller/Admin/PayPalConfigController.php b/src/Controller/Admin/PayPalConfigController.php index dfaf5cf3f..6c6dd03e8 100644 --- a/src/Controller/Admin/PayPalConfigController.php +++ b/src/Controller/Admin/PayPalConfigController.php @@ -287,6 +287,9 @@ protected function handleSpecialFields(array $conf): array $dAmount = (string) str_replace(',', '.', $conf['oscPayPalDefaultShippingPriceExpress']); $conf['oscPayPalDefaultShippingPriceExpress'] = $dAmount; } + if (!isset($conf['oscPayPalUseStructuralCustomIdSchema'])) { + $conf['oscPayPalUseStructuralCustomIdSchema'] = false; + } return $conf; } diff --git a/src/Core/Config.php b/src/Core/Config.php index 612159ee7..e6ddd228b 100755 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -343,6 +343,11 @@ public function getStartTimeCleanUpOrders(): int return $this->getServiceFromContainer(ModuleSettings::class)->getStartTimeCleanUpOrders(); } + public function isCustomIdSchemaStructural(): bool + { + return $this->getServiceFromContainer(ModuleSettings::class)->isCustomIdSchemaStructural(); + } + public function tableExists(string $tableName = ''): bool { $exists = false; diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index e6317bdf7..b2028b2f1 100755 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -624,11 +624,17 @@ public function getIsVaultingActive(): bool { return (bool)$this->getSettingValue('oscPayPalSetVaulting'); } + public function getIsGooglePayDeliveryAddressActive(): bool { return (bool)$this->getSettingValue('oscPayPalUseGooglePayAddress'); } + public function isCustomIdSchemaStructural(): bool + { + return (bool)$this->getSettingValue('oscPayPalUseStructuralCustomIdSchema'); + } + /** * @return mixed */ diff --git a/src/Service/Payment.php b/src/Service/Payment.php index d22995682..af39adb4e 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -319,7 +319,7 @@ public function doCapturePayPalOrder( $this->doPatchPayPalOrder( Registry::getSession()->getBasket(), $checkoutOrderId, - $this->getCustomIdParameterJSON($order) + $this->getCustomIdParameter($order) ); /** @var $result ApiOrderModel */ @@ -812,16 +812,24 @@ private function displayErrorIfInstrumentDeclined(?string $issue): void * @param \OxidEsales\Eshop\Application\Model\Order|null $order * @return mixed|null */ - public function getCustomIdParameterJSON(?EshopModelOrder $order) + public function getCustomIdParameter(?EshopModelOrder $order): string { + /** @var ModuleSettingsService $moduleSettings */ + $moduleSettings = $this->getServiceFromContainer(ModuleSettings::class); $module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class); $module->load(Module::MODULE_ID); - $customID = [ - 'oxordernr' => $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null, - 'moduleVersion' => $module->getInfo('version'), - 'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion() - ]; + $orderNumber = $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null; + + if($moduleSettings->isCustomIdSchemaStructural()){ + $customID = [ + 'oxordernr' => $orderNumber, + 'moduleVersion' => $module->getInfo('version'), + 'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion() + ]; + + return json_encode($customID); + } - return json_encode($customID); + return $orderNumber; } } diff --git a/views/admin/de/admin_lang.php b/views/admin/de/admin_lang.php index fe8e2f638..50452650e 100755 --- a/views/admin/de/admin_lang.php +++ b/views/admin/de/admin_lang.php @@ -289,4 +289,7 @@ // PayPal Payment 'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'Diese PayPal Zahlungsart kann nicht mehr aktiviert werden, da diese demnächst entfernt wird!', + + 'OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE' => 'PayPal Inhalte des benutzerdefinierten ID-Feldes', + 'OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC' => 'Das benutzerdefinierte PayPal-ID-Feld kann entweder nur den Bestellnummernwert oder ein JSON mit zusätzlichen Daten enthalten.', ]; diff --git a/views/admin/en/admin_lang.php b/views/admin/en/admin_lang.php index 9e1831595..0f471ba51 100755 --- a/views/admin/en/admin_lang.php +++ b/views/admin/en/admin_lang.php @@ -290,4 +290,7 @@ // PayPal Payment 'OSC_PAYPAL_PAYMENT_DEPRECATED' => 'This PayPal payment method can no longer be activated as it will be removed soon!', + + 'OSC_PAYPAL_CUSTOM_ID_CONTENTS_TITLE' => 'PayPal custom id field contents', + 'OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC' => 'PayPal custom id field will be JSON encoded string with order number, shop version and the PayPal module version.', ]; diff --git a/views/admin/tpl/oscpaypalconfig.tpl b/views/admin/tpl/oscpaypalconfig.tpl index 2ab2b16b1..079bc7270 100755 --- a/views/admin/tpl/oscpaypalconfig.tpl +++ b/views/admin/tpl/oscpaypalconfig.tpl @@ -546,6 +546,28 @@ + +
+
+ +
+
+
+
+
+
+
+ isCustomIdSchemaStructural()}] checked[{/if}]> + [{oxmultilang ident="OSC_PAYPAL_CUSTOM_ID_CONTENTS_DESC"}] +
+
+
+
+
+
+
[{*
From d458195d99642ce6da39a2c619ab74de16be1161 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:31:36 +0000 Subject: [PATCH 03/10] Update tag to v2.0.17 --- LATEST_CLIENT_TAG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LATEST_CLIENT_TAG b/LATEST_CLIENT_TAG index 3a3b26eac..e97b65edf 100644 --- a/LATEST_CLIENT_TAG +++ b/LATEST_CLIENT_TAG @@ -1 +1 @@ -v2.0.16 \ No newline at end of file +v2.0.17 \ No newline at end of file From facc1c9eb5b43bfd7d1c21cc1e022a9a3717a56b Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:00:33 +0100 Subject: [PATCH 04/10] 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 From 3d8b7bdb88c4370712c9719519e74d9db4377c2f Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:15:50 +0100 Subject: [PATCH 05/10] CHANGELOG, version, composer.json --- CHANGELOG.md | 2 ++ composer.json | 2 +- metadata.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d012b8c..ee314db6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Catch possible thrown Error by getting DataClientToken - [0007719](https://bugs.oxid-esales.com/view.php?id=7719): Tracking code also be stored in standard DB field for backwards compatibility +- add possibility to ignore cached tokens. It helps e.g. for webhook registration +- use PayPal-Client v2.0.17 ## [2.5.1] - 2024-09-20 diff --git a/composer.json b/composer.json index 4572713c7..4a2720227 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": "v2.0.16" + "oxid-solution-catalysts/paypal-client": "v2.0.17" }, "require-dev": { "codeception/module-rest": "^1.4.2", diff --git a/metadata.php b/metadata.php index 437c1bfb4..ab15987b6 100755 --- a/metadata.php +++ b/metadata.php @@ -61,7 +61,7 @@ 'en' => 'Use of the online payment service from PayPal. Documentation: PayPal Checkout' ], 'thumbnail' => 'out/img/paypal.png', - 'version' => '2.5.2-rc.1', + 'version' => '2.5.2-rc.2', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com', From e589695d2aad78d4beb87e4780cb58576c21cd2f Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:30:33 +0000 Subject: [PATCH 06/10] Update tag to v1.0.12 --- LATEST_CLIENT_TAG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LATEST_CLIENT_TAG b/LATEST_CLIENT_TAG index e97b65edf..9b9bc15c8 100644 --- a/LATEST_CLIENT_TAG +++ b/LATEST_CLIENT_TAG @@ -1 +1 @@ -v2.0.17 \ No newline at end of file +v1.0.12 \ No newline at end of file From c1ca224d36e7a1dbf896c42a1320bd94672c1db3 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:31:36 +0000 Subject: [PATCH 07/10] Update tag to v2.0.17 --- LATEST_CLIENT_TAG | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LATEST_CLIENT_TAG b/LATEST_CLIENT_TAG index 3a3b26eac..e97b65edf 100644 --- a/LATEST_CLIENT_TAG +++ b/LATEST_CLIENT_TAG @@ -1 +1 @@ -v2.0.16 \ No newline at end of file +v2.0.17 \ No newline at end of file From 545e0da35a038e5a11a3fbaf33acb6317329b1ab Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:00:33 +0100 Subject: [PATCH 08/10] 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 From 7e7492a6f924131460adb6a9254b40b1797981a4 Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:15:50 +0100 Subject: [PATCH 09/10] CHANGELOG, version, composer.json --- CHANGELOG.md | 2 ++ composer.json | 2 +- metadata.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46d012b8c..ee314db6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Catch possible thrown Error by getting DataClientToken - [0007719](https://bugs.oxid-esales.com/view.php?id=7719): Tracking code also be stored in standard DB field for backwards compatibility +- add possibility to ignore cached tokens. It helps e.g. for webhook registration +- use PayPal-Client v2.0.17 ## [2.5.1] - 2024-09-20 diff --git a/composer.json b/composer.json index 4572713c7..4a2720227 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": "v2.0.16" + "oxid-solution-catalysts/paypal-client": "v2.0.17" }, "require-dev": { "codeception/module-rest": "^1.4.2", diff --git a/metadata.php b/metadata.php index f22bef1d4..f071ae3d3 100755 --- a/metadata.php +++ b/metadata.php @@ -61,7 +61,7 @@ 'en' => 'Use of the online payment service from PayPal. Documentation: PayPal Checkout' ], 'thumbnail' => 'out/img/paypal.png', - 'version' => '2.5.2-rc.1', + 'version' => '2.5.2-rc.2', 'author' => 'OXID eSales AG', 'url' => 'https://www.oxid-esales.com', 'email' => 'info@oxid-esales.com', From 70caaa0b55a2c8d25f62012b5926c3d02c8c3e4e Mon Sep 17 00:00:00 2001 From: Mario Lorenz Date: Fri, 13 Dec 2024 14:48:30 +0100 Subject: [PATCH 10/10] CHANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee314db6c..8132b1496 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - add possibility to ignore cached tokens. It helps e.g. for webhook registration - use PayPal-Client v2.0.17 +### NEW + +- Custom id passed to PayPal as JSON with additional versioning data + ## [2.5.1] - 2024-09-20 ### FIX