Skip to content

Commit

Permalink
PIPRES-225: Decouple apple pay direct feature flag (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mandan2 authored Aug 8, 2023
1 parent 14c470f commit 35f7c08
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 60 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
64 changes: 39 additions & 25 deletions mollie.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @codingStandardsIgnoreStart
*/

use Mollie\Adapter\ConfigurationAdapter;
use Mollie\Adapter\ToolsAdapter;
use Mollie\Api\Exceptions\ApiException;
use Mollie\Builder\InvoicePdfTemplateBuilder;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -408,46 +409,59 @@ 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(
[
'id_method' => Config::MOLLIE_METHOD_ID_APPLE_PAY,
'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');
}
}

Expand Down
19 changes: 10 additions & 9 deletions src/Builder/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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),
[
Expand Down Expand Up @@ -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)),
];
Expand Down
3 changes: 2 additions & 1 deletion src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
28 changes: 19 additions & 9 deletions src/Service/SettingsSaveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,25 @@ 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),
[$this->module->display($this->module->getPathUri(), 'views/templates/admin/applePayDirectDocumentation.tpl')]
);
}
}

$molliePaymentscreenLocale = Tools::getValue(Config::MOLLIE_PAYMENTSCREEN_LOCALE);
$mollieOrderConfirmationSand = Tools::getValue(Config::MOLLIE_SEND_ORDER_CONFIRMATION);
$mollieIFrameEnabled = Tools::getValue(Config::MOLLIE_IFRAME[$environment ? 'production' : 'sandbox']);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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)))
Expand Down
31 changes: 31 additions & 0 deletions upgrade/Upgrade-5.4.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* Mollie https://www.mollie.nl
*
* @author Mollie B.V. <[email protected]>
* @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;
}
20 changes: 13 additions & 7 deletions views/js/admin/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 35f7c08

Please sign in to comment.