From 6ce87604ca3cafdb78b9c06bdc7a05b5fd7d4d07 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Fri, 6 Dec 2024 08:22:34 +0100 Subject: [PATCH] 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"}] +
+
+
+
+
+
+
[{*