From 631e2a97788f09aa48b895073e89d8e056924f18 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Fri, 6 Dec 2024 14:20:02 +0100 Subject: [PATCH 1/3] Custom id passed to PayPal as JSON with additional versioning data O7 twig --- metadata.php | 6 +++++ .../Admin/PayPalConfigController.php | 3 +++ src/Core/Config.php | 5 ++++ src/Service/ModuleSettings.php | 5 ++++ src/Service/Payment.php | 26 ++++++++++++++++++- views/de/admin_translations.php | 3 +++ views/en/admin_translations.php | 3 +++ views/twig/admin/oscpaypalconfig.html.twig | 26 +++++++++++++++++++ 8 files changed, 76 insertions(+), 1 deletion(-) diff --git a/metadata.php b/metadata.php index dd046d2f3..322832834 100644 --- a/metadata.php +++ b/metadata.php @@ -469,5 +469,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 c6fa0c3b7..72d8548d2 100644 --- a/src/Controller/Admin/PayPalConfigController.php +++ b/src/Controller/Admin/PayPalConfigController.php @@ -280,6 +280,9 @@ protected function handleSpecialFields(array $conf): array $dAmount = (float) 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 d8a1611f8..6f5c54238 100644 --- a/src/Core/Config.php +++ b/src/Core/Config.php @@ -322,6 +322,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 d90069535..b6a839b13 100644 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -363,6 +363,11 @@ public function getIsVaultingActive(): bool return (bool)$this->getSettingValue('oscPayPalSetVaulting'); } + public function isCustomIdSchemaStructural(): bool + { + return (bool)$this->getSettingValue('oscPayPalUseStructuralCustomIdSchema'); + } + /** * @throws ModuleSettingNotFountException */ diff --git a/src/Service/Payment.php b/src/Service/Payment.php index ac7be394a..dcb8ca040 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -23,6 +23,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\PayPalApi\Exception\ApiException; use OxidSolutionCatalysts\PayPalApi\Model\Orders\AuthorizationWithAdditionalData; @@ -126,7 +127,7 @@ public function doCreatePayPalOrder( $basket, $intent, $userAction, - $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null, + $this->getCustomIdParameter($order), $processingInstruction, $paymentSource, null, @@ -800,4 +801,27 @@ private function displayErrorIfInstrumentDeclined(?string $issue): void ); } } + + /** + * @param \OxidEsales\Eshop\Application\Model\Order|null $order + * @return mixed|null + */ + public function getCustomIdParameter(?EshopModelOrder $order): string + { + $module = oxNew(\OxidEsales\Eshop\Core\Module\Module::class); + $module->load(Module::MODULE_ID); + $orderNumber = $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null; + + if($this->moduleSettingsService->isCustomIdSchemaStructural()){ + $customID = [ + 'oxordernr' => $orderNumber, + 'moduleVersion' => $module->getInfo('version'), + 'oxidVersion' => \OxidEsales\Eshop\Core\ShopVersion::getVersion() + ]; + + return json_encode($customID); + } + + return $orderNumber; + } } diff --git a/views/de/admin_translations.php b/views/de/admin_translations.php index 5d3fe6485..dc6c1e9d1 100644 --- a/views/de/admin_translations.php +++ b/views/de/admin_translations.php @@ -275,4 +275,7 @@ eine höhere Checkout-Conversion bedeuten.', 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Da das Modul nicht korrekt per Composer installiert ist, sind Fehler bei der (De-)Aktivierung des Moduls aufgetreten. Bitte installieren Sie das Modul via Composer frisch und wiederholen den Vorgang.', + + '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/en/admin_translations.php b/views/en/admin_translations.php index 0322f804e..fee29820b 100644 --- a/views/en/admin_translations.php +++ b/views/en/admin_translations.php @@ -276,4 +276,7 @@ mean higher checkout conversion.', 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.', + + '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/twig/admin/oscpaypalconfig.html.twig b/views/twig/admin/oscpaypalconfig.html.twig index 0347d20d6..d0e9f59fe 100644 --- a/views/twig/admin/oscpaypalconfig.html.twig +++ b/views/twig/admin/oscpaypalconfig.html.twig @@ -510,6 +510,32 @@ + +
+
+ +
+ +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ From 5cb6a1401cb5eac4efafbd9b522f6e82a66f2751 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Tue, 10 Dec 2024 15:41:31 +0100 Subject: [PATCH 2/3] Additional information for pseudo shipping cost for PayPal Express O7 Twig --- views/de/admin_translations.php | 1 + views/en/admin_translations.php | 11 ++++++----- views/twig/admin/oscpaypalconfig.html.twig | 3 +++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/views/de/admin_translations.php b/views/de/admin_translations.php index dc6c1e9d1..dbeea3914 100644 --- a/views/de/admin_translations.php +++ b/views/de/admin_translations.php @@ -264,6 +264,7 @@ 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Wie alt müssen nicht beendete Bestellungen sein, damit sie frühestens automatisch storniert werden (in Minuten)?', 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudoversandkosten für PayPal Express', 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'Die hier eingegebenen Pseudeversandkosten werden verwendet, wenn die Shopoption “Versandkosten auch dann berechnen, wenn der Kunde noch nicht eingeloggt ist” nicht aktiviert ist.', + 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED' => 'Wenn Sie anstelle der Pseudo-Versandkosten für noch nicht angemeldete Benutzer mit PayPal Express die standardmäßige Versandkostenberechnung verwenden möchten, aktivieren Sie die Option `Standardversandkosten berechnen, wenn Benutzer noch nicht angemeldet sind` in den Mastereinstellungen | Einstellungen-Tab | Abschnitt Sonstige Einstellungen.', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Versanddienstleister (Land)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Versanddienstleister (Anbieter)', 'OSC_PAYPAL_TRACKCARRIER_GLOBAL' => 'weltweit', diff --git a/views/en/admin_translations.php b/views/en/admin_translations.php index fee29820b..50daebd00 100644 --- a/views/en/admin_translations.php +++ b/views/en/admin_translations.php @@ -262,8 +262,9 @@ cancel manually.', 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Start time for automatic cancellation', 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'How old do not finished orders have to be before they are automatically canceled (in minutes)?', - 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudo shipping costs for PayPal Express', - 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'The shipping costs entered here are used if the store option "Calculate default Shipping costs when User is not logged in yet” in not activated.', + 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudo shipping costs for PayPal Express', + 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'The shipping costs entered here are used if the store option "Calculate default Shipping costs when User is not logged in yet” in not activated.', + 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED' => 'If You want to use standard shipping cost calculation instead of pseudo shipping cost for not yet logged in users with PayPal Express please check `Calculate default Shipping costs when User is not logged in yet` option in Master settings | Settings tab | Other settings section.', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Tracking Carrier (Country)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Tracking Carrier (Provider)', @@ -275,8 +276,8 @@ Enable purchase processing. With their saved payment details, customers can make repeat purchases with just a few clicks. This can be for you mean higher checkout conversion.', - 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.', + 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.', - '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.', + '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/twig/admin/oscpaypalconfig.html.twig b/views/twig/admin/oscpaypalconfig.html.twig index d0e9f59fe..8d1fdd5db 100644 --- a/views/twig/admin/oscpaypalconfig.html.twig +++ b/views/twig/admin/oscpaypalconfig.html.twig @@ -504,6 +504,9 @@
{{ translate({ ident: "OSC_PAYPAL_EXPRESS_SHIPPING_DESC" }) }} +
+
+ {{ translate({ ident: "OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED" }) }}
From f656716dd04844882b216ccbd19c25d595aa3e3f Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Tue, 10 Dec 2024 15:42:44 +0100 Subject: [PATCH 3/3] Revert "Additional information for pseudo shipping cost for PayPal Express O7 Twig" This reverts commit 5cb6a1401cb5eac4efafbd9b522f6e82a66f2751. --- views/de/admin_translations.php | 1 - views/en/admin_translations.php | 11 +++++------ views/twig/admin/oscpaypalconfig.html.twig | 3 --- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/views/de/admin_translations.php b/views/de/admin_translations.php index dbeea3914..dc6c1e9d1 100644 --- a/views/de/admin_translations.php +++ b/views/de/admin_translations.php @@ -264,7 +264,6 @@ 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Wie alt müssen nicht beendete Bestellungen sein, damit sie frühestens automatisch storniert werden (in Minuten)?', 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudoversandkosten für PayPal Express', 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'Die hier eingegebenen Pseudeversandkosten werden verwendet, wenn die Shopoption “Versandkosten auch dann berechnen, wenn der Kunde noch nicht eingeloggt ist” nicht aktiviert ist.', - 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED' => 'Wenn Sie anstelle der Pseudo-Versandkosten für noch nicht angemeldete Benutzer mit PayPal Express die standardmäßige Versandkostenberechnung verwenden möchten, aktivieren Sie die Option `Standardversandkosten berechnen, wenn Benutzer noch nicht angemeldet sind` in den Mastereinstellungen | Einstellungen-Tab | Abschnitt Sonstige Einstellungen.', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Versanddienstleister (Land)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Versanddienstleister (Anbieter)', 'OSC_PAYPAL_TRACKCARRIER_GLOBAL' => 'weltweit', diff --git a/views/en/admin_translations.php b/views/en/admin_translations.php index 50daebd00..fee29820b 100644 --- a/views/en/admin_translations.php +++ b/views/en/admin_translations.php @@ -262,9 +262,8 @@ cancel manually.', 'OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'Start time for automatic cancellation', 'HELP_OSC_PAYPAL_STARTTIME_CLEANUP_ORDERS' => 'How old do not finished orders have to be before they are automatically canceled (in minutes)?', - 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudo shipping costs for PayPal Express', - 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'The shipping costs entered here are used if the store option "Calculate default Shipping costs when User is not logged in yet” in not activated.', - 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED' => 'If You want to use standard shipping cost calculation instead of pseudo shipping cost for not yet logged in users with PayPal Express please check `Calculate default Shipping costs when User is not logged in yet` option in Master settings | Settings tab | Other settings section.', + 'OSC_PAYPAL_EXPRESS_SHIPPING_TITLE' => 'Pseudo shipping costs for PayPal Express', + 'OSC_PAYPAL_EXPRESS_SHIPPING_DESC' => 'The shipping costs entered here are used if the store option "Calculate default Shipping costs when User is not logged in yet” in not activated.', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_COUNTRY' => 'Tracking Carrier (Country)', 'OSC_PAYPAL_ORDER_MAIN_TRACKCARRIER_PROVIDER' => 'Tracking Carrier (Provider)', @@ -276,8 +275,8 @@ Enable purchase processing. With their saved payment details, customers can make repeat purchases with just a few clicks. This can be for you mean higher checkout conversion.', - 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.', + 'OSC_PAYPAL_INSTALLPROCESS_FAILED' => 'Because the module was not installed correctly via Composer, errors occurred during the (de)activation of the module. Please reinstall the module via composer and repeat the process.', - '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.', + '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/twig/admin/oscpaypalconfig.html.twig b/views/twig/admin/oscpaypalconfig.html.twig index 8d1fdd5db..d0e9f59fe 100644 --- a/views/twig/admin/oscpaypalconfig.html.twig +++ b/views/twig/admin/oscpaypalconfig.html.twig @@ -504,9 +504,6 @@
{{ translate({ ident: "OSC_PAYPAL_EXPRESS_SHIPPING_DESC" }) }} -
-
- {{ translate({ ident: "OSC_PAYPAL_EXPRESS_SHIPPING_DESC_EXTENDED" }) }}