From ea6bf3a554880a70590d94c5288b48909386921e Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Thu, 2 Oct 2025 16:00:13 +0300 Subject: [PATCH 01/15] Added new PayLater configuration handling and removed old configuration references --- .../PayPalPayLaterConfiguration.php | 14 +-- .../Configuration/PayPalSdkConfiguration.php | 44 ++++----- .../Validator/FrontControllerValidator.php | 19 ++-- .../Admin/Modules/ConfigurationModule.php | 38 ++++---- .../Settings/Admin/Modules/ContextModule.php | 11 ++- .../Settings/Admin/Modules/PaypalModule.php | 1 + .../Front/Modules/ConfigurationModule.php | 13 +-- ps17/config/admin/presenter.yml | 1 + .../AdminAjaxPrestashopCheckoutController.php | 50 ---------- ps17/upgrade/upgrade-7.5.1.1.php | 93 +++++++++++++++++++ ps8/config/admin/presenter.yml | 1 + .../AdminAjaxPrestashopCheckoutController.php | 56 +---------- ps8/upgrade/upgrade-8.5.1.1.php | 93 +++++++++++++++++++ ps9/config/admin/presenter.yml | 1 + .../AdminAjaxPrestashopCheckoutController.php | 50 ---------- ps9/upgrade/upgrade-9.5.1.1.php | 93 +++++++++++++++++++ 16 files changed, 353 insertions(+), 225 deletions(-) create mode 100644 ps17/upgrade/upgrade-7.5.1.1.php create mode 100644 ps8/upgrade/upgrade-8.5.1.1.php create mode 100644 ps9/upgrade/upgrade-9.5.1.1.php diff --git a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php index b750f9837..5b11f4abf 100644 --- a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php +++ b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php @@ -22,21 +22,11 @@ class PayPalPayLaterConfiguration { - const PS_CHECKOUT_PAY_LATER_ORDER_PAGE = 'PS_CHECKOUT_PAY_IN_4X_ORDER_PAGE'; - - const PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE = 'PS_CHECKOUT_PAY_IN_4X_PRODUCT_PAGE'; - - const PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER'; - - const PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER'; - - const PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER'; - - const PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER'; - const PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_ORDER_PAGE_BUTTON'; const PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_CART_PAGE_BUTTON'; const PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_PRODUCT_PAGE_BUTTON'; + + const PS_CHECKOUT_PAY_LATER_CONFIG = 'PS_CHECKOUT_PAY_LATER_CONFIG'; } diff --git a/core/src/Settings/Configuration/PayPalSdkConfiguration.php b/core/src/Settings/Configuration/PayPalSdkConfiguration.php index 7fb8523e5..88b49ee7c 100644 --- a/core/src/Settings/Configuration/PayPalSdkConfiguration.php +++ b/core/src/Settings/Configuration/PayPalSdkConfiguration.php @@ -261,35 +261,22 @@ private function shouldIncludeMessagesComponent(): bool { $pageName = $this->getPageName(); - if ('index' === $pageName && $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER)) { - return true; - } - - if ('category' === $pageName && $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER)) { - return true; - } - - if ( - in_array($pageName, ['cart', 'order']) && - ( - $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) || - $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER) - ) - ) { - return true; - } - - if ( - 'product' === $pageName && - ( - $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) || - $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER) - ) - ) { - return true; + $payLaterMessagingCustomization = $this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG); + + $payLaterMessagingCustomization = json_decode($payLaterMessagingCustomization, true); + + switch ($pageName) { + case 'cart': + case 'category': + case 'product': + return $payLaterMessagingCustomization[$pageName]['status'] === 'enabled'; + case 'order': + return $payLaterMessagingCustomization['checkout']['status'] === 'enabled'; + case 'index': + return $payLaterMessagingCustomization['homepage']['status'] === 'enabled'; + default: + return false; } - - return false; } private function shouldIncludeGooglePayComponent(): bool @@ -407,6 +394,7 @@ private function getPageName(): string */ private function getCountryIsoCode(): string { + return 'FR'; $code = ''; if (\Validate::isLoadedObject($this->context->getCountry())) { diff --git a/infrastructure/src/Validator/FrontControllerValidator.php b/infrastructure/src/Validator/FrontControllerValidator.php index 14e78d32c..e2aff4e9b 100644 --- a/infrastructure/src/Validator/FrontControllerValidator.php +++ b/infrastructure/src/Validator/FrontControllerValidator.php @@ -43,13 +43,15 @@ public function __construct( */ public function shouldLoadFrontCss(string $controller): bool { + $payLaterConfiguration = json_decode($this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG), true); + switch ($controller) { // Homepage case 'index': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER); + return $payLaterConfiguration['homepage']['status'] === 'enabled'; // Category case 'category': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER); + return $payLaterConfiguration['category']['status'] === 'enabled'; // Payment step case 'orderopc': case 'order': @@ -71,25 +73,26 @@ public function shouldLoadFrontCss(string $controller): bool */ public function shouldLoadFrontJS(string $controller): bool { + $payLaterConfiguration = json_decode($this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG), true); + switch ($controller) { // Homepage case 'index': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER); + return $payLaterConfiguration['homepage']['status'] === 'enabled'; // Category case 'category': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER); + return $payLaterConfiguration['category']['status'] === 'enabled'; case 'orderopc': case 'order': return true; case 'product': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) - || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER) + return + $payLaterConfiguration['product']['status'] === 'enabled' || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) || $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_PRODUCT_PAGE) || $this->configuration->getBoolean(PayPalConfiguration::PS_CHECKOUT_DISPLAY_LOGO_PRODUCT); case 'cart': - return $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) - || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER) + return $payLaterConfiguration['cart']['status'] === 'enabled' || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) || $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_ORDER_PAGE) || $this->configuration->getBoolean(PayPalConfiguration::PS_CHECKOUT_DISPLAY_LOGO_CART); diff --git a/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php index 2665e685e..dcb3ec381 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php @@ -91,25 +91,25 @@ public function present(): array 'productPage' => $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_PRODUCT_PAGE), ], 'payLater' => [ - 'orderPage' => [ - 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE), - 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER), - 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON), - ], - 'cartPage' => [ - 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON), - ], - 'productPage' => [ - 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE), - 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER), - 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON), - ], - 'categoryPage' => [ - 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER), - ], - 'homePage' => [ - 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER), - ], +// 'orderPage' => [ +// 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE), +// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER), +// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON), +// ], +// 'cartPage' => [ +// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON), +// ], +// 'productPage' => [ +// 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE), +// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER), +// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON), +// ], +// 'categoryPage' => [ +// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER), +// ], +// 'homePage' => [ +// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER), +// ], ], 'logger' => [ 'levels' => [ diff --git a/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php b/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php index 53533057f..fac98e63f 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php @@ -24,6 +24,7 @@ use PsCheckout\Infrastructure\Adapter\ConfigurationInterface; use PsCheckout\Infrastructure\Adapter\ContextInterface; use PsCheckout\Infrastructure\Adapter\LinkInterface; +use PsCheckout\Infrastructure\Environment\EnvInterface; use PsCheckout\Presentation\Presenter\PresenterInterface; /** @@ -55,6 +56,10 @@ class ContextModule implements PresenterInterface * @var ConfigurationInterface */ private $configuration; + /** + * @var EnvInterface + */ + private $env; /** * @param string $moduleName @@ -68,13 +73,15 @@ public function __construct( string $moduleVersion, ContextInterface $context, LinkInterface $link, - ConfigurationInterface $configuration + ConfigurationInterface $configuration, + EnvInterface $env ) { $this->moduleName = $moduleName; $this->moduleVersion = $moduleVersion; $this->context = $context; $this->link = $link; $this->configuration = $configuration; + $this->env = $env; } /** @@ -109,6 +116,8 @@ public function present(): array 'configure' => $this->moduleName, ] ), + 'clientId' => $this->env->getPaypalClientId(), + 'bnCode' => $this->env->getBnCode(), ], ]; } diff --git a/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php b/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php index c78002a3f..d3b4d3dff 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php @@ -22,6 +22,7 @@ use PsCheckout\Core\Settings\Configuration\PayPalConfiguration; use PsCheckout\Infrastructure\Adapter\ConfigurationInterface; +use PsCheckout\Infrastructure\Environment\EnvInterface; use PsCheckout\Presentation\Presenter\PresenterInterface; /** diff --git a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php index e570642e7..54410e903 100644 --- a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php @@ -108,15 +108,16 @@ public function present(): array $this->moduleName . 'ExpressCheckoutCartEnabled' => $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_ORDER_PAGE) && $isPayPalPaymentsReceivable, $this->moduleName . 'ExpressCheckoutOrderEnabled' => $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_CHECKOUT_PAGE) && $isPayPalPaymentsReceivable, $this->moduleName . 'ExpressCheckoutProductEnabled' => $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_PRODUCT_PAGE) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterOrderPageMessageEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterProductPageMessageEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterOrderPageBannerEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterHomePageBannerEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterCategoryPageBannerEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterProductPageBannerEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterOrderPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterCartPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterProductPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) && $isPayPalPaymentsReceivable, + $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->configuration->getDeserializedRaw(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG) : [ + 'product' => ['status' => 'disabled'], + 'homepage' => ['status' => 'disabled'], + 'cart' => ['status' => 'disabled'], + 'payment' => ['status' => 'disabled'], + 'category' => ['status' => 'disabled'], + ], ]; } } diff --git a/ps17/config/admin/presenter.yml b/ps17/config/admin/presenter.yml index e2636990b..c491cb70a 100644 --- a/ps17/config/admin/presenter.yml +++ b/ps17/config/admin/presenter.yml @@ -18,6 +18,7 @@ services: - '@PsCheckout\Infrastructure\Adapter\Context' - '@PsCheckout\Infrastructure\Adapter\Link' - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Infrastructure\Environment\Env' PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule: class: PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule diff --git a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php index b9eb50c5c..3703a4474 100644 --- a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -611,56 +611,6 @@ public function ajaxProcessToggleECProductPage() $this->ajaxRender(json_encode(true)); } - /** - * AJAX: Toggle pay later message on order page - */ - public function ajaxProcessTogglePayLaterOrderPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later message on product page - */ - public function ajaxProcessTogglePayLaterProductPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on home page - */ - public function ajaxProcessTogglePayLaterHomePageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on cart page - */ - public function ajaxProcessTogglePayLaterOrderPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on product page - */ - public function ajaxProcessTogglePayLaterProductPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - /** * AJAX: Toggle pay later button on cart page */ diff --git a/ps17/upgrade/upgrade-7.5.1.1.php b/ps17/upgrade/upgrade-7.5.1.1.php new file mode 100644 index 000000000..85f7ce644 --- /dev/null +++ b/ps17/upgrade/upgrade-7.5.1.1.php @@ -0,0 +1,93 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * Update main function for module version 7.5.1.1 + * + * @param Ps_checkout $module + * + * @return bool + */ +function upgrade_module_7_5_1_1(Ps_checkout $module) +{ + try { + $savedShopContext = Shop::getContext(); + $savedShopId = Shop::getContextShopID(); + $savedGroupShopId = Shop::getContextShopGroupID(); + Shop::setContext(Shop::CONTEXT_ALL); + $shopsList = \Shop::getShops(false, null, true); + + foreach ($shopsList as $shopId) { + $configuration = json_encode([ + 'product' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'homepage' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'cart' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'payment' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'category' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + ]); + + Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId); + } + + // Restore initial PrestaShop shop context + if (Shop::CONTEXT_SHOP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedShopId); + } elseif (Shop::CONTEXT_GROUP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedGroupShopId); + } else { + Shop::setContext($savedShopContext); + } + + } catch (Exception $exception) { + PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); + + return false; + } + + return true; +} diff --git a/ps8/config/admin/presenter.yml b/ps8/config/admin/presenter.yml index a5350210d..0444d2809 100644 --- a/ps8/config/admin/presenter.yml +++ b/ps8/config/admin/presenter.yml @@ -19,6 +19,7 @@ services: - '@PsCheckout\Infrastructure\Adapter\Context' - '@PsCheckout\Infrastructure\Adapter\Link' - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Infrastructure\Environment\Env' PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule: class: PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule diff --git a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php index ed640ea69..847707772 100644 --- a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -360,7 +360,11 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + if (is_array($configurationItem['value'])) { + $this->setConfiguration($configurationItem['name'], json_encode($configurationItem['value'])); + } else { + $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + } } $this->exitWithResponse([ @@ -610,56 +614,6 @@ public function ajaxProcessToggleECProductPage() $this->ajaxRender(json_encode(true)); } - /** - * AJAX: Toggle pay later message on order page - */ - public function ajaxProcessTogglePayLaterOrderPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later message on product page - */ - public function ajaxProcessTogglePayLaterProductPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on home page - */ - public function ajaxProcessTogglePayLaterHomePageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on cart page - */ - public function ajaxProcessTogglePayLaterOrderPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on product page - */ - public function ajaxProcessTogglePayLaterProductPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - /** * AJAX: Toggle pay later button on cart page */ diff --git a/ps8/upgrade/upgrade-8.5.1.1.php b/ps8/upgrade/upgrade-8.5.1.1.php new file mode 100644 index 000000000..ff0614d65 --- /dev/null +++ b/ps8/upgrade/upgrade-8.5.1.1.php @@ -0,0 +1,93 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * Update main function for module version 8.5.1.1 + * + * @param Ps_checkout $module + * + * @return bool + */ +function upgrade_module_8_5_1_1(Ps_checkout $module) +{ + try { + $savedShopContext = Shop::getContext(); + $savedShopId = Shop::getContextShopID(); + $savedGroupShopId = Shop::getContextShopGroupID(); + Shop::setContext(Shop::CONTEXT_ALL); + $shopsList = \Shop::getShops(false, null, true); + + foreach ($shopsList as $shopId) { + $configuration = json_encode([ + 'product' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'homepage' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'cart' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'payment' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'category' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + ]); + + Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId); + } + + // Restore initial PrestaShop shop context + if (Shop::CONTEXT_SHOP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedShopId); + } elseif (Shop::CONTEXT_GROUP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedGroupShopId); + } else { + Shop::setContext($savedShopContext); + } + + } catch (Exception $exception) { + PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); + + return false; + } + + return true; +} diff --git a/ps9/config/admin/presenter.yml b/ps9/config/admin/presenter.yml index a5350210d..0444d2809 100644 --- a/ps9/config/admin/presenter.yml +++ b/ps9/config/admin/presenter.yml @@ -19,6 +19,7 @@ services: - '@PsCheckout\Infrastructure\Adapter\Context' - '@PsCheckout\Infrastructure\Adapter\Link' - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Infrastructure\Environment\Env' PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule: class: PsCheckout\Presentation\Presenter\Settings\Admin\Modules\ConfigurationModule diff --git a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php index 6551378d3..dc000bc94 100644 --- a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -611,56 +611,6 @@ public function ajaxProcessToggleECProductPage() $this->ajaxRender(json_encode(true)); } - /** - * AJAX: Toggle pay later message on order page - */ - public function ajaxProcessTogglePayLaterOrderPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later message on product page - */ - public function ajaxProcessTogglePayLaterProductPageMessage() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on home page - */ - public function ajaxProcessTogglePayLaterHomePageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on cart page - */ - public function ajaxProcessTogglePayLaterOrderPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - - /** - * AJAX: Toggle pay later banner on product page - */ - public function ajaxProcessTogglePayLaterProductPageBanner() - { - $this->setConfiguration(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER, (bool) Tools::getValue('status')); - - $this->ajaxRender(json_encode(true)); - } - /** * AJAX: Toggle pay later button on cart page */ diff --git a/ps9/upgrade/upgrade-9.5.1.1.php b/ps9/upgrade/upgrade-9.5.1.1.php new file mode 100644 index 000000000..54ef469fe --- /dev/null +++ b/ps9/upgrade/upgrade-9.5.1.1.php @@ -0,0 +1,93 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +if (!defined('_PS_VERSION_')) { + exit; +} + +/** + * Update main function for module version 9.5.1.1 + * + * @param Ps_checkout $module + * + * @return bool + */ +function upgrade_module_9_5_1_1(Ps_checkout $module) +{ + try { + $savedShopContext = Shop::getContext(); + $savedShopId = Shop::getContextShopID(); + $savedGroupShopId = Shop::getContextShopGroupID(); + Shop::setContext(Shop::CONTEXT_ALL); + $shopsList = \Shop::getShops(false, null, true); + + foreach ($shopsList as $shopId) { + $configuration = json_encode([ + 'product' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'homepage' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'cart' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'payment' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + 'category' => ['status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled'], + ]); + + Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId); + } + + // Restore initial PrestaShop shop context + if (Shop::CONTEXT_SHOP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedShopId); + } elseif (Shop::CONTEXT_GROUP === $savedShopContext) { + Shop::setContext($savedShopContext, $savedGroupShopId); + } else { + Shop::setContext($savedShopContext); + } + + } catch (Exception $exception) { + PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); + + return false; + } + + return true; +} From 36e78e6eecb96d3f46b68aea4f1f9d9a39e4f180 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Thu, 2 Oct 2025 13:01:57 +0000 Subject: [PATCH 02/15] Apply PHP-CS-Fixer changes --- .../src/Presenter/Settings/Admin/Modules/ContextModule.php | 1 + ps17/upgrade/upgrade-7.5.1.1.php | 1 - ps8/upgrade/upgrade-8.5.1.1.php | 1 - ps9/upgrade/upgrade-9.5.1.1.php | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php b/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php index fac98e63f..7dc09491e 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/ContextModule.php @@ -56,6 +56,7 @@ class ContextModule implements PresenterInterface * @var ConfigurationInterface */ private $configuration; + /** * @var EnvInterface */ diff --git a/ps17/upgrade/upgrade-7.5.1.1.php b/ps17/upgrade/upgrade-7.5.1.1.php index 85f7ce644..05238ea38 100644 --- a/ps17/upgrade/upgrade-7.5.1.1.php +++ b/ps17/upgrade/upgrade-7.5.1.1.php @@ -82,7 +82,6 @@ function upgrade_module_7_5_1_1(Ps_checkout $module) } else { Shop::setContext($savedShopContext); } - } catch (Exception $exception) { PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); diff --git a/ps8/upgrade/upgrade-8.5.1.1.php b/ps8/upgrade/upgrade-8.5.1.1.php index ff0614d65..4fab34fc4 100644 --- a/ps8/upgrade/upgrade-8.5.1.1.php +++ b/ps8/upgrade/upgrade-8.5.1.1.php @@ -82,7 +82,6 @@ function upgrade_module_8_5_1_1(Ps_checkout $module) } else { Shop::setContext($savedShopContext); } - } catch (Exception $exception) { PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); diff --git a/ps9/upgrade/upgrade-9.5.1.1.php b/ps9/upgrade/upgrade-9.5.1.1.php index 54ef469fe..e26bbce1d 100644 --- a/ps9/upgrade/upgrade-9.5.1.1.php +++ b/ps9/upgrade/upgrade-9.5.1.1.php @@ -82,7 +82,6 @@ function upgrade_module_9_5_1_1(Ps_checkout $module) } else { Shop::setContext($savedShopContext); } - } catch (Exception $exception) { PrestaShopLogger::addLog($exception->getMessage(), 4, 1, 'Module', $module->id); From 3bd7ce28f7699ebfcc82db23ef40954d0f607cbb Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 3 Oct 2025 15:03:14 +0300 Subject: [PATCH 03/15] Code review feedback --- .../Configuration/DefaultConfiguration.php | 1 + .../PayPalPayLaterConfiguration.php | 46 +++++++++++++++++++ .../Configuration/PayPalSdkConfiguration.php | 14 ++++-- infrastructure/src/Adapter/Configuration.php | 2 +- .../Validator/FrontControllerValidator.php | 12 +++-- .../Admin/Modules/ConfigurationModule.php | 28 ++++------- .../Front/Modules/ConfigurationModule.php | 10 +++- ps17/config/front/configuration.yml | 1 + ps17/config/front/presenter.yml | 1 + ps17/config/front/validator.yml | 1 + ps17/config/shared/configuration.yml | 5 ++ ps8/config/front/configuration.yml | 1 + ps8/config/front/presenter.yml | 1 + ps8/config/front/validator.yml | 1 + ps8/config/shared/configuration.yml | 5 ++ ps9/config/front/configuration.yml | 2 + ps9/config/front/presenter.yml | 1 + ps9/config/front/validator.yml | 1 + ps9/config/shared/configuration.yml | 5 ++ 19 files changed, 109 insertions(+), 29 deletions(-) diff --git a/core/src/Settings/Configuration/DefaultConfiguration.php b/core/src/Settings/Configuration/DefaultConfiguration.php index 62fdeadda..162a9b059 100644 --- a/core/src/Settings/Configuration/DefaultConfiguration.php +++ b/core/src/Settings/Configuration/DefaultConfiguration.php @@ -47,5 +47,6 @@ class DefaultConfiguration 'PS_CHECKOUT_DISPLAY_LOGO_CART' => '1', 'PS_CHECKOUT_HOSTED_FIELDS_CONTINGENCIES' => 'SCA_WHEN_REQUIRED', 'PS_CHECKOUT_PAYPAL_BUTTON' => '{"shape":"pill","label":"pay","color":"gold"}', + 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"disabled"},"category":{"status":"enabled"},"checkout":{"status":"enabled"},"homepage":{"status":"enabled"},"product":{"status":"enabled"}}', ]; } diff --git a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php index 5b11f4abf..7ec95bbe4 100644 --- a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php +++ b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php @@ -20,8 +20,32 @@ namespace PsCheckout\Core\Settings\Configuration; +use PsCheckout\Infrastructure\Adapter\ConfigurationInterface; + class PayPalPayLaterConfiguration { + /** + * @var ConfigurationInterface + */ + private $configuration; + + public function __construct(ConfigurationInterface $configuration,) + { + $this->configuration = $configuration; + } + + /** @deprecated used only as fallback */ + const PS_CHECKOUT_PAY_LATER_ORDER_PAGE = 'PS_CHECKOUT_PAY_IN_4X_ORDER_PAGE'; + + /** @deprecated used only as fallback */ + const PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE = 'PS_CHECKOUT_PAY_IN_4X_PRODUCT_PAGE'; + + /** @deprecated used only as fallback */ + const PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER'; + + /** @deprecated used only as fallback */ + const PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER = 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER'; + const PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_ORDER_PAGE_BUTTON'; const PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_CART_PAGE_BUTTON'; @@ -29,4 +53,26 @@ class PayPalPayLaterConfiguration const PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON = 'PS_CHECKOUT_PAY_IN_4X_PRODUCT_PAGE_BUTTON'; const PS_CHECKOUT_PAY_LATER_CONFIG = 'PS_CHECKOUT_PAY_LATER_CONFIG'; + + /** + * Returns Pay Later customization, with fallback from old configuration values for banner and message statuses + * + * @return array[] + */ + public function getPayLaterMessagingConfiguration(): array + { + $config = $this->configuration->getDeserializedRaw(self::PS_CHECKOUT_PAY_LATER_CONFIG); + + if (!$config) { + return [ + 'product' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) ? 'enabled': 'disabled'], + 'homepage' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER) ? 'enabled': 'disabled'], + 'category' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER) ? 'enabled': 'disabled'], + 'payment' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], + 'cart' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], + ]; + } + + return $config; + } } diff --git a/core/src/Settings/Configuration/PayPalSdkConfiguration.php b/core/src/Settings/Configuration/PayPalSdkConfiguration.php index 88b49ee7c..65ed6f382 100644 --- a/core/src/Settings/Configuration/PayPalSdkConfiguration.php +++ b/core/src/Settings/Configuration/PayPalSdkConfiguration.php @@ -82,6 +82,11 @@ class PayPalSdkConfiguration */ private $logger; + /** + * @var PayPalPayLaterConfiguration + */ + private $payPalPayLaterConfiguration; + /** * @param ContextInterface $context * @param ConfigurationInterface $configuration @@ -91,6 +96,7 @@ class PayPalSdkConfiguration * @param PayPalCustomerRepositoryInterface $payPalCustomerRepository * @param OAuthServiceInterface $oAuthService * @param LoggerInterface $logger + * @param PayPalPayLaterConfiguration $payPalPayLaterConfiguration */ public function __construct( ContextInterface $context, @@ -100,7 +106,8 @@ public function __construct( FundingSourcePresenterInterface $fundingSourcePresenter, PayPalCustomerRepositoryInterface $payPalCustomerRepository, OAuthServiceInterface $oAuthService, - LoggerInterface $logger + LoggerInterface $logger, + PayPalPayLaterConfiguration $payPalPayLaterConfiguration ) { $this->context = $context; $this->configuration = $configuration; @@ -110,6 +117,7 @@ public function __construct( $this->payPalCustomerRepository = $payPalCustomerRepository; $this->oAuthService = $oAuthService; $this->logger = $logger; + $this->payPalPayLaterConfiguration = $payPalPayLaterConfiguration; } /** @@ -261,9 +269,7 @@ private function shouldIncludeMessagesComponent(): bool { $pageName = $this->getPageName(); - $payLaterMessagingCustomization = $this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG); - - $payLaterMessagingCustomization = json_decode($payLaterMessagingCustomization, true); + $payLaterMessagingCustomization = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); switch ($pageName) { case 'cart': diff --git a/infrastructure/src/Adapter/Configuration.php b/infrastructure/src/Adapter/Configuration.php index d2797c4fb..79cd6ef9b 100644 --- a/infrastructure/src/Adapter/Configuration.php +++ b/infrastructure/src/Adapter/Configuration.php @@ -70,7 +70,7 @@ public function getDeserializedRaw(string $key) return ''; } - return json_decode($configuration); + return json_decode($configuration, true); } /** diff --git a/infrastructure/src/Validator/FrontControllerValidator.php b/infrastructure/src/Validator/FrontControllerValidator.php index e2aff4e9b..c7bc254ba 100644 --- a/infrastructure/src/Validator/FrontControllerValidator.php +++ b/infrastructure/src/Validator/FrontControllerValidator.php @@ -31,11 +31,17 @@ class FrontControllerValidator implements FrontControllerValidatorInterface * @var ConfigurationInterface */ private $configuration; + /** + * @var PayPalPayLaterConfiguration + */ + private $payPalPayLaterConfiguration; public function __construct( - ConfigurationInterface $configuration + ConfigurationInterface $configuration, + PayPalPayLaterConfiguration $payPalPayLaterConfiguration ) { $this->configuration = $configuration; + $this->payPalPayLaterConfiguration = $payPalPayLaterConfiguration; } /** @@ -43,7 +49,7 @@ public function __construct( */ public function shouldLoadFrontCss(string $controller): bool { - $payLaterConfiguration = json_decode($this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG), true); + $payLaterConfiguration = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); switch ($controller) { // Homepage @@ -73,7 +79,7 @@ public function shouldLoadFrontCss(string $controller): bool */ public function shouldLoadFrontJS(string $controller): bool { - $payLaterConfiguration = json_decode($this->configuration->get(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG), true); + $payLaterConfiguration = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); switch ($controller) { // Homepage diff --git a/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php index dcb3ec381..dfd76c5f7 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/ConfigurationModule.php @@ -91,25 +91,15 @@ public function present(): array 'productPage' => $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_PRODUCT_PAGE), ], 'payLater' => [ -// 'orderPage' => [ -// 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE), -// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER), -// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON), -// ], -// 'cartPage' => [ -// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON), -// ], -// 'productPage' => [ -// 'message' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE), -// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BANNER), -// 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON), -// ], -// 'categoryPage' => [ -// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER), -// ], -// 'homePage' => [ -// 'banner' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER), -// ], + 'orderPage' => [ + 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON), + ], + 'cartPage' => [ + 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON), + ], + 'productPage' => [ + 'button' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON), + ], ], 'logger' => [ 'levels' => [ diff --git a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php index 54410e903..b4e04232d 100644 --- a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php @@ -60,6 +60,10 @@ class ConfigurationModule implements PresenterInterface * @var PayPalSdkConfiguration */ private $payPalSdkConfiguration; + /** + * @var PayPalPayLaterConfiguration + */ + private $payLaterConfiguration; /** * @param string $moduleName @@ -74,7 +78,8 @@ public function __construct( ConfigurationInterface $configuration, PayPalConfiguration $payPalConfiguration, FundingSourcePresenterInterface $fundingSourcePresenter, - PayPalSdkConfiguration $payPalSdkConfiguration + PayPalSdkConfiguration $payPalSdkConfiguration, + PayPalPayLaterConfiguration $payLaterConfiguration ) { $this->moduleName = $moduleName; $this->context = $context; @@ -82,6 +87,7 @@ public function __construct( $this->payPalConfiguration = $payPalConfiguration; $this->fundingSourcePresenter = $fundingSourcePresenter; $this->payPalSdkConfiguration = $payPalSdkConfiguration; + $this->payLaterConfiguration = $payLaterConfiguration; } public function present(): array @@ -111,7 +117,7 @@ public function present(): array $this->moduleName . 'PayLaterOrderPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterCartPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterProductPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->configuration->getDeserializedRaw(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CONFIG) : [ + $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->payLaterConfiguration->getPayLaterMessagingConfiguration() : [ 'product' => ['status' => 'disabled'], 'homepage' => ['status' => 'disabled'], 'cart' => ['status' => 'disabled'], diff --git a/ps17/config/front/configuration.yml b/ps17/config/front/configuration.yml index c93866af4..d9d09aef5 100644 --- a/ps17/config/front/configuration.yml +++ b/ps17/config/front/configuration.yml @@ -13,3 +13,4 @@ services: - '@PsCheckout\Infrastructure\Repository\PayPalCustomerRepository' - '@PsCheckout\Core\PayPal\OAuth\OAuthService' - '@Psr\Log\LoggerInterface' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' diff --git a/ps17/config/front/presenter.yml b/ps17/config/front/presenter.yml index a148bddf3..77855bd70 100644 --- a/ps17/config/front/presenter.yml +++ b/ps17/config/front/presenter.yml @@ -39,6 +39,7 @@ services: - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps17/config/front/validator.yml b/ps17/config/front/validator.yml index 179456f47..381a9568f 100644 --- a/ps17/config/front/validator.yml +++ b/ps17/config/front/validator.yml @@ -6,6 +6,7 @@ services: class: PsCheckout\Infrastructure\Validator\FrontControllerValidator arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Core\Order\Validator\OrderAuthorizationValidator: class: PsCheckout\Core\Order\Validator\OrderAuthorizationValidator diff --git a/ps17/config/shared/configuration.yml b/ps17/config/shared/configuration.yml index 08625ca25..8ef8ddb04 100644 --- a/ps17/config/shared/configuration.yml +++ b/ps17/config/shared/configuration.yml @@ -6,3 +6,8 @@ services: class: PsCheckout\Core\Settings\Configuration\PayPalConfiguration arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + + PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: + class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration + arguments: + - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file diff --git a/ps8/config/front/configuration.yml b/ps8/config/front/configuration.yml index c93866af4..d9d09aef5 100644 --- a/ps8/config/front/configuration.yml +++ b/ps8/config/front/configuration.yml @@ -13,3 +13,4 @@ services: - '@PsCheckout\Infrastructure\Repository\PayPalCustomerRepository' - '@PsCheckout\Core\PayPal\OAuth\OAuthService' - '@Psr\Log\LoggerInterface' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' diff --git a/ps8/config/front/presenter.yml b/ps8/config/front/presenter.yml index 31517954d..4280dc8bd 100644 --- a/ps8/config/front/presenter.yml +++ b/ps8/config/front/presenter.yml @@ -40,6 +40,7 @@ services: - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps8/config/front/validator.yml b/ps8/config/front/validator.yml index 179456f47..381a9568f 100644 --- a/ps8/config/front/validator.yml +++ b/ps8/config/front/validator.yml @@ -6,6 +6,7 @@ services: class: PsCheckout\Infrastructure\Validator\FrontControllerValidator arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Core\Order\Validator\OrderAuthorizationValidator: class: PsCheckout\Core\Order\Validator\OrderAuthorizationValidator diff --git a/ps8/config/shared/configuration.yml b/ps8/config/shared/configuration.yml index 08625ca25..8ef8ddb04 100644 --- a/ps8/config/shared/configuration.yml +++ b/ps8/config/shared/configuration.yml @@ -6,3 +6,8 @@ services: class: PsCheckout\Core\Settings\Configuration\PayPalConfiguration arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + + PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: + class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration + arguments: + - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file diff --git a/ps9/config/front/configuration.yml b/ps9/config/front/configuration.yml index c93866af4..523880ae7 100644 --- a/ps9/config/front/configuration.yml +++ b/ps9/config/front/configuration.yml @@ -13,3 +13,5 @@ services: - '@PsCheckout\Infrastructure\Repository\PayPalCustomerRepository' - '@PsCheckout\Core\PayPal\OAuth\OAuthService' - '@Psr\Log\LoggerInterface' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' + diff --git a/ps9/config/front/presenter.yml b/ps9/config/front/presenter.yml index 31517954d..4280dc8bd 100644 --- a/ps9/config/front/presenter.yml +++ b/ps9/config/front/presenter.yml @@ -40,6 +40,7 @@ services: - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps9/config/front/validator.yml b/ps9/config/front/validator.yml index 179456f47..381a9568f 100644 --- a/ps9/config/front/validator.yml +++ b/ps9/config/front/validator.yml @@ -6,6 +6,7 @@ services: class: PsCheckout\Infrastructure\Validator\FrontControllerValidator arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' PsCheckout\Core\Order\Validator\OrderAuthorizationValidator: class: PsCheckout\Core\Order\Validator\OrderAuthorizationValidator diff --git a/ps9/config/shared/configuration.yml b/ps9/config/shared/configuration.yml index 08625ca25..8ef8ddb04 100644 --- a/ps9/config/shared/configuration.yml +++ b/ps9/config/shared/configuration.yml @@ -6,3 +6,8 @@ services: class: PsCheckout\Core\Settings\Configuration\PayPalConfiguration arguments: - '@PsCheckout\Infrastructure\Adapter\Configuration' + + PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: + class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration + arguments: + - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file From 787cd69a0d48b4d702e971865554fe9597c40695 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 3 Oct 2025 12:04:19 +0000 Subject: [PATCH 04/15] Apply PHP-CS-Fixer changes --- infrastructure/src/Validator/FrontControllerValidator.php | 1 + .../src/Presenter/Settings/Front/Modules/ConfigurationModule.php | 1 + 2 files changed, 2 insertions(+) diff --git a/infrastructure/src/Validator/FrontControllerValidator.php b/infrastructure/src/Validator/FrontControllerValidator.php index c7bc254ba..195d90681 100644 --- a/infrastructure/src/Validator/FrontControllerValidator.php +++ b/infrastructure/src/Validator/FrontControllerValidator.php @@ -31,6 +31,7 @@ class FrontControllerValidator implements FrontControllerValidatorInterface * @var ConfigurationInterface */ private $configuration; + /** * @var PayPalPayLaterConfiguration */ diff --git a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php index b4e04232d..00d25e02c 100644 --- a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php @@ -60,6 +60,7 @@ class ConfigurationModule implements PresenterInterface * @var PayPalSdkConfiguration */ private $payPalSdkConfiguration; + /** * @var PayPalPayLaterConfiguration */ From ac8a80c80d901443500d8b8c18f759934b5bdf2d Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 3 Oct 2025 15:21:17 +0300 Subject: [PATCH 05/15] Fixed default config --- core/src/Settings/Configuration/DefaultConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Settings/Configuration/DefaultConfiguration.php b/core/src/Settings/Configuration/DefaultConfiguration.php index 162a9b059..e7303bc17 100644 --- a/core/src/Settings/Configuration/DefaultConfiguration.php +++ b/core/src/Settings/Configuration/DefaultConfiguration.php @@ -47,6 +47,6 @@ class DefaultConfiguration 'PS_CHECKOUT_DISPLAY_LOGO_CART' => '1', 'PS_CHECKOUT_HOSTED_FIELDS_CONTINGENCIES' => 'SCA_WHEN_REQUIRED', 'PS_CHECKOUT_PAYPAL_BUTTON' => '{"shape":"pill","label":"pay","color":"gold"}', - 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"disabled"},"category":{"status":"enabled"},"checkout":{"status":"enabled"},"homepage":{"status":"enabled"},"product":{"status":"enabled"}}', + 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"disabled"},"category":{"status":"disabled"},"checkout":{"status":"disabled"},"homepage":{"status":"disabled"},"product":{"status":"disabled"}}', ]; } From ee9738af70b4fb2054e4e8b04a4ad2f0085d43b9 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Mon, 6 Oct 2025 10:57:35 +0300 Subject: [PATCH 06/15] Removed hardcoded country for debugging --- core/src/Settings/Configuration/PayPalSdkConfiguration.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/Settings/Configuration/PayPalSdkConfiguration.php b/core/src/Settings/Configuration/PayPalSdkConfiguration.php index 65ed6f382..c91c36532 100644 --- a/core/src/Settings/Configuration/PayPalSdkConfiguration.php +++ b/core/src/Settings/Configuration/PayPalSdkConfiguration.php @@ -400,7 +400,6 @@ private function getPageName(): string */ private function getCountryIsoCode(): string { - return 'FR'; $code = ''; if (\Validate::isLoadedObject($this->context->getCountry())) { From a31b8b45fb88adf2dd6ed400234a8d2c6bb097b2 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Wed, 8 Oct 2025 15:23:07 +0300 Subject: [PATCH 07/15] changed the way json config is handled --- .../admin/AdminAjaxPrestashopCheckoutController.php | 6 +++++- .../admin/AdminAjaxPrestashopCheckoutController.php | 2 +- .../admin/AdminAjaxPrestashopCheckoutController.php | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php index 3703a4474..c2158ddd5 100644 --- a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -361,7 +361,11 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + if (is_array($configurationItem['value'])) { + $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); + } else { + $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + } } $this->exitWithResponse([ diff --git a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php index 847707772..3bdf9b28b 100644 --- a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -361,7 +361,7 @@ public function ajaxProcessBatchSaveConfiguration() foreach ($configuration as $configurationItem) { if (is_array($configurationItem['value'])) { - $this->setConfiguration($configurationItem['name'], json_encode($configurationItem['value'])); + $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); } else { $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); } diff --git a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php index dc000bc94..b6119f4a5 100644 --- a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -361,7 +361,11 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + if (is_array($configurationItem['value'])) { + $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); + } else { + $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); + } } $this->exitWithResponse([ From e9e7f415f9faea8f68fb2a88b812f4516a6542e5 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Wed, 15 Oct 2025 15:28:51 +0300 Subject: [PATCH 08/15] Bumped muodle version --- ps17/config.xml | 2 +- .../admin/AdminAjaxPrestashopCheckoutController.php | 6 +----- ps17/ps_checkout.php | 2 +- ps8/config.xml | 2 +- .../admin/AdminAjaxPrestashopCheckoutController.php | 6 +----- ps8/ps_checkout.php | 2 +- ps9/config.xml | 2 +- .../admin/AdminAjaxPrestashopCheckoutController.php | 6 +----- ps9/ps_checkout.php | 2 +- 9 files changed, 9 insertions(+), 21 deletions(-) diff --git a/ps17/config.xml b/ps17/config.xml index e4e2e7c1c..55d13ec03 100644 --- a/ps17/config.xml +++ b/ps17/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php index c2158ddd5..76cabe763 100644 --- a/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps17/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -361,11 +361,7 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - if (is_array($configurationItem['value'])) { - $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); - } else { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); - } + $configurationService->set(pSQL($configurationItem['name']), $configurationItem['value']); } $this->exitWithResponse([ diff --git a/ps17/ps_checkout.php b/ps17/ps_checkout.php index 10c9e6f7d..6b50ae697 100644 --- a/ps17/ps_checkout.php +++ b/ps17/ps_checkout.php @@ -108,7 +108,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '7.5.0.4'; + $this->version = '7.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); diff --git a/ps8/config.xml b/ps8/config.xml index b14f7d9d5..149f0dd05 100644 --- a/ps8/config.xml +++ b/ps8/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php index 3bdf9b28b..8790cd559 100644 --- a/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps8/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -360,11 +360,7 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - if (is_array($configurationItem['value'])) { - $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); - } else { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); - } + $configurationService->set(pSQL($configurationItem['name']), $configurationItem['value']); } $this->exitWithResponse([ diff --git a/ps8/ps_checkout.php b/ps8/ps_checkout.php index 7839fbb4b..f1d13c41f 100644 --- a/ps8/ps_checkout.php +++ b/ps8/ps_checkout.php @@ -107,7 +107,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '8.5.0.4'; + $this->version = '8.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); diff --git a/ps9/config.xml b/ps9/config.xml index 0a03b828a..fde773e63 100644 --- a/ps9/config.xml +++ b/ps9/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php index b6119f4a5..b11f3dd3d 100644 --- a/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/ps9/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -361,11 +361,7 @@ public function ajaxProcessBatchSaveConfiguration() $this->validateBatchConfiguration($configuration); foreach ($configuration as $configurationItem) { - if (is_array($configurationItem['value'])) { - $configurationService->set($configurationItem['name'], json_encode($configurationItem['value'])); - } else { - $configurationService->set(pSQL($configurationItem['name']), pSQL($configurationItem['value'])); - } + $configurationService->set(pSQL($configurationItem['name']), $configurationItem['value']); } $this->exitWithResponse([ diff --git a/ps9/ps_checkout.php b/ps9/ps_checkout.php index 3c4b1c6f4..3d3143f9f 100644 --- a/ps9/ps_checkout.php +++ b/ps9/ps_checkout.php @@ -107,7 +107,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '9.5.0.4'; + $this->version = '9.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); From 97cb79f67f096fba995512b477dcdc60f8d62f82 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:46:32 +0200 Subject: [PATCH 09/15] Bump module version --- ps17/config.xml | 2 +- ps17/ps_checkout.php | 2 +- ps17/upgrade/{upgrade-7.5.1.1.php => upgrade-7.5.1.0.php} | 4 ++-- ps8/config.xml | 2 +- ps8/ps_checkout.php | 2 +- ps8/upgrade/{upgrade-8.5.1.1.php => upgrade-8.5.1.0.php} | 4 ++-- ps9/config.xml | 2 +- ps9/ps_checkout.php | 2 +- ps9/upgrade/{upgrade-9.5.1.1.php => upgrade-9.5.1.0.php} | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) rename ps17/upgrade/{upgrade-7.5.1.1.php => upgrade-7.5.1.0.php} (96%) rename ps8/upgrade/{upgrade-8.5.1.1.php => upgrade-8.5.1.0.php} (96%) rename ps9/upgrade/{upgrade-9.5.1.1.php => upgrade-9.5.1.0.php} (96%) diff --git a/ps17/config.xml b/ps17/config.xml index 9ee92c0e1..55d13ec03 100644 --- a/ps17/config.xml +++ b/ps17/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps17/ps_checkout.php b/ps17/ps_checkout.php index 31eb4f75e..6b50ae697 100644 --- a/ps17/ps_checkout.php +++ b/ps17/ps_checkout.php @@ -108,7 +108,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '7.5.0.5'; + $this->version = '7.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); diff --git a/ps17/upgrade/upgrade-7.5.1.1.php b/ps17/upgrade/upgrade-7.5.1.0.php similarity index 96% rename from ps17/upgrade/upgrade-7.5.1.1.php rename to ps17/upgrade/upgrade-7.5.1.0.php index 05238ea38..914e4b2f5 100644 --- a/ps17/upgrade/upgrade-7.5.1.1.php +++ b/ps17/upgrade/upgrade-7.5.1.0.php @@ -22,13 +22,13 @@ } /** - * Update main function for module version 7.5.1.1 + * Update main function for module version 7.5.1.0 * * @param Ps_checkout $module * * @return bool */ -function upgrade_module_7_5_1_1(Ps_checkout $module) +function upgrade_module_7_5_1_0(Ps_checkout $module) { try { $savedShopContext = Shop::getContext(); diff --git a/ps8/config.xml b/ps8/config.xml index ad88b1fdd..149f0dd05 100644 --- a/ps8/config.xml +++ b/ps8/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps8/ps_checkout.php b/ps8/ps_checkout.php index 60fa38ed1..f1d13c41f 100644 --- a/ps8/ps_checkout.php +++ b/ps8/ps_checkout.php @@ -107,7 +107,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '8.5.0.5'; + $this->version = '8.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); diff --git a/ps8/upgrade/upgrade-8.5.1.1.php b/ps8/upgrade/upgrade-8.5.1.0.php similarity index 96% rename from ps8/upgrade/upgrade-8.5.1.1.php rename to ps8/upgrade/upgrade-8.5.1.0.php index 4fab34fc4..29fa18a70 100644 --- a/ps8/upgrade/upgrade-8.5.1.1.php +++ b/ps8/upgrade/upgrade-8.5.1.0.php @@ -22,13 +22,13 @@ } /** - * Update main function for module version 8.5.1.1 + * Update main function for module version 8.5.1.0 * * @param Ps_checkout $module * * @return bool */ -function upgrade_module_8_5_1_1(Ps_checkout $module) +function upgrade_module_8_5_1_0(Ps_checkout $module) { try { $savedShopContext = Shop::getContext(); diff --git a/ps9/config.xml b/ps9/config.xml index ed1714bfe..fde773e63 100644 --- a/ps9/config.xml +++ b/ps9/config.xml @@ -2,7 +2,7 @@ ps_checkout - + diff --git a/ps9/ps_checkout.php b/ps9/ps_checkout.php index 0b00d585f..3d3143f9f 100644 --- a/ps9/ps_checkout.php +++ b/ps9/ps_checkout.php @@ -107,7 +107,7 @@ public function __construct() { $this->name = 'ps_checkout'; $this->tab = 'payments_gateways'; - $this->version = '9.5.0.5'; + $this->version = '9.5.1.0'; $this->author = 'PrestaShop'; parent::__construct(); diff --git a/ps9/upgrade/upgrade-9.5.1.1.php b/ps9/upgrade/upgrade-9.5.1.0.php similarity index 96% rename from ps9/upgrade/upgrade-9.5.1.1.php rename to ps9/upgrade/upgrade-9.5.1.0.php index e26bbce1d..536d4638b 100644 --- a/ps9/upgrade/upgrade-9.5.1.1.php +++ b/ps9/upgrade/upgrade-9.5.1.0.php @@ -22,13 +22,13 @@ } /** - * Update main function for module version 9.5.1.1 + * Update main function for module version 9.5.1.0 * * @param Ps_checkout $module * * @return bool */ -function upgrade_module_9_5_1_1(Ps_checkout $module) +function upgrade_module_9_5_1_0(Ps_checkout $module) { try { $savedShopContext = Shop::getContext(); From 87d24b583839d40de7e9fb4386f4ea2d7467ec31 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Tue, 21 Oct 2025 09:47:50 +0200 Subject: [PATCH 10/15] Remove useless import --- .../src/Presenter/Settings/Admin/Modules/PaypalModule.php | 1 - 1 file changed, 1 deletion(-) diff --git a/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php b/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php index d3b4d3dff..c78002a3f 100644 --- a/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php +++ b/presentation/src/Presenter/Settings/Admin/Modules/PaypalModule.php @@ -22,7 +22,6 @@ use PsCheckout\Core\Settings\Configuration\PayPalConfiguration; use PsCheckout\Infrastructure\Adapter\ConfigurationInterface; -use PsCheckout\Infrastructure\Environment\EnvInterface; use PsCheckout\Presentation\Presenter\PresenterInterface; /** From e556d08e323fe31e6f5cadd8daa2f992667a7317 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Tue, 21 Oct 2025 10:22:05 +0200 Subject: [PATCH 11/15] Improve the PayPalPayLaterConfiguration --- .../PayPalPayLaterConfiguration.php | 77 ++++++++++++++----- .../Configuration/PayPalSdkConfiguration.php | 8 +- infrastructure/src/Adapter/Configuration.php | 2 +- .../Validator/FrontControllerValidator.php | 16 ++-- .../Front/Modules/ConfigurationModule.php | 8 +- ps17/config/shared/configuration.yml | 2 +- ps8/config/shared/configuration.yml | 2 +- ps9/config/shared/configuration.yml | 2 +- 8 files changed, 70 insertions(+), 47 deletions(-) diff --git a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php index 7ec95bbe4..b3db8c816 100644 --- a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php +++ b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php @@ -24,16 +24,6 @@ class PayPalPayLaterConfiguration { - /** - * @var ConfigurationInterface - */ - private $configuration; - - public function __construct(ConfigurationInterface $configuration,) - { - $this->configuration = $configuration; - } - /** @deprecated used only as fallback */ const PS_CHECKOUT_PAY_LATER_ORDER_PAGE = 'PS_CHECKOUT_PAY_IN_4X_ORDER_PAGE'; @@ -54,6 +44,22 @@ public function __construct(ConfigurationInterface $configuration,) const PS_CHECKOUT_PAY_LATER_CONFIG = 'PS_CHECKOUT_PAY_LATER_CONFIG'; + /** + * @var ConfigurationInterface + */ + private $configuration; + + /** + * @var array|null + */ + private $config; + + public function __construct(ConfigurationInterface $configuration) + { + $this->configuration = $configuration; + $this->config = $this->configuration->getDeserializedRaw(self::PS_CHECKOUT_PAY_LATER_CONFIG); + } + /** * Returns Pay Later customization, with fallback from old configuration values for banner and message statuses * @@ -61,18 +67,47 @@ public function __construct(ConfigurationInterface $configuration,) */ public function getPayLaterMessagingConfiguration(): array { - $config = $this->configuration->getDeserializedRaw(self::PS_CHECKOUT_PAY_LATER_CONFIG); - - if (!$config) { - return [ - 'product' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) ? 'enabled': 'disabled'], - 'homepage' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER) ? 'enabled': 'disabled'], - 'category' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER) ? 'enabled': 'disabled'], - 'payment' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], - 'cart' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], - ]; + if (!$this->config) { + return $this->getPayLaterMessagingConfigurationLegacy(); } - return $config; + return $this->config; + } + + /** + * Returns the default Pay Later configuration + * + * @return array[] + */ + public function getPayLaterMessagingConfigurationDefault(): array + { + return [ + 'product' => ['status' => 'disabled'], + 'homepage' => ['status' => 'disabled'], + 'category' => ['status' => 'disabled'], + 'payment' => ['status' => 'disabled'], + 'cart' => ['status' => 'disabled'], + ]; + } + + public function isPayLaterMessagingEnabled($page): bool + { + return isset($this->config[$page]) && $this->config[$page]['status'] === 'enabled'; + } + + /** + * Returns Pay Later customization from legacy configuration values + * + * @return array[] + */ + private function getPayLaterMessagingConfigurationLegacy(): array + { + return [ + 'product' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) ? 'enabled': 'disabled'], + 'homepage' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER) ? 'enabled': 'disabled'], + 'category' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER) ? 'enabled': 'disabled'], + 'payment' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], + 'cart' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], + ]; } } diff --git a/core/src/Settings/Configuration/PayPalSdkConfiguration.php b/core/src/Settings/Configuration/PayPalSdkConfiguration.php index c91c36532..187b18d3c 100644 --- a/core/src/Settings/Configuration/PayPalSdkConfiguration.php +++ b/core/src/Settings/Configuration/PayPalSdkConfiguration.php @@ -269,17 +269,15 @@ private function shouldIncludeMessagesComponent(): bool { $pageName = $this->getPageName(); - $payLaterMessagingCustomization = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); - switch ($pageName) { case 'cart': case 'category': case 'product': - return $payLaterMessagingCustomization[$pageName]['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled($pageName); case 'order': - return $payLaterMessagingCustomization['checkout']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('checkout'); case 'index': - return $payLaterMessagingCustomization['homepage']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('homepage'); default: return false; } diff --git a/infrastructure/src/Adapter/Configuration.php b/infrastructure/src/Adapter/Configuration.php index 79cd6ef9b..6d16e8ad2 100644 --- a/infrastructure/src/Adapter/Configuration.php +++ b/infrastructure/src/Adapter/Configuration.php @@ -67,7 +67,7 @@ public function getDeserializedRaw(string $key) $configuration = $this->get($key); if (!$configuration) { - return ''; + return []; } return json_decode($configuration, true); diff --git a/infrastructure/src/Validator/FrontControllerValidator.php b/infrastructure/src/Validator/FrontControllerValidator.php index 7c4355019..225f87b41 100644 --- a/infrastructure/src/Validator/FrontControllerValidator.php +++ b/infrastructure/src/Validator/FrontControllerValidator.php @@ -50,15 +50,13 @@ public function __construct( */ public function shouldLoadFrontCss(string $controller): bool { - $payLaterConfiguration = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); - switch ($controller) { // Homepage case 'index': - return $payLaterConfiguration['homepage']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('homepage'); // Category case 'category': - return $payLaterConfiguration['category']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('category'); // Payment step case 'orderopc': case 'order': @@ -80,26 +78,24 @@ public function shouldLoadFrontCss(string $controller): bool */ public function shouldLoadFrontJS(string $controller): bool { - $payLaterConfiguration = $this->payPalPayLaterConfiguration->getPayLaterMessagingConfiguration(); - switch ($controller) { // Homepage case 'index': - return $payLaterConfiguration['homepage']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('homepage'); // Category case 'category': - return $payLaterConfiguration['category']['status'] === 'enabled'; + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('category'); case 'orderopc': case 'order': return true; case 'product': return - $payLaterConfiguration['product']['status'] === 'enabled' + $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('product') || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) || $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_PRODUCT_PAGE) || $this->configuration->getBoolean(PayPalConfiguration::PS_CHECKOUT_DISPLAY_LOGO_PRODUCT); case 'cart': - return $payLaterConfiguration['cart']['status'] === 'enabled' + return $this->payPalPayLaterConfiguration->isPayLaterMessagingEnabled('cart') || $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) || $this->configuration->getBoolean(PayPalExpressCheckoutConfiguration::PS_CHECKOUT_EC_ORDER_PAGE) || $this->configuration->getBoolean(PayPalConfiguration::PS_CHECKOUT_DISPLAY_LOGO_CART); diff --git a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php index 00d25e02c..b107758b0 100644 --- a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php @@ -118,13 +118,7 @@ public function present(): array $this->moduleName . 'PayLaterOrderPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterCartPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterProductPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->payLaterConfiguration->getPayLaterMessagingConfiguration() : [ - 'product' => ['status' => 'disabled'], - 'homepage' => ['status' => 'disabled'], - 'cart' => ['status' => 'disabled'], - 'payment' => ['status' => 'disabled'], - 'category' => ['status' => 'disabled'], - ], + $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->payLaterConfiguration->getPayLaterMessagingConfiguration() : $this->payLaterConfiguration->getPayLaterMessagingConfigurationDefault(), ]; } } diff --git a/ps17/config/shared/configuration.yml b/ps17/config/shared/configuration.yml index 8ef8ddb04..222b6438a 100644 --- a/ps17/config/shared/configuration.yml +++ b/ps17/config/shared/configuration.yml @@ -10,4 +10,4 @@ services: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration arguments: - - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file + - '@PsCheckout\Infrastructure\Adapter\Configuration' diff --git a/ps8/config/shared/configuration.yml b/ps8/config/shared/configuration.yml index 8ef8ddb04..222b6438a 100644 --- a/ps8/config/shared/configuration.yml +++ b/ps8/config/shared/configuration.yml @@ -10,4 +10,4 @@ services: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration arguments: - - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file + - '@PsCheckout\Infrastructure\Adapter\Configuration' diff --git a/ps9/config/shared/configuration.yml b/ps9/config/shared/configuration.yml index 8ef8ddb04..222b6438a 100644 --- a/ps9/config/shared/configuration.yml +++ b/ps9/config/shared/configuration.yml @@ -10,4 +10,4 @@ services: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration: class: PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration arguments: - - '@PsCheckout\Infrastructure\Adapter\Configuration' \ No newline at end of file + - '@PsCheckout\Infrastructure\Adapter\Configuration' From 41594eb7d3ff14b57a3905580f6d450d7008e597 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Thu, 23 Oct 2025 18:05:34 +0300 Subject: [PATCH 12/15] Added validation for merchant country/locale/currency --- .../Constraint/FundingSourceConstraint.php | 3 +- .../Configuration/PayPalConfiguration.php | 11 + .../src/Validator/PayLaterValidator.php | 62 ++++ .../Validator/PayLaterValidatorInterface.php | 29 ++ .../Unit/Validator/PayLaterValidatorTest.php | 270 ++++++++++++++++++ .../Front/Modules/ConfigurationModule.php | 19 +- ps17/config/front/presenter.yml | 1 + ps17/config/shared/validator.yml | 8 +- ps8/config/front/presenter.yml | 1 + ps8/config/shared/validator.yml | 8 +- ps9/config/front/presenter.yml | 1 + ps9/config/shared/validator.yml | 8 +- 12 files changed, 415 insertions(+), 6 deletions(-) create mode 100644 infrastructure/src/Validator/PayLaterValidator.php create mode 100644 infrastructure/src/Validator/PayLaterValidatorInterface.php create mode 100644 infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php diff --git a/core/src/FundingSource/Constraint/FundingSourceConstraint.php b/core/src/FundingSource/Constraint/FundingSourceConstraint.php index 05ca2e0e5..1cf46e97d 100644 --- a/core/src/FundingSource/Constraint/FundingSourceConstraint.php +++ b/core/src/FundingSource/Constraint/FundingSourceConstraint.php @@ -38,7 +38,7 @@ public static function getCountries(string $fundingSourceName): array 'ideal' => ['NL'], 'mybank' => ['IT'], 'p24' => ['PL'], - 'paylater' => ['FR', 'GB', 'US', 'ES', 'IT'], + 'paylater' => ['AU', 'DE', 'ES', 'FR', 'GB', 'IT', 'US'], 'google_pay' => ['AU', 'AT', 'BE', 'BG', 'CA', 'CN', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MK', 'MT', 'NL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'US'], 'apple_pay' => ['AU', 'AT', 'BE', 'BG', 'CA', 'CN', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MT', 'NL', 'NO', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'US'], ]; @@ -58,6 +58,7 @@ public static function getCurrencies(string $fundingSourceName): array $currencies = [ 'google_pay' => ['AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'], 'apple_pay' => ['AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'], + 'paylater' => ['EUR', 'USD', 'AUD', 'GBP'], ]; return isset($currencies[$fundingSourceName]) ? $currencies[$fundingSourceName] : []; diff --git a/core/src/Settings/Configuration/PayPalConfiguration.php b/core/src/Settings/Configuration/PayPalConfiguration.php index 9cdcc54c0..afd125199 100644 --- a/core/src/Settings/Configuration/PayPalConfiguration.php +++ b/core/src/Settings/Configuration/PayPalConfiguration.php @@ -74,6 +74,9 @@ class PayPalConfiguration const PS_CHECKOUT_DOMAIN_REGISTERED_LIVE = 'PS_CHECKOUT_DOMAIN_REGISTERED_LIVE'; + const PS_CHECKOUT_PAYPAL_COUNTRY_MERCHANT = 'PS_CHECKOUT_PAYPAL_COUNTRY_MERCHANT'; + + // NOT CONFIGURATION const PS_CHECKOUT_CUSTOMER_INTENT_VAULT = 'VAULT'; const PS_CHECKOUT_CUSTOMER_INTENT_FAVORITE = 'FAVORITE'; @@ -116,4 +119,12 @@ public function is3dSecureEnabled(): bool { return $this->getCardFieldsContingencies() !== 'NONE'; } + + /** + * @return string + */ + public function getMerchantCountry(): string + { + return $this->configuration->get(self::PS_CHECKOUT_PAYPAL_COUNTRY_MERCHANT); + } } diff --git a/infrastructure/src/Validator/PayLaterValidator.php b/infrastructure/src/Validator/PayLaterValidator.php new file mode 100644 index 000000000..61ddc4243 --- /dev/null +++ b/infrastructure/src/Validator/PayLaterValidator.php @@ -0,0 +1,62 @@ +context = $context; + $this->payPalConfiguration = $payPalConfiguration; + } + + public function isPayLaterAvailable(): bool + { + $merchantCountry = $this->payPalConfiguration->getMerchantCountry(); + $countries = FundingSourceConstraint::getCountries('paylater'); + $currency = $this->context->getCurrency()->iso_code; + $locale = $this->context->getLanguage()->locale; + $customerCountry = $this->context->getCountry()->iso_code; + + // Define supported country-currency combinations for Pay Later messaging + $supportedCountryCurrencyMap = [ + 'AU' => 'AUD', // Australia + 'FR' => 'EUR', // France + 'DE' => 'EUR', // Germany + 'IT' => 'EUR', // Italy + 'ES' => 'EUR', // Spain + 'GB' => 'GBP', // United Kingdom + 'US' => 'USD', // United States + ]; + + // Define locale to country mapping for website locale validation + $localeCountryMap = [ + 'en-AU' => 'AU', // Australia + 'fr-FR' => 'FR', // France + 'de-DE' => 'DE', // Germany + 'it-IT' => 'IT', // Italy + 'es-ES' => 'ES', // Spain + 'en-GB' => 'GB', // United Kingdom + 'en-US' => 'US', // United States + ]; + + return in_array($merchantCountry, $countries, true) + && $merchantCountry === $customerCountry + && isset($supportedCountryCurrencyMap[$customerCountry]) + && $supportedCountryCurrencyMap[$customerCountry] === $currency + && isset($localeCountryMap[$locale]) + && $localeCountryMap[$locale] === $merchantCountry; + } +} \ No newline at end of file diff --git a/infrastructure/src/Validator/PayLaterValidatorInterface.php b/infrastructure/src/Validator/PayLaterValidatorInterface.php new file mode 100644 index 000000000..3db45dd16 --- /dev/null +++ b/infrastructure/src/Validator/PayLaterValidatorInterface.php @@ -0,0 +1,29 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +namespace PsCheckout\Infrastructure\Validator; + +interface PayLaterValidatorInterface +{ + /** + * @return bool + */ + public function isPayLaterAvailable(): bool; +} diff --git a/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php b/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php new file mode 100644 index 000000000..51be0bf7f --- /dev/null +++ b/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php @@ -0,0 +1,270 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +namespace Tests\Unit\PsCheckout\Infrastructure\Validator; + +use PHPUnit\Framework\TestCase; +use PsCheckout\Core\Settings\Configuration\PayPalConfiguration; +use PsCheckout\Infrastructure\Adapter\Context; +use PsCheckout\Infrastructure\Validator\PayLaterValidator; + +class PayLaterValidatorTest extends TestCase +{ + private $contextMock; + private $payPalConfigurationMock; + private $payLaterValidator; + + protected function setUp(): void + { + $this->contextMock = $this->createMock(Context::class); + $this->payPalConfigurationMock = $this->createMock(PayPalConfiguration::class); + $this->payLaterValidator = new PayLaterValidator($this->contextMock, $this->payPalConfigurationMock); + } + + /** + * @dataProvider validPayLaterScenariosProvider + */ + public function testIsPayLaterAvailableReturnsTrueForValidScenarios( + string $merchantCountry, + string $customerCountry, + string $currency, + string $locale + ): void { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn($merchantCountry); + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = $currency; + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = $locale; + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = $customerCountry; + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertTrue($this->payLaterValidator->isPayLaterAvailable()); + } + + /** + * @dataProvider invalidPayLaterScenariosProvider + */ + public function testIsPayLaterAvailableReturnsFalseForInvalidScenarios( + string $merchantCountry, + string $customerCountry, + string $currency, + string $locale + ): void { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn($merchantCountry); + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = $currency; + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = $locale; + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = $customerCountry; + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertFalse($this->payLaterValidator->isPayLaterAvailable()); + } + + public function testIsPayLaterAvailableReturnsFalseForUnsupportedMerchantCountry(): void + { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn('CA'); // Canada is not supported + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = 'CAD'; + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = 'en-CA'; + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = 'CA'; + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertFalse($this->payLaterValidator->isPayLaterAvailable()); + } + + public function testIsPayLaterAvailableReturnsFalseForMismatchedMerchantAndCustomerCountry(): void + { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn('US'); // US merchant + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = 'USD'; + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = 'en-US'; + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = 'CA'; // Canadian customer + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertFalse($this->payLaterValidator->isPayLaterAvailable()); + } + + public function testIsPayLaterAvailableReturnsFalseForWrongCurrency(): void + { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn('US'); + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = 'EUR'; // Wrong currency for US + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = 'en-US'; + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = 'US'; + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertFalse($this->payLaterValidator->isPayLaterAvailable()); + } + + public function testIsPayLaterAvailableReturnsFalseForUnsupportedLocale(): void + { + $this->payPalConfigurationMock + ->method('getMerchantCountry') + ->willReturn('US'); + + $currencyMock = $this->createMock(\stdClass::class); + $currencyMock->iso_code = 'USD'; + + $languageMock = $this->createMock(\stdClass::class); + $languageMock->locale = 'fr-FR'; // French locale for US merchant + + $countryMock = $this->createMock(\stdClass::class); + $countryMock->iso_code = 'US'; + + $this->contextMock + ->method('getCurrency') + ->willReturn($currencyMock); + + $this->contextMock + ->method('getLanguage') + ->willReturn($languageMock); + + $this->contextMock + ->method('getCountry') + ->willReturn($countryMock); + + $this->assertFalse($this->payLaterValidator->isPayLaterAvailable()); + } + + public function validPayLaterScenariosProvider(): array + { + return [ + 'Australia scenario' => ['AU', 'AU', 'AUD', 'en-AU'], + 'France scenario' => ['FR', 'FR', 'EUR', 'fr-FR'], + 'Germany scenario' => ['DE', 'DE', 'EUR', 'de-DE'], + 'Italy scenario' => ['IT', 'IT', 'EUR', 'it-IT'], + 'Spain scenario' => ['ES', 'ES', 'EUR', 'es-ES'], + 'United Kingdom scenario' => ['GB', 'GB', 'GBP', 'en-GB'], + 'United States scenario' => ['US', 'US', 'USD', 'en-US'], + ]; + } + + public function invalidPayLaterScenariosProvider(): array + { + return [ + 'Wrong currency for Australia' => ['AU', 'AU', 'USD', 'en-AU'], + 'Wrong currency for France' => ['FR', 'FR', 'USD', 'fr-FR'], + 'Wrong currency for Germany' => ['DE', 'DE', 'GBP', 'de-DE'], + 'Wrong currency for Italy' => ['IT', 'IT', 'AUD', 'it-IT'], + 'Wrong currency for Spain' => ['ES', 'ES', 'GBP', 'es-ES'], + 'Wrong currency for UK' => ['GB', 'GB', 'EUR', 'en-GB'], + 'Wrong currency for US' => ['US', 'US', 'EUR', 'en-US'], + 'Wrong locale for Australia' => ['AU', 'AU', 'AUD', 'fr-FR'], + 'Wrong locale for France' => ['FR', 'FR', 'EUR', 'en-US'], + 'Wrong locale for Germany' => ['DE', 'DE', 'EUR', 'it-IT'], + 'Wrong locale for Italy' => ['IT', 'IT', 'EUR', 'es-ES'], + 'Wrong locale for Spain' => ['ES', 'ES', 'EUR', 'de-DE'], + 'Wrong locale for UK' => ['GB', 'GB', 'GBP', 'fr-FR'], + 'Wrong locale for US' => ['US', 'US', 'USD', 'de-DE'], + 'Unsupported merchant country' => ['CA', 'CA', 'CAD', 'en-CA'], + 'Unsupported customer country' => ['US', 'CA', 'USD', 'en-US'], + ]; + } +} diff --git a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php index b107758b0..d2affab7f 100644 --- a/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php +++ b/presentation/src/Presenter/Settings/Front/Modules/ConfigurationModule.php @@ -20,12 +20,14 @@ namespace PsCheckout\Presentation\Presenter\Settings\Front\Modules; +use PsCheckout\Core\FundingSource\Constraint\FundingSourceConstraint; use PsCheckout\Core\Settings\Configuration\PayPalConfiguration; use PsCheckout\Core\Settings\Configuration\PayPalExpressCheckoutConfiguration; use PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration; use PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration; use PsCheckout\Infrastructure\Adapter\ConfigurationInterface; use PsCheckout\Infrastructure\Adapter\ContextInterface; +use PsCheckout\Infrastructure\Validator\PayLaterValidatorInterface; use PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenterInterface; use PsCheckout\Presentation\Presenter\PresenterInterface; @@ -66,12 +68,20 @@ class ConfigurationModule implements PresenterInterface */ private $payLaterConfiguration; + /** + * @var PayLaterValidatorInterface + */ + private $payLaterValidator; + /** * @param string $moduleName * @param ContextInterface $context * @param ConfigurationInterface $configuration * @param PayPalConfiguration $payPalConfiguration * @param FundingSourcePresenterInterface $fundingSourcePresenter + * @param PayPalSdkConfiguration $payPalSdkConfiguration + * @param PayPalPayLaterConfiguration $payLaterConfiguration + * @param PayLaterValidatorInterface $payLaterValidator */ public function __construct( string $moduleName, @@ -80,7 +90,8 @@ public function __construct( PayPalConfiguration $payPalConfiguration, FundingSourcePresenterInterface $fundingSourcePresenter, PayPalSdkConfiguration $payPalSdkConfiguration, - PayPalPayLaterConfiguration $payLaterConfiguration + PayPalPayLaterConfiguration $payLaterConfiguration, + PayLaterValidatorInterface $payLaterValidator ) { $this->moduleName = $moduleName; $this->context = $context; @@ -89,6 +100,7 @@ public function __construct( $this->fundingSourcePresenter = $fundingSourcePresenter; $this->payPalSdkConfiguration = $payPalSdkConfiguration; $this->payLaterConfiguration = $payLaterConfiguration; + $this->payLaterValidator = $payLaterValidator; } public function present(): array @@ -104,6 +116,7 @@ public function present(): array } $isPayPalPaymentsReceivable = $this->configuration->getBoolean(PayPalConfiguration::PS_CHECKOUT_PAYPAL_PAYMENT_STATUS); + $isPayLaterAvailable = $this->payLaterValidator->isPayLaterAvailable(); return [ $this->moduleName . 'PayPalSdkConfig' => $this->payPalSdkConfiguration->buildConfiguration(), @@ -118,7 +131,9 @@ public function present(): array $this->moduleName . 'PayLaterOrderPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterCartPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_CART_PAGE_BUTTON) && $isPayPalPaymentsReceivable, $this->moduleName . 'PayLaterProductPageButtonEnabled' => $this->configuration->getBoolean(PayPalPayLaterConfiguration::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE_BUTTON) && $isPayPalPaymentsReceivable, - $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable ? $this->payLaterConfiguration->getPayLaterMessagingConfiguration() : $this->payLaterConfiguration->getPayLaterMessagingConfigurationDefault(), + $this->moduleName . 'PayLaterMessagingConfig' => $isPayPalPaymentsReceivable && $isPayLaterAvailable + ? $this->payLaterConfiguration->getPayLaterMessagingConfiguration() + : $this->payLaterConfiguration->getPayLaterMessagingConfigurationDefault(), ]; } } diff --git a/ps17/config/front/presenter.yml b/ps17/config/front/presenter.yml index aab11e37a..3c40a1d93 100644 --- a/ps17/config/front/presenter.yml +++ b/ps17/config/front/presenter.yml @@ -40,6 +40,7 @@ services: - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' + - '@PsCheckout\Infrastructure\Validator\PayLaterValidator' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps17/config/shared/validator.yml b/ps17/config/shared/validator.yml index b12ad128e..d7e5153bd 100644 --- a/ps17/config/shared/validator.yml +++ b/ps17/config/shared/validator.yml @@ -9,4 +9,10 @@ services: - '@PsCheckout\Infrastructure\Repository\PsAccountRepository' PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator: - class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator \ No newline at end of file + class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator + + PsCheckout\Infrastructure\Validator\PayLaterValidator: + class: PsCheckout\Infrastructure\Validator\PayLaterValidator + arguments: + - '@PsCheckout\Infrastructure\Adapter\Context' + - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' \ No newline at end of file diff --git a/ps8/config/front/presenter.yml b/ps8/config/front/presenter.yml index 00fc621b8..0b8e48765 100644 --- a/ps8/config/front/presenter.yml +++ b/ps8/config/front/presenter.yml @@ -41,6 +41,7 @@ services: - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' + - '@PsCheckout\Infrastructure\Validator\PayLaterValidator' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps8/config/shared/validator.yml b/ps8/config/shared/validator.yml index b12ad128e..d7e5153bd 100644 --- a/ps8/config/shared/validator.yml +++ b/ps8/config/shared/validator.yml @@ -9,4 +9,10 @@ services: - '@PsCheckout\Infrastructure\Repository\PsAccountRepository' PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator: - class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator \ No newline at end of file + class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator + + PsCheckout\Infrastructure\Validator\PayLaterValidator: + class: PsCheckout\Infrastructure\Validator\PayLaterValidator + arguments: + - '@PsCheckout\Infrastructure\Adapter\Context' + - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' \ No newline at end of file diff --git a/ps9/config/front/presenter.yml b/ps9/config/front/presenter.yml index 00fc621b8..0b8e48765 100644 --- a/ps9/config/front/presenter.yml +++ b/ps9/config/front/presenter.yml @@ -41,6 +41,7 @@ services: - '@PsCheckout\Presentation\Presenter\FundingSource\FundingSourcePresenter' - '@PsCheckout\Core\Settings\Configuration\PayPalSdkConfiguration' - '@PsCheckout\Core\Settings\Configuration\PayPalPayLaterConfiguration' + - '@PsCheckout\Infrastructure\Validator\PayLaterValidator' PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule: class: PsCheckout\Presentation\Presenter\Settings\Front\Modules\MediaModule diff --git a/ps9/config/shared/validator.yml b/ps9/config/shared/validator.yml index b12ad128e..d7e5153bd 100644 --- a/ps9/config/shared/validator.yml +++ b/ps9/config/shared/validator.yml @@ -9,4 +9,10 @@ services: - '@PsCheckout\Infrastructure\Repository\PsAccountRepository' PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator: - class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator \ No newline at end of file + class: PsCheckout\Core\PayPal\Card3DSecure\Card3DSecureValidator + + PsCheckout\Infrastructure\Validator\PayLaterValidator: + class: PsCheckout\Infrastructure\Validator\PayLaterValidator + arguments: + - '@PsCheckout\Infrastructure\Adapter\Context' + - '@PsCheckout\Core\Settings\Configuration\PayPalConfiguration' \ No newline at end of file From c5b05149faa295e651784f4812996abedd99f0a7 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Thu, 23 Oct 2025 15:06:26 +0000 Subject: [PATCH 13/15] Apply PHP-CS-Fixer changes --- infrastructure/src/Validator/PayLaterValidator.php | 6 ++++-- .../tests/Unit/Validator/PayLaterValidatorTest.php | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/infrastructure/src/Validator/PayLaterValidator.php b/infrastructure/src/Validator/PayLaterValidator.php index 61ddc4243..76d3ebab1 100644 --- a/infrastructure/src/Validator/PayLaterValidator.php +++ b/infrastructure/src/Validator/PayLaterValidator.php @@ -12,12 +12,14 @@ class PayLaterValidator implements PayLaterValidatorInterface * @var ContextInterface */ private $context; + /** * @var PayPalConfiguration */ private $payPalConfiguration; - public function __construct(ContextInterface $context, PayPalConfiguration $payPalConfiguration) { + public function __construct(ContextInterface $context, PayPalConfiguration $payPalConfiguration) + { $this->context = $context; $this->payPalConfiguration = $payPalConfiguration; } @@ -59,4 +61,4 @@ public function isPayLaterAvailable(): bool && isset($localeCountryMap[$locale]) && $localeCountryMap[$locale] === $merchantCountry; } -} \ No newline at end of file +} diff --git a/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php b/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php index 51be0bf7f..26c37a9e8 100644 --- a/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php +++ b/infrastructure/tests/Unit/Validator/PayLaterValidatorTest.php @@ -29,7 +29,9 @@ class PayLaterValidatorTest extends TestCase { private $contextMock; + private $payPalConfigurationMock; + private $payLaterValidator; protected function setUp(): void From 49c5e0cf5df40819f63c6dec4e30d004d5ae16aa Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 28 Oct 2025 16:35:33 +0200 Subject: [PATCH 14/15] Updated default configuration to enable messages --- core/src/Settings/Configuration/DefaultConfiguration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/Settings/Configuration/DefaultConfiguration.php b/core/src/Settings/Configuration/DefaultConfiguration.php index e7303bc17..40d8a0287 100644 --- a/core/src/Settings/Configuration/DefaultConfiguration.php +++ b/core/src/Settings/Configuration/DefaultConfiguration.php @@ -47,6 +47,6 @@ class DefaultConfiguration 'PS_CHECKOUT_DISPLAY_LOGO_CART' => '1', 'PS_CHECKOUT_HOSTED_FIELDS_CONTINGENCIES' => 'SCA_WHEN_REQUIRED', 'PS_CHECKOUT_PAYPAL_BUTTON' => '{"shape":"pill","label":"pay","color":"gold"}', - 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"disabled"},"category":{"status":"disabled"},"checkout":{"status":"disabled"},"homepage":{"status":"disabled"},"product":{"status":"disabled"}}', + 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"enabled"},"category":{"status":"disabled"},"checkout":{"status":"enabled"},"homepage":{"status":"disabled"},"product":{"status":"enabled"}}', ]; } From 6969d54ddb6cb2068f569107b5b3a0a873755d67 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Mon, 17 Nov 2025 12:36:22 +0200 Subject: [PATCH 15/15] Fixed upgrade file config name --- .../Configuration/DefaultConfiguration.php | 2 +- .../PayPalPayLaterConfiguration.php | 4 +- ps17/upgrade/upgrade-7.5.1.0.php | 93 +++++++++++++------ ps8/upgrade/upgrade-8.5.1.0.php | 93 +++++++++++++------ ps9/upgrade/upgrade-9.5.1.0.php | 93 +++++++++++++------ 5 files changed, 192 insertions(+), 93 deletions(-) diff --git a/core/src/Settings/Configuration/DefaultConfiguration.php b/core/src/Settings/Configuration/DefaultConfiguration.php index 40d8a0287..4a9543950 100644 --- a/core/src/Settings/Configuration/DefaultConfiguration.php +++ b/core/src/Settings/Configuration/DefaultConfiguration.php @@ -47,6 +47,6 @@ class DefaultConfiguration 'PS_CHECKOUT_DISPLAY_LOGO_CART' => '1', 'PS_CHECKOUT_HOSTED_FIELDS_CONTINGENCIES' => 'SCA_WHEN_REQUIRED', 'PS_CHECKOUT_PAYPAL_BUTTON' => '{"shape":"pill","label":"pay","color":"gold"}', - 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"status":"enabled"},"category":{"status":"disabled"},"checkout":{"status":"enabled"},"homepage":{"status":"disabled"},"product":{"status":"enabled"}}', + 'PS_CHECKOUT_PAY_LATER_CONFIG' => '{"cart":{"placement":"cart","status":"enabled","layout":"text","logo-type":"inline","text-color":"black","text-size":"12"},"category":{"placement":"category","status":"disabled","color":"white","layout":"flex","ratio":"8x1"},"checkout":{"placement":"checkout","status":"enabled","layout":"text","logo-type":"inline","text-color":"black","text-size":"12"},"homepage":{"placement":"homepage","status":"disabled","color":"white","layout":"flex","ratio":"8x1"},"product":{"placement":"product","status":"enabled","layout":"text","logo-type":"inline","text-color":"black","text-size":"12"}}', ]; } diff --git a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php index b3db8c816..2aaeba99b 100644 --- a/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php +++ b/core/src/Settings/Configuration/PayPalPayLaterConfiguration.php @@ -85,7 +85,7 @@ public function getPayLaterMessagingConfigurationDefault(): array 'product' => ['status' => 'disabled'], 'homepage' => ['status' => 'disabled'], 'category' => ['status' => 'disabled'], - 'payment' => ['status' => 'disabled'], + 'checkout' => ['status' => 'disabled'], 'cart' => ['status' => 'disabled'], ]; } @@ -106,7 +106,7 @@ private function getPayLaterMessagingConfigurationLegacy(): array 'product' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE) ? 'enabled': 'disabled'], 'homepage' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER) ? 'enabled': 'disabled'], 'category' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER) ? 'enabled': 'disabled'], - 'payment' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], + 'checkout' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], 'cart' => ['status' => $this->configuration->getBoolean(self::PS_CHECKOUT_PAY_LATER_ORDER_PAGE) ? 'enabled': 'disabled'], ]; } diff --git a/ps17/upgrade/upgrade-7.5.1.0.php b/ps17/upgrade/upgrade-7.5.1.0.php index 914e4b2f5..d88e05a36 100644 --- a/ps17/upgrade/upgrade-7.5.1.0.php +++ b/ps17/upgrade/upgrade-7.5.1.0.php @@ -39,36 +39,69 @@ function upgrade_module_7_5_1_0(Ps_checkout $module) foreach ($shopsList as $shopId) { $configuration = json_encode([ - 'product' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'homepage' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'cart' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'payment' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'category' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], + 'cart' => [ + 'placement' => 'cart', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'category' => [ + 'placement' => 'category', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'checkout' => [ + 'placement' => 'checkout', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'homepage' => [ + 'placement' => 'homepage', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'product' => [ + 'placement' => 'product', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], ]); Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId); diff --git a/ps8/upgrade/upgrade-8.5.1.0.php b/ps8/upgrade/upgrade-8.5.1.0.php index 29fa18a70..15c30f031 100644 --- a/ps8/upgrade/upgrade-8.5.1.0.php +++ b/ps8/upgrade/upgrade-8.5.1.0.php @@ -39,36 +39,69 @@ function upgrade_module_8_5_1_0(Ps_checkout $module) foreach ($shopsList as $shopId) { $configuration = json_encode([ - 'product' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'homepage' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'cart' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'payment' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'category' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], + 'cart' => [ + 'placement' => 'cart', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'category' => [ + 'placement' => 'category', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'checkout' => [ + 'placement' => 'checkout', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'homepage' => [ + 'placement' => 'homepage', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'product' => [ + 'placement' => 'product', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], ]); Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId); diff --git a/ps9/upgrade/upgrade-9.5.1.0.php b/ps9/upgrade/upgrade-9.5.1.0.php index 536d4638b..56485d4ab 100644 --- a/ps9/upgrade/upgrade-9.5.1.0.php +++ b/ps9/upgrade/upgrade-9.5.1.0.php @@ -39,36 +39,69 @@ function upgrade_module_9_5_1_0(Ps_checkout $module) foreach ($shopsList as $shopId) { $configuration = json_encode([ - 'product' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'homepage' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'cart' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'payment' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], - 'category' => ['status' => (bool) \Configuration::get( - 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', - null, - null, - $shopId - ) ? 'enabled' : 'disabled'], + 'cart' => [ + 'placement' => 'cart', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'category' => [ + 'placement' => 'category', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_CATEGORY_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'checkout' => [ + 'placement' => 'checkout', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_ORDER_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], + 'homepage' => [ + 'placement' => 'homepage', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_HOME_PAGE_BANNER', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'color' => 'white', + 'layout' => 'flex', + 'ratio' => '8x1', + ], + 'product' => [ + 'placement' => 'product', + 'status' => (bool) \Configuration::get( + 'PS_CHECKOUT_PAY_LATER_PRODUCT_PAGE', + null, + null, + $shopId + ) ? 'enabled' : 'disabled', + 'layout' => 'text', + 'logo-type' => 'inline', + 'text-color' => 'black', + 'text-size' => '12', + ], ]); Configuration::updateValue('PS_CHECKOUT_PAY_LATER_CONFIG', $configuration, false, null, (int) $shopId);