diff --git a/.idea/php.xml b/.idea/php.xml index f41096f5..813e1695 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -132,6 +132,10 @@ + + + + @@ -241,7 +245,7 @@ - + diff --git a/mollie-payments-for-woocommerce.php b/mollie-payments-for-woocommerce.php index d0e72a75..7281215f 100644 --- a/mollie-payments-for-woocommerce.php +++ b/mollie-payments-for-woocommerce.php @@ -162,4 +162,4 @@ function initialize() } } -add_action('after_setup_theme', __NAMESPACE__ . '\\initialize'); +add_action('plugins_loaded', __NAMESPACE__ . '\\initialize'); diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index 777e0d84..a7a06172 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -285,9 +285,10 @@ static function () { // Set order to paid and processed when eventually completed without Mollie add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1); - $appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get( - 'gateway.instances' - )['mollie_wc_gateway_applepay'] : false; + + $surchargeService = $container->get(Surcharge::class); + assert($surchargeService instanceof Surcharge); + $this->gatewaySurchargeHandling($surchargeService); $notice = $container->get(AdminNotice::class); assert($notice instanceof AdminNotice); $logger = $container->get(Logger::class); @@ -297,9 +298,9 @@ static function () { assert($apiHelper instanceof Api); $settingsHelper = $container->get('settings.settings_helper'); assert($settingsHelper instanceof Settings); - $surchargeService = $container->get(Surcharge::class); - assert($surchargeService instanceof Surcharge); - $this->gatewaySurchargeHandling($surchargeService); + $appleGateway = isset($container->get('gateway.instances')['mollie_wc_gateway_applepay']) ? $container->get( + 'gateway.instances' + )['mollie_wc_gateway_applepay'] : false; if ($appleGateway) { $this->mollieApplePayDirectHandling($notice, $logger, $apiHelper, $settingsHelper, $appleGateway); } diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index 18ef627a..11e6b2f3 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -127,8 +127,9 @@ public function __construct( ); $this->supports = $this->paymentMethod->getProperty('supports'); - // Load the settings. - $this->init_form_fields(); + // Load the settings when translations are ready + add_action('init', [$this, 'init_form_fields']); + $this->init_settings(); $this->title = $this->paymentMethod->title(); diff --git a/src/PaymentMethods/AbstractPaymentMethod.php b/src/PaymentMethods/AbstractPaymentMethod.php index a83cee26..1976e785 100644 --- a/src/PaymentMethods/AbstractPaymentMethod.php +++ b/src/PaymentMethods/AbstractPaymentMethod.php @@ -44,6 +44,10 @@ abstract class AbstractPaymentMethod implements PaymentMethodI * @var array */ private $apiPaymentMethod; + /** + * @var bool + */ + protected bool $translationsInitialized = false; public function __construct( IconFactory $iconFactory, @@ -61,6 +65,8 @@ public function __construct( $this->config = $this->getConfig(); $this->settings = $this->getSettings(); $this->apiPaymentMethod = $apiPaymentMethod; + add_action('init', [$this, 'initializeTranslations']); + add_action('init', [$this, 'updateSettingsWithDefaults']); } public function title(): string @@ -223,6 +229,20 @@ public function getProcessedDescriptionForBlock(): string * @return array */ public function getSettings(): array + { + $optionName = 'mollie_wc_gateway_' . $this->id . '_settings'; + $settings = get_option($optionName, false); + if (!$settings) { + $settings = []; + } + return $settings; + } + + /** + * Update the payment method's settings with defaults if not exist + * @return array + */ + public function updateSettingsWithDefaults(): array { $optionName = 'mollie_wc_gateway_' . $this->id . '_settings'; $settings = get_option($optionName, false); diff --git a/src/PaymentMethods/Alma.php b/src/PaymentMethods/Alma.php index d127a986..8534730b 100644 --- a/src/PaymentMethods/Alma.php +++ b/src/PaymentMethods/Alma.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'alma', - 'defaultTitle' => __('Alma', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Alma', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -29,7 +29,15 @@ protected function getConfig(): array 'docs' => 'https://www.mollie.com/gb/payments/alma', ]; } - + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Alma', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Applepay.php b/src/PaymentMethods/Applepay.php index 9b392b5b..f791252f 100644 --- a/src/PaymentMethods/Applepay.php +++ b/src/PaymentMethods/Applepay.php @@ -10,8 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'applepay', - 'defaultTitle' => __('Apple Pay', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __('To accept payments via Apple Pay', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Apple Pay', + 'settingsDescription' => 'To accept payments via Apple Pay', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => true, @@ -28,6 +28,19 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Apple Pay', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Apple Pay', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } public function getFormFields($generalFormFields): array { diff --git a/src/PaymentMethods/Bancomatpay.php b/src/PaymentMethods/Bancomatpay.php index 7f9600fa..020162f1 100644 --- a/src/PaymentMethods/Bancomatpay.php +++ b/src/PaymentMethods/Bancomatpay.php @@ -10,7 +10,7 @@ public function getConfig(): array { return [ 'id' => 'bancomatpay', - 'defaultTitle' => __('Bancomat Pay', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Bancomat Pay', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -25,6 +25,16 @@ public function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Bancomat Pay', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Bancontact.php b/src/PaymentMethods/Bancontact.php index 14ac3832..64c9d4fe 100644 --- a/src/PaymentMethods/Bancontact.php +++ b/src/PaymentMethods/Bancontact.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'bancontact', - 'defaultTitle' => __('Bancontact', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Bancontact', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Bancontact', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Banktransfer.php b/src/PaymentMethods/Banktransfer.php index 6abc7586..1765f9be 100644 --- a/src/PaymentMethods/Banktransfer.php +++ b/src/PaymentMethods/Banktransfer.php @@ -29,7 +29,7 @@ protected function getConfig(): array { return [ 'id' => 'banktransfer', - 'defaultTitle' => __('Bank Transfer', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Bank Transfer', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -46,6 +46,17 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Bank Transfer', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + + public function getFormFields($generalFormFields): array { unset($generalFormFields['activate_expiry_days_setting']); diff --git a/src/PaymentMethods/Belfius.php b/src/PaymentMethods/Belfius.php index c8876451..aeca93f1 100644 --- a/src/PaymentMethods/Belfius.php +++ b/src/PaymentMethods/Belfius.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'belfius', - 'defaultTitle' => __('Belfius Direct Net', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Belfius Direct Net', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,15 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Belfius Direct Net', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index 923b52b1..e791ac31 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -20,11 +20,8 @@ protected function getConfig(): array { return [ 'id' => 'billie', - 'defaultTitle' => __('Billie', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Billie', + 'settingsDescription' => 'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => true, 'instructions' => false, @@ -36,15 +33,35 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, - 'errorMessage' => __( - 'Company field is empty. The company field is required.', - 'mollie-payments-for-woocommerce' - ), - 'companyPlaceholder' => __('Please enter your company name here.', 'mollie-payments-for-woocommerce'), + 'errorMessage' => 'Company field is empty. The company field is required.', + 'companyPlaceholder' => 'Please enter your company name here.', 'docs' => 'https://www.mollie.com/gb/payments/billie', ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Billie', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Billie, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->config['errorMessage'] = __( + 'Company field is empty. The company field is required.', + 'mollie-payments-for-woocommerce' + ); + $this->config['companyPlaceholder'] = __( + 'Please enter your company name here.', + 'mollie-payments-for-woocommerce' + ); + + $this->translationsInitialized = true; + } + /** * Add filters and actions for the Billie payment method. * This will be added during constructor diff --git a/src/PaymentMethods/Blik.php b/src/PaymentMethods/Blik.php index c0590dcd..156cd009 100644 --- a/src/PaymentMethods/Blik.php +++ b/src/PaymentMethods/Blik.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'blik', - 'defaultTitle' => __('BLIK', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'BLIK', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('BLIK', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Creditcard.php b/src/PaymentMethods/Creditcard.php index 85e26b43..ea7c4872 100644 --- a/src/PaymentMethods/Creditcard.php +++ b/src/PaymentMethods/Creditcard.php @@ -13,7 +13,7 @@ protected function getConfig(): array { return [ 'id' => 'creditcard', - 'defaultTitle' => __('Credit card', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Credit card', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => $this->hasPaymentFields(), @@ -31,6 +31,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Credit card', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $componentFields = $this->includeMollieComponentsFields($generalFormFields); diff --git a/src/PaymentMethods/Directdebit.php b/src/PaymentMethods/Directdebit.php index 0b7bf94f..50171cd1 100644 --- a/src/PaymentMethods/Directdebit.php +++ b/src/PaymentMethods/Directdebit.php @@ -10,8 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'directdebit', - 'defaultTitle' => __('SEPA Direct Debit', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __("SEPA Direct Debit is used for recurring payments with WooCommerce Subscriptions, and will not be shown in the WooCommerce checkout for regular payments! You also need to enable iDEAL and/or other 'first' payment methods if you want to use SEPA Direct Debit.", 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'SEPA Direct Debit', 'mollie-payments-for-woocommerce', + 'settingsDescription' => "SEPA Direct Debit is used for recurring payments with WooCommerce Subscriptions, and will not be shown in the WooCommerce checkout for regular payments! You also need to enable iDEAL and/or other 'first' payment methods if you want to use SEPA Direct Debit.", 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => true, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('SEPA Direct Debit', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __("SEPA Direct Debit is used for recurring payments with WooCommerce Subscriptions, and will not be shown in the WooCommerce checkout for regular payments! You also need to enable iDEAL and/or other 'first' payment methods if you want to use SEPA Direct Debit.", 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { unset($generalFormFields['display_logo']); diff --git a/src/PaymentMethods/Eps.php b/src/PaymentMethods/Eps.php index 327a53ac..e05e364c 100644 --- a/src/PaymentMethods/Eps.php +++ b/src/PaymentMethods/Eps.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'eps', - 'defaultTitle' => __('EPS', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'EPS', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('EPS', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Giftcard.php b/src/PaymentMethods/Giftcard.php index b5154541..6bb5d80e 100644 --- a/src/PaymentMethods/Giftcard.php +++ b/src/PaymentMethods/Giftcard.php @@ -59,9 +59,9 @@ protected function getConfig(): array { return [ 'id' => 'giftcard', - 'defaultTitle' => __('Gift cards', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Gift cards', 'mollie-payments-for-woocommerce', 'settingsDescription' => '', - 'defaultDescription' => __('Select your gift card', 'mollie-payments-for-woocommerce'), + 'defaultDescription' => 'Select your gift card', 'paymentFields' => true, 'instructions' => false, 'supports' => [ @@ -74,6 +74,16 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Gift cards', 'mollie-payments-for-woocommerce'); + $this->config['defaultDescription'] = __('Select your gift card', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $searchKey = 'advanced'; diff --git a/src/PaymentMethods/Giropay.php b/src/PaymentMethods/Giropay.php index 8939ce56..28501b96 100644 --- a/src/PaymentMethods/Giropay.php +++ b/src/PaymentMethods/Giropay.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'giropay', - 'defaultTitle' => __('Giropay', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Giropay', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Giropay', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $notice = [ diff --git a/src/PaymentMethods/Ideal.php b/src/PaymentMethods/Ideal.php index 08b28c0b..82aa9395 100644 --- a/src/PaymentMethods/Ideal.php +++ b/src/PaymentMethods/Ideal.php @@ -12,7 +12,7 @@ public function getConfig(): array { return [ 'id' => 'ideal', - 'defaultTitle' => __('iDEAL', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'iDEAL', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -28,6 +28,15 @@ public function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('iDEAL', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $notice = [ @@ -36,12 +45,12 @@ public function getFormFields($generalFormFields): array sprintf( /* translators: Placeholder 1: paragraph opening tag Placeholder 2: link url Placeholder 3: link closing tag 4: link url Placeholder 5: closing tags */ __( - '%1$s Note: In June 2024, Mollie upgraded its iDEAL implementation to iDEAL 2.0. - As a result, the bank selector dropdown is no longer displayed on the checkout page when using the Mollie plugin. - Buyers will now select their bank directly on the iDEAL website. - The only action required from you is to update your iDEAL gateway description to remove any prompts for buyers to select a bank during checkout. - No further manual action is needed. For more details about the iDEAL 2.0 migration, please visit the - %2$s Mollie Help Center %3$s or read this + '%1$s Note: In June 2024, Mollie upgraded its iDEAL implementation to iDEAL 2.0. + As a result, the bank selector dropdown is no longer displayed on the checkout page when using the Mollie plugin. + Buyers will now select their bank directly on the iDEAL website. + The only action required from you is to update your iDEAL gateway description to remove any prompts for buyers to select a bank during checkout. + No further manual action is needed. For more details about the iDEAL 2.0 migration, please visit the + %2$s Mollie Help Center %3$s or read this %4$s this blog post. %5$s', 'mollie-payments-for-woocommerce' ), diff --git a/src/PaymentMethods/In3.php b/src/PaymentMethods/In3.php index f839c6e7..95f9db64 100644 --- a/src/PaymentMethods/In3.php +++ b/src/PaymentMethods/In3.php @@ -10,9 +10,9 @@ public function getConfig(): array { return [ 'id' => 'in3', - 'defaultTitle' => __('in3', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'in3', 'settingsDescription' => '', - 'defaultDescription' => __('Pay in 3 instalments, 0% interest', 'mollie-payments-for-woocommerce'), + 'defaultDescription' => 'Pay in 3 instalments, 0% interest', 'paymentFields' => true, 'additionalFields' => ['birthdate', 'phone'], 'instructions' => false, @@ -23,16 +23,29 @@ public function getConfig(): array 'filtersOnBuild' => false, 'confirmationDelayed' => false, 'orderMandatory' => true, - 'errorMessage' => __( - 'Required field is empty or invalid. Phone (+316xxxxxxxx) and birthdate fields are required.', - 'mollie-payments-for-woocommerce' - ), - 'phonePlaceholder' => __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'), - 'birthdatePlaceholder' => __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'), + 'errorMessage' => 'Required field is empty or invalid. Phone (+316xxxxxxxx) and birthdate fields are required.', + 'phonePlaceholder' => 'Please enter your phone here. +316xxxxxxxx', + 'birthdatePlaceholder' => 'Please enter your birthdate here.', 'docs' => 'https://www.mollie.com/gb/payments/ideal-in3', ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('in3', 'mollie-payments-for-woocommerce'); + $this->config['defaultDescription'] = __('Pay in 3 instalments, 0% interest', 'mollie-payments-for-woocommerce'); + $this->config['errorMessage'] = __( + 'Required field is empty or invalid. Phone (+316xxxxxxxx) and birthdate fields are required.', + 'mollie-payments-for-woocommerce' + ); + $this->config['phonePlaceholder'] = __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'); + $this->config['birthdatePlaceholder'] = __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Kbc.php b/src/PaymentMethods/Kbc.php index 99de76e9..04943def 100644 --- a/src/PaymentMethods/Kbc.php +++ b/src/PaymentMethods/Kbc.php @@ -11,9 +11,9 @@ protected function getConfig(): array { return [ 'id' => 'kbc', - 'defaultTitle' => __('KBC/CBC Payment Button', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'KBC/CBC Payment Button', 'settingsDescription' => '', - 'defaultDescription' => __('Select your bank', 'mollie-payments-for-woocommerce'), + 'defaultDescription' => 'Select your bank', 'paymentFields' => true, 'instructions' => false, 'supports' => [ @@ -27,6 +27,16 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('KBC/CBC Payment Button', 'mollie-payments-for-woocommerce'); + $this->config['defaultDescription'] = __('Select your bank', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $searchKey = 'advanced'; diff --git a/src/PaymentMethods/Klarna.php b/src/PaymentMethods/Klarna.php index 0c0b3ccc..6258f5dd 100644 --- a/src/PaymentMethods/Klarna.php +++ b/src/PaymentMethods/Klarna.php @@ -10,11 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'klarna', - 'defaultTitle' => __('Pay with Klarna', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Pay with Klarna', + 'settingsDescription' => 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => false, @@ -30,6 +27,19 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Pay with Klarna', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Klarnapaylater.php b/src/PaymentMethods/Klarnapaylater.php index edd6f6c9..6b0ba5b6 100644 --- a/src/PaymentMethods/Klarnapaylater.php +++ b/src/PaymentMethods/Klarnapaylater.php @@ -10,11 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'klarnapaylater', - 'defaultTitle' => __('Klarna Pay later', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Klarna Pay later', + 'settingsDescription' => 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => false, @@ -30,6 +27,19 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Klarna Pay later', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Klarnapaynow.php b/src/PaymentMethods/Klarnapaynow.php index 5cdddfeb..1e763e66 100644 --- a/src/PaymentMethods/Klarnapaynow.php +++ b/src/PaymentMethods/Klarnapaynow.php @@ -10,11 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'klarnapaynow', - 'defaultTitle' => __('Klarna Pay Now', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Klarna Pay Now', + 'settingsDescription' => 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => false, @@ -30,6 +27,19 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Klarna Pay Now', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Klarnasliceit.php b/src/PaymentMethods/Klarnasliceit.php index dd8e31c2..b827eb90 100644 --- a/src/PaymentMethods/Klarnasliceit.php +++ b/src/PaymentMethods/Klarnasliceit.php @@ -10,11 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'klarnasliceit', - 'defaultTitle' => __('Klarna Slice it', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Klarna Slice it', 'mollie-payments-for-woocommerce', + 'settingsDescription' => 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => false, @@ -30,6 +27,19 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Klarna Slice it', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Klarna, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Mybank.php b/src/PaymentMethods/Mybank.php index e656d23e..05f7d998 100644 --- a/src/PaymentMethods/Mybank.php +++ b/src/PaymentMethods/Mybank.php @@ -10,8 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'mybank', - 'defaultTitle' => __('MyBank', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __('To accept payments via MyBank', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'MyBank', + 'settingsDescription' => 'To accept payments via MyBank', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => true, @@ -26,6 +26,16 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('MyBank', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __('To accept payments via MyBank', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Payconiq.php b/src/PaymentMethods/Payconiq.php index b89696c9..c2ec1cb8 100644 --- a/src/PaymentMethods/Payconiq.php +++ b/src/PaymentMethods/Payconiq.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'payconiq', - 'defaultTitle' => __('payconiq', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'payconiq', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -23,6 +23,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('payconiq', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Paypal.php b/src/PaymentMethods/Paypal.php index 7484f072..ca990f49 100644 --- a/src/PaymentMethods/Paypal.php +++ b/src/PaymentMethods/Paypal.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'paypal', - 'defaultTitle' => __('PayPal', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'PayPal', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('PayPal', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $paymentMethodFormFieds = [ diff --git a/src/PaymentMethods/Paysafecard.php b/src/PaymentMethods/Paysafecard.php index 4e1fe4d5..c2666fd8 100644 --- a/src/PaymentMethods/Paysafecard.php +++ b/src/PaymentMethods/Paysafecard.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'paysafecard', - 'defaultTitle' => __('paysafecard', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'paysafecard', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -23,6 +23,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('paysafecard', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Przelewy24.php b/src/PaymentMethods/Przelewy24.php index 58eb2692..4edbd19c 100644 --- a/src/PaymentMethods/Przelewy24.php +++ b/src/PaymentMethods/Przelewy24.php @@ -10,11 +10,8 @@ protected function getConfig(): array { return [ 'id' => 'przelewy24', - 'defaultTitle' => __('Przelewy24', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Przelewy24, a customer email is required for every payment.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Przelewy24', + 'settingsDescription' => 'To accept payments via Przelewy24, a customer email is required for every payment.', 'defaultDescription' => '', 'paymentFields' => false, 'instructions' => true, @@ -29,6 +26,19 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Przelewy24', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Przelewy24, a customer email is required for every payment.', + 'mollie-payments-for-woocommerce' + ); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Riverty.php b/src/PaymentMethods/Riverty.php index e7db2037..7c589783 100644 --- a/src/PaymentMethods/Riverty.php +++ b/src/PaymentMethods/Riverty.php @@ -12,11 +12,8 @@ protected function getConfig(): array { return [ 'id' => 'riverty', - 'defaultTitle' => __('Riverty', 'mollie-payments-for-woocommerce'), - 'settingsDescription' => __( - 'To accept payments via Riverty, all default WooCommerce checkout fields should be enabled and required.', - 'mollie-payments-for-woocommerce' - ), + 'defaultTitle' => 'Riverty', + 'settingsDescription' => 'To accept payments via Riverty, all default WooCommerce checkout fields should be enabled and required.', 'defaultDescription' => '', 'paymentFields' => true, 'additionalFields' => ['birthdate', 'phone'], @@ -29,12 +26,28 @@ protected function getConfig(): array 'confirmationDelayed' => false, 'SEPA' => false, 'orderMandatory' => true, - 'phonePlaceholder' => __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'), - 'birthdatePlaceholder' => __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'), + 'phonePlaceholder' => 'Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce', + 'birthdatePlaceholder' => 'Please enter your birthdate here.', 'mollie-payments-for-woocommerce', 'docs' => 'https://www.mollie.com/gb/payments/riverty', ]; } + // Replace translatable strings after the 'after_setup_theme' hook + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Riverty', 'mollie-payments-for-woocommerce'); + $this->config['settingsDescription'] = __( + 'To accept payments via Riverty, all default WooCommerce checkout fields should be enabled and required.', + 'mollie-payments-for-woocommerce' + ); + $this->config['phonePlaceholder'] = __('Please enter your phone here. +316xxxxxxxx', 'mollie-payments-for-woocommerce'); + $this->config['birthdatePlaceholder'] = __('Please enter your birthdate here.', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Satispay.php b/src/PaymentMethods/Satispay.php index 61bd49f7..3103a021 100644 --- a/src/PaymentMethods/Satispay.php +++ b/src/PaymentMethods/Satispay.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'satispay', - 'defaultTitle' => __('Satispay', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Satispay', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -23,6 +23,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Satispay', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Sofort.php b/src/PaymentMethods/Sofort.php index d33a0865..57ff5a88 100644 --- a/src/PaymentMethods/Sofort.php +++ b/src/PaymentMethods/Sofort.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'sofort', - 'defaultTitle' => __('SOFORT Banking', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'SOFORT Banking', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('SOFORT Banking', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Swish.php b/src/PaymentMethods/Swish.php index 704fbc04..c33b89bf 100644 --- a/src/PaymentMethods/Swish.php +++ b/src/PaymentMethods/Swish.php @@ -10,7 +10,7 @@ public function getConfig(): array { return [ 'id' => 'swish', - 'defaultTitle' => __('Swish', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Swish', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -25,6 +25,15 @@ public function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Swish', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Trustly.php b/src/PaymentMethods/Trustly.php index 14fca0df..1279224b 100644 --- a/src/PaymentMethods/Trustly.php +++ b/src/PaymentMethods/Trustly.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'trustly', - 'defaultTitle' => __('Trustly', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Trustly', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Trustly', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Twint.php b/src/PaymentMethods/Twint.php index 8b33f958..5389a852 100644 --- a/src/PaymentMethods/Twint.php +++ b/src/PaymentMethods/Twint.php @@ -10,7 +10,7 @@ protected function getConfig(): array { return [ 'id' => 'twint', - 'defaultTitle' => __('Twint', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Twint', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -26,6 +26,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Twint', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { return $generalFormFields; diff --git a/src/PaymentMethods/Voucher.php b/src/PaymentMethods/Voucher.php index 80224f32..4623da4a 100644 --- a/src/PaymentMethods/Voucher.php +++ b/src/PaymentMethods/Voucher.php @@ -31,7 +31,7 @@ protected function getConfig(): array { return [ 'id' => 'voucher', - 'defaultTitle' => __('Voucher', 'mollie-payments-for-woocommerce'), + 'defaultTitle' => 'Voucher', 'settingsDescription' => '', 'defaultDescription' => '', 'paymentFields' => false, @@ -47,6 +47,15 @@ protected function getConfig(): array ]; } + public function initializeTranslations(): void + { + if ($this->translationsInitialized) { + return; + } + $this->config['defaultTitle'] = __('Voucher', 'mollie-payments-for-woocommerce'); + $this->translationsInitialized = true; + } + public function getFormFields($generalFormFields): array { $paymentMethodFormFieds = [ diff --git a/src/Shared/GatewaySurchargeHandler.php b/src/Shared/GatewaySurchargeHandler.php index 2b5240e9..6c5ad9f6 100644 --- a/src/Shared/GatewaySurchargeHandler.php +++ b/src/Shared/GatewaySurchargeHandler.php @@ -19,9 +19,13 @@ class GatewaySurchargeHandler public function __construct(Surcharge $surcharge) { $this->surcharge = $surcharge; - $this->gatewayFeeLabel = $this->surchargeFeeOption(); + add_action('after_setup_theme', [$this, 'initializeGatewayFeeLabel']); add_action('init', [$this, 'surchargeActions']); } + public function initializeGatewayFeeLabel() + { + $this->gatewayFeeLabel = $this->surchargeFeeOption(); + } public function surchargeActions() { diff --git a/src/Shared/SharedModule.php b/src/Shared/SharedModule.php index 40f62690..7b61e446 100644 --- a/src/Shared/SharedModule.php +++ b/src/Shared/SharedModule.php @@ -37,15 +37,11 @@ public function services(): array return plugin_basename(self::PLUGIN_ID . '/' . self::PLUGIN_ID . '.php'); }, 'shared.plugin_url' => static function (ContainerInterface $container): string { - $pluginProperties = $container->get(Package::PROPERTIES); - - return $pluginProperties->baseUrl(); + return $container->get('properties')->baseUrl(); }, 'shared.plugin_path' => static function (ContainerInterface $container): string { - $pluginProperties = $container->get(Package::PROPERTIES); - - return $pluginProperties->basePath(); + return $container->get('properties')->basePath(); }, 'shared.status_helper' => static function (ContainerInterface $container): Status { $pluginTitle = $container->get('shared.plugin_title'); diff --git a/tests/php/Functional/Shared/SurchargeHandlerTest.php b/tests/php/Functional/Shared/SurchargeHandlerTest.php index bbf43be0..764616cd 100644 --- a/tests/php/Functional/Shared/SurchargeHandlerTest.php +++ b/tests/php/Functional/Shared/SurchargeHandlerTest.php @@ -59,6 +59,7 @@ public function addsSurchargeFeesInCheckout(){ [new Surcharge()], ['canProcessOrder', 'canProcessGateway', 'orderRemoveFee', 'orderAddFee'] )->getMock(); + $testee->initializeGatewayFeeLabel(); expect('mollieWooCommerceIsCheckoutContext')->andReturn(true); expect('wc_tax_enabled')->andReturn(false); expect('WC')->andReturn($this->wooCommerce()); @@ -106,6 +107,7 @@ public function addsSurchargeFeesInOrderPayPage() [new Surcharge()], ['canProcessOrder', 'canProcessGateway', 'orderRemoveFee', 'orderAddFee'] )->getMock(); + $testee->initializeGatewayFeeLabel(); $testee->expects($this->once()) ->method('canProcessOrder')