diff --git a/changelog.md b/changelog.md index 2f581979b..e5c003d72 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,10 @@ # Changelog # +## Changes in release 5.4.2 ## ++ Decoupled Apple Pay direct feature flag into product and cart separate settings. ++ Overall improvements and bug fixes. + ## Changes in release 5.4.1 ## + Fixed payment fee tax problems and improved fee set-up process. + Sync Mollie components and Single click flag to the environment selected. diff --git a/mollie.php b/mollie.php index ba661646a..fd13aa287 100644 --- a/mollie.php +++ b/mollie.php @@ -10,6 +10,7 @@ * @codingStandardsIgnoreStart */ +use Mollie\Adapter\ConfigurationAdapter; use Mollie\Adapter\ToolsAdapter; use Mollie\Api\Exceptions\ApiException; use Mollie\Builder\InvoicePdfTemplateBuilder; @@ -59,7 +60,7 @@ public function __construct() { $this->name = 'mollie'; $this->tab = 'payments_gateways'; - $this->version = '5.4.1'; + $this->version = '5.4.2'; $this->author = 'Mollie B.V.'; $this->need_instance = 1; $this->bootstrap = true; @@ -408,13 +409,19 @@ public function hookActionFrontControllerSetMedia($params) { /** @var \Mollie\Service\ErrorDisplayService $errorDisplayService */ $errorDisplayService = $this->getMollieContainer()->get(\Mollie\Service\ErrorDisplayService::class); + /** @var PaymentMethodRepositoryInterface $methodRepository */ $methodRepository = $this->getMollieContainer()->get(PaymentMethodRepositoryInterface::class); - $isCartController = $this->context->controller instanceof CartControllerCore; - if ($isCartController) { + /** @var ConfigurationAdapter $configuration */ + $configuration = $this->getMollieContainer()->get(ConfigurationAdapter::class); + + $controller = $this->context->controller; + + if ($controller instanceof CartControllerCore) { $errorDisplayService->showCookieError('mollie_payment_canceled_error'); } + /** @var ?MolPaymentMethod $paymentMethod */ $paymentMethod = $methodRepository->findOneBy( [ @@ -422,32 +429,39 @@ public function hookActionFrontControllerSetMedia($params) 'live_environment' => Configuration::get(Config::MOLLIE_ENVIRONMENT), ] ); + if (!$paymentMethod || !$paymentMethod->enabled) { return; } - $isApplePayEnabled = Configuration::get(Config::MOLLIE_APPLE_PAY_DIRECT); - if ($isApplePayEnabled) { - $controller = $this->context->controller; - if ($controller instanceof ProductControllerCore || $controller instanceof CartControllerCore) { - Media::addJsDef([ - 'countryCode' => $this->context->country->iso_code, - 'currencyCode' => $this->context->currency->iso_code, - 'totalLabel' => $this->context->shop->name, - 'customerId' => $this->context->customer->id ?? 0, - 'ajaxUrl' => $this->context->link->getModuleLink('mollie', 'applePayDirectAjax'), - 'cartId' => $this->context->cart->id, - 'applePayButtonStyle' => (int) Configuration::get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), - ]); - $this->context->controller->addCSS($this->getPathUri() . 'views/css/front/apple_pay_direct.css'); - - if ($controller instanceof ProductControllerCore) { - $this->context->controller->addJS($this->getPathUri() . 'views/js/front/applePayDirect/applePayDirectProduct.js'); - } - if ($controller instanceof CartControllerCore) { - $this->context->controller->addJS($this->getPathUri() . 'views/js/front/applePayDirect/applePayDirectCart.js'); - } - } + $isApplePayDirectProductEnabled = (int) $configuration->get(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT); + $isApplePayDirectCartEnabled = (int) $configuration->get(Config::MOLLIE_APPLE_PAY_DIRECT_CART); + + $canDisplayInProductPage = $controller instanceof ProductControllerCore && $isApplePayDirectProductEnabled; + $canDisplayInCartPage = $controller instanceof CartControllerCore && $isApplePayDirectCartEnabled; + + if (!$canDisplayInProductPage && !$canDisplayInCartPage) { + return; + } + + Media::addJsDef([ + 'countryCode' => $this->context->country->iso_code, + 'currencyCode' => $this->context->currency->iso_code, + 'totalLabel' => $this->context->shop->name, + 'customerId' => $this->context->customer->id ?? 0, + 'ajaxUrl' => $this->context->link->getModuleLink('mollie', 'applePayDirectAjax'), + 'cartId' => $this->context->cart->id, + 'applePayButtonStyle' => (int) Configuration::get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), + ]); + + $this->context->controller->addCSS($this->getPathUri() . 'views/css/front/apple_pay_direct.css'); + + if ($controller instanceof ProductControllerCore) { + $this->context->controller->addJS($this->getPathUri() . 'views/js/front/applePayDirect/applePayDirectProduct.js'); + } + + if ($controller instanceof CartControllerCore) { + $this->context->controller->addJS($this->getPathUri() . 'views/js/front/applePayDirect/applePayDirectCart.js'); } } diff --git a/src/Builder/FormBuilder.php b/src/Builder/FormBuilder.php index d912beb92..8995092cc 100644 --- a/src/Builder/FormBuilder.php +++ b/src/Builder/FormBuilder.php @@ -140,7 +140,7 @@ public function buildSettingsForm() $helper->table = $this->module->getTable(); $helper->module = $this->module; $helper->default_form_language = $this->module->getContext()->language->id; - $helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0); + $helper->allow_employee_form_lang = $this->configurationAdapter->get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG'); $helper->identifier = $this->module->getIdentifier(); $helper->submit_action = 'submitmollie'; @@ -413,23 +413,24 @@ protected function getAccountSettingsSection($isApiKeyProvided) 'taxRulesGroups' => $this->taxRulesGroupRepository->getTaxRulesGroups($this->context->getShopId()), 'tab' => $generalSettings, 'onlyOrderMethods' => Config::ORDER_API_ONLY_METHODS, - 'displayErrors' => Configuration::get(Config::MOLLIE_DISPLAY_ERRORS), + 'displayErrors' => $this->configurationAdapter->get(Config::MOLLIE_DISPLAY_ERRORS), 'methodDescription' => TagsUtility::ppTags( $this->module->l('[1]Read more[/1] about the differences between Payments and Orders API.', self::FILE_NAME), [ $this->module->display($this->module->getPathUri(), 'views/templates/admin/mollie_method_info.tpl'), ] ), - 'showCustomLogo' => Configuration::get(Config::MOLLIE_SHOW_CUSTOM_LOGO), + 'showCustomLogo' => $this->configurationAdapter->get(Config::MOLLIE_SHOW_CUSTOM_LOGO), 'customLogoUrl' => $this->creditCardLogoProvider->getLogoPathUri() . "?{$dateStamp}", 'customLogoExist' => $this->creditCardLogoProvider->logoExists(), - 'voucherCategory' => Configuration::get(Config::MOLLIE_VOUCHER_CATEGORY), + 'voucherCategory' => $this->configurationAdapter->get(Config::MOLLIE_VOUCHER_CATEGORY), 'klarnaPayments' => Config::KLARNA_PAYMENTS, 'klarnaStatuses' => [Config::MOLLIE_STATUS_KLARNA_AUTHORIZED, Config::MOLLIE_STATUS_KLARNA_SHIPPED], - 'applePayDirect' => (int) Configuration::get(Config::MOLLIE_APPLE_PAY_DIRECT), - 'applePayDIrectStyle' => (int) Configuration::get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), - 'isBancontactQrCodeEnabled' => (int) Configuration::get(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED), - 'isLive' => (int) Configuration::get(Config::MOLLIE_ENVIRONMENT), + 'applePayDirectProduct' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT), + 'applePayDirectCart' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_CART), + 'applePayDirectStyle' => (int) $this->configurationAdapter->get(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE), + 'isBancontactQrCodeEnabled' => (int) $this->configurationAdapter->get(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED), + 'isLive' => (int) $this->configurationAdapter->get(Config::MOLLIE_ENVIRONMENT), 'bancontactQRCodeDescription' => TagsUtility::ppTags( $this->module->l('Only available with your Live API key and Payments API. [1]Learn more[/1] about QR Codes.', self::FILE_NAME), [ @@ -573,7 +574,7 @@ protected function getAdvancedSettingsSection() 'description' => $desc, 'message' => sprintf($messageStatus, $this->module->lang($name)), 'key_mail' => @constant('Mollie\Config\Config::MOLLIE_MAIL_WHEN_' . Tools::strtoupper($name)), - 'value_mail' => Configuration::get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($name)), + 'value_mail' => $this->configurationAdapter->get('MOLLIE_MAIL_WHEN_' . Tools::strtoupper($name)), 'description_mail' => sprintf($descriptionMail, $this->module->lang($name)), 'message_mail' => sprintf($messageMail, $this->module->lang($name)), ]; diff --git a/src/Config/Config.php b/src/Config/Config.php index f76c50581..7097dee73 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -149,7 +149,8 @@ class Config const MOLLIE_STATUS_KLARNA_SHIPPED = 'MOLLIE_STATUS_KLARNA_SHIPPED'; const MOLLIE_STATUS_CHARGEBACK = 'MOLLIE_STATUS_CHARGEBACK'; const MOLLIE_KLARNA_INVOICE_ON = 'MOLLIE_KLARNA_INVOICE_ON'; - const MOLLIE_APPLE_PAY_DIRECT = 'MOLLIE_APPLE_PAY_DIRECT'; + const MOLLIE_APPLE_PAY_DIRECT_PRODUCT = 'MOLLIE_APPLE_PAY_DIRECT_PRODUCT'; + const MOLLIE_APPLE_PAY_DIRECT_CART = 'MOLLIE_APPLE_PAY_DIRECT_CART'; const MOLLIE_APPLE_PAY_DIRECT_STYLE = 'MOLLIE_APPLE_PAY_DIRECT_STYLE'; const MOLLIE_BANCONTACT_QR_CODE_ENABLED = 'MOLLIE_BANCONTACT_QR_CODE_ENABLED'; diff --git a/src/Service/SettingsSaveService.php b/src/Service/SettingsSaveService.php index 882213245..860c7d9d6 100644 --- a/src/Service/SettingsSaveService.php +++ b/src/Service/SettingsSaveService.php @@ -215,12 +215,17 @@ public function saveSettings(&$errors = []) Config::MOLLIE_SHOW_CUSTOM_LOGO, $useCustomLogo ); - $isApplePayDirectEnabled = (bool) Tools::getValue('MOLLIE_APPLE_PAY_DIRECT_ENABLED'); - if ($isApplePayDirectEnabled) { + + $isApplePayDirectProductEnabled = (int) Tools::getValue('MOLLIE_APPLE_PAY_DIRECT_PRODUCT_ENABLED'); + $isApplePayDirectCartEnabled = (int) Tools::getValue('MOLLIE_APPLE_PAY_DIRECT_CART_ENABLED'); + + if ($isApplePayDirectProductEnabled || $isApplePayDirectCartEnabled) { try { $this->applePayDirectCertificateHandler->handle(); } catch (ApplePayDirectCertificateCreation $e) { - $isApplePayDirectEnabled = false; + $isApplePayDirectProductEnabled = false; + $isApplePayDirectCartEnabled = false; + $errors[] = $e->getMessage(); $errors[] = TagsUtility::ppTags( $this->module->l('Grant permissions for the folder or visit [1]ApplePay[/1] to see how it can be added manually', self::FILE_NAME), @@ -228,6 +233,7 @@ public function saveSettings(&$errors = []) ); } } + $molliePaymentscreenLocale = Tools::getValue(Config::MOLLIE_PAYMENTSCREEN_LOCALE); $mollieOrderConfirmationSand = Tools::getValue(Config::MOLLIE_SEND_ORDER_CONFIRMATION); $mollieIFrameEnabled = Tools::getValue(Config::MOLLIE_IFRAME[$environment ? 'production' : 'sandbox']); @@ -236,13 +242,15 @@ public function saveSettings(&$errors = []) $showResentPayment = Tools::getValue(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK); $mollieIssuers = Tools::getValue(Config::MOLLIE_ISSUERS[$environment ? 'production' : 'sandbox']); $mollieCss = Tools::getValue(Config::MOLLIE_CSS); + if (!isset($mollieCss)) { $mollieCss = ''; } + $mollieLogger = Tools::getValue(Config::MOLLIE_DEBUG_LOG); $mollieApi = Tools::getValue(Config::MOLLIE_API); - $mollieMethodCountriesEnabled = (bool) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES); - $mollieMethodCountriesDisplayEnabled = (bool) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY); + $mollieMethodCountriesEnabled = (int) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES); + $mollieMethodCountriesDisplayEnabled = (int) Tools::getValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY); $mollieErrors = Tools::getValue(Config::MOLLIE_DISPLAY_ERRORS); $voucherCategory = Tools::getValue(Config::MOLLIE_VOUCHER_CATEGORY); $applePayDirectStyle = Tools::getValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE); @@ -282,7 +290,9 @@ public function saveSettings(&$errors = []) if ($isBancontactQrCodeEnabled !== false) { $this->configurationAdapter->updateValue(Config::MOLLIE_BANCONTACT_QR_CODE_ENABLED, $isBancontactQrCodeEnabled); } - $this->configurationAdapter->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT, $isApplePayDirectEnabled); + + $this->configurationAdapter->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT, $isApplePayDirectProductEnabled); + $this->configurationAdapter->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_CART, $isApplePayDirectCartEnabled); $this->configurationAdapter->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_STYLE, $applePayDirectStyle); $this->configurationAdapter->updateValue(Config::MOLLIE_API_KEY, $mollieApiKey); $this->configurationAdapter->updateValue(Config::MOLLIE_API_KEY_TEST, $mollieApiKeyTest); @@ -294,8 +304,8 @@ public function saveSettings(&$errors = []) $this->configurationAdapter->updateValue(Config::MOLLIE_IMAGES, $mollieImages); $this->configurationAdapter->updateValue(Config::MOLLIE_SHOW_RESEND_PAYMENT_LINK, $showResentPayment); $this->configurationAdapter->updateValue(Config::MOLLIE_ISSUERS, $mollieIssuers); - $this->configurationAdapter->updateValue(Config::MOLLIE_METHOD_COUNTRIES, (bool) $mollieMethodCountriesEnabled); - $this->configurationAdapter->updateValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY, (bool) $mollieMethodCountriesDisplayEnabled); + $this->configurationAdapter->updateValue(Config::MOLLIE_METHOD_COUNTRIES, (int) $mollieMethodCountriesEnabled); + $this->configurationAdapter->updateValue(Config::MOLLIE_METHOD_COUNTRIES_DISPLAY, (int) $mollieMethodCountriesDisplayEnabled); $this->configurationAdapter->updateValue(Config::MOLLIE_CSS, $mollieCss); $this->configurationAdapter->updateValue(Config::MOLLIE_DISPLAY_ERRORS, (int) $mollieErrors); $this->configurationAdapter->updateValue(Config::MOLLIE_DEBUG_LOG, (int) $mollieLogger); @@ -305,7 +315,7 @@ public function saveSettings(&$errors = []) Config::MOLLIE_AUTO_SHIP_STATUSES, json_encode($this->getStatusesValue(Config::MOLLIE_AUTO_SHIP_STATUSES)) ); - $this->configurationAdapter->updateValue(Config::MOLLIE_AUTO_SHIP_MAIN, (bool) $mollieShipMain); + $this->configurationAdapter->updateValue(Config::MOLLIE_AUTO_SHIP_MAIN, (int) $mollieShipMain); $this->configurationAdapter->updateValue( Config::MOLLIE_TRACKING_URLS, json_encode(@json_decode(Tools::getValue(Config::MOLLIE_TRACKING_URLS))) diff --git a/upgrade/Upgrade-5.4.2.php b/upgrade/Upgrade-5.4.2.php new file mode 100644 index 000000000..4eb467563 --- /dev/null +++ b/upgrade/Upgrade-5.4.2.php @@ -0,0 +1,31 @@ + + * @copyright Mollie B.V. + * @license https://github.com/mollie/PrestaShop/blob/master/LICENSE.md + * + * @see https://github.com/mollie/PrestaShop + */ + +use Mollie\Adapter\ConfigurationAdapter; +use Mollie\Config\Config; + +if (!defined('_PS_VERSION_')) { + exit; +} + +function upgrade_module_5_4_2(Mollie $module): bool +{ + /** @var ConfigurationAdapter $configuration */ + $configuration = $module->getMollieContainer(ConfigurationAdapter::class); + + $configuration->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_PRODUCT, (int) $configuration->get('MOLLIE_APPLE_PAY_DIRECT')); + $configuration->updateValue(Config::MOLLIE_APPLE_PAY_DIRECT_CART, (int) $configuration->get('MOLLIE_APPLE_PAY_DIRECT')); + + $configuration->delete('MOLLIE_APPLE_PAY_DIRECT'); + + return true; +} diff --git a/views/js/admin/settings.js b/views/js/admin/settings.js index 90c72a789..8392f8e13 100644 --- a/views/js/admin/settings.js +++ b/views/js/admin/settings.js @@ -76,14 +76,20 @@ $(document).ready(function () { function handleApplePayButtonStylesToggle() { - var $applePayButtonStyles = $('#js-mollie-applepay-button-styles'); - var $applePayDirectEnableSelector = $('select[name^="MOLLIE_APPLE_PAY_DIRECT_ENABLED"]'); + let $applePayButtonStyles = $('#js-mollie-applepay-button-styles'); + let $applePayDirectProductEnableSelector = $('select[name^="MOLLIE_APPLE_PAY_DIRECT_PRODUCT_ENABLED"]'); + let $applePayDirectCartEnableSelector = $('select[name^="MOLLIE_APPLE_PAY_DIRECT_CART_ENABLED"]'); - toggleElement($applePayButtonStyles, $applePayDirectEnableSelector.val() === '1') - $($applePayDirectEnableSelector).on('change', function () { - var isEnabled = $(this).val() === '1'; - toggleElement($applePayButtonStyles, isEnabled) - }) + toggleElement( + $applePayButtonStyles, + $applePayDirectProductEnableSelector.val() === '1' || $applePayDirectCartEnableSelector.val() === '1' + ) + + $applePayDirectProductEnableSelector.add($applePayDirectCartEnableSelector).on('change', function() { + let isEnabled = $applePayDirectProductEnableSelector.val() === '1' || $applePayDirectCartEnableSelector.val() === '1'; + + toggleElement($applePayButtonStyles, isEnabled) + }) } function toggleElement(element, isShown) diff --git a/views/templates/admin/_configure/helpers/form/form.tpl b/views/templates/admin/_configure/helpers/form/form.tpl index b93b59811..315b9d2db 100644 --- a/views/templates/admin/_configure/helpers/form/form.tpl +++ b/views/templates/admin/_configure/helpers/form/form.tpl @@ -108,14 +108,23 @@ {if $paymentMethod.id === 'applepay'}
- + + + +
+
+
+ +
+
@@ -130,7 +139,7 @@ style="width: 100%;" alt="Black">
@@ -138,7 +147,7 @@ style="width: 100%;" alt="White with Outline">
@@ -146,7 +155,7 @@ style="width: 100%;" alt="White">