diff --git a/mollie-payments-for-woocommerce.php b/mollie-payments-for-woocommerce.php index b62a5af2..07eae740 100644 --- a/mollie-payments-for-woocommerce.php +++ b/mollie-payments-for-woocommerce.php @@ -3,7 +3,7 @@ * Plugin Name: Mollie Payments for WooCommerce * Plugin URI: https://www.mollie.com * Description: Accept payments in WooCommerce with the official Mollie plugin - * Version: 7.5.1 + * Version: 7.6.0 * Author: Mollie * Author URI: https://www.mollie.com * Requires at least: 5.0 diff --git a/public/images/bancomatpay.svg b/public/images/bancomatpay.svg new file mode 100644 index 00000000..6d0b5e84 --- /dev/null +++ b/public/images/bancomatpay.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/resources/js/mollieBillie.js b/resources/js/mollieBillie.js deleted file mode 100644 index ad31361e..00000000 --- a/resources/js/mollieBillie.js +++ /dev/null @@ -1,32 +0,0 @@ -import {maybeRequireField, saveOriginalField} from "./wooCheckoutFieldsUtility"; - -( - function ({jQuery}) { - let gateway = 'mollie_wc_gateway_billie'; - let inputCompanyName = 'billing_company'; - let originalBillingCompanyField = saveOriginalField(inputCompanyName, {}); - let companyFieldId = 'billing_company_field'; - let companyField = jQuery('form[name="checkout"] p#billing_company_field'); - let positionCompanyField = 'li.wc_payment_method.payment_method_mollie_wc_gateway_billie'; - let companyMarkup = '

' - + '' - + '' - + '' - + '' - + '

' - - jQuery(function () { - jQuery('body') - .on('updated_checkout payment_method_selected', function () { - companyField = maybeRequireField(companyField, positionCompanyField, companyMarkup, inputCompanyName, companyFieldId, originalBillingCompanyField, gateway); - }); - }); - } -)( - window -) - - - diff --git a/src/Assets/AssetsModule.php b/src/Assets/AssetsModule.php index 5a97e4e7..da8c7a6e 100644 --- a/src/Assets/AssetsModule.php +++ b/src/Assets/AssetsModule.php @@ -276,13 +276,6 @@ protected function registerFrontendScripts(string $pluginUrl, string $pluginPath (string) filemtime($this->getPluginPath($pluginPath, '/public/js/gatewaySurcharge.min.js')), true ); - wp_register_script( - 'mollie-billie-classic-handles', - $this->getPluginUrl($pluginUrl, '/public/js/mollieBillie.min.js'), - ['underscore', 'jquery'], - (string) filemtime($this->getPluginPath($pluginPath, '/public/js/mollieBillie.min.js')), - true - ); } public function registerBlockScripts(string $pluginUrl, string $pluginPath): void diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index e06c151e..f0ed2a3e 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -249,6 +249,11 @@ static function () { 11, 2 ); + add_action( + 'woocommerce_checkout_posted_data', + [$this, 'switchFields'], + 11 + ); } $isIn3Enabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_in3_settings', 'enabled'); if ($isIn3Enabled) { @@ -263,6 +268,30 @@ static function () { [$this, 'in3FieldsMandatoryPayForOrder'], 11 ); + add_action( + 'woocommerce_checkout_posted_data', + [$this, 'switchFields'], + 11 + ); + } + $isBancomatPayEnabled = mollieWooCommerceIsGatewayEnabled('mollie_wc_gateway_bancomatpay_settings', 'enabled'); + if ($isBancomatPayEnabled) { + add_filter( + 'woocommerce_after_checkout_validation', + [$this, 'bancomatpayFieldsMandatory'], + 11, + 2 + ); + add_action( + 'woocommerce_before_pay_action', + [$this, 'bancomatpayFieldsMandatoryPayForOrder'], + 11 + ); + add_action( + 'woocommerce_checkout_posted_data', + [$this, 'switchFields'], + 11 + ); } // Set order to paid and processed when eventually completed without Mollie add_action('woocommerce_payment_complete', [$this, 'setOrderPaidByOtherGateway'], 10, 1); @@ -621,7 +650,7 @@ protected function instantiatePaymentMethods($container): array public function BillieFieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_billie"; - $field = 'billing_company'; + $field = 'billing_company_billie'; $companyLabel = __('Company', 'mollie-payments-for-woocommerce'); return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $field, $companyLabel, $errors); } @@ -629,7 +658,7 @@ public function BillieFieldsMandatory($fields, $errors) public function in3FieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_in3"; - $phoneField = 'billing_phone'; + $phoneField = 'billing_phone_in3'; $birthdateField = self::FIELD_IN3_BIRTHDATE; $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); $birthDateLabel = __('Birthdate', 'mollie-payments-for-woocommerce'); @@ -637,6 +666,15 @@ public function in3FieldsMandatory($fields, $errors) return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $birthdateField, $birthDateLabel, $errors); } + public function bancomatpayFieldsMandatory($fields, $errors) + { + $gatewayName = "mollie_wc_gateway_bancomatpay"; + $phoneField = 'billing_phone_bancomatpay'; + $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); + return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $phoneField, $phoneLabel, $errors); + } + + /** * @param $order */ @@ -662,6 +700,31 @@ public function in3FieldsMandatoryPayForOrder($order) } } + /** + * @param $order + */ + public function bancomatpayFieldsMandatoryPayForOrder($order) + { + $paymentMethod = filter_input(INPUT_POST, 'payment_method', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + + if ($paymentMethod !== 'mollie_wc_gateway_bancomatpay') { + return; + } + + $phoneValue = filter_input(INPUT_POST, 'billing_phone_bancomatpay', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); + + if (!$phoneValue) { + wc_add_notice( + sprintf( + __('%s is a required field.', 'woocommerce'), + "$phoneLabel" + ), + 'error' + ); + } + } + /** * @param string $id * @param IconFactory $iconFactory @@ -722,4 +785,28 @@ public function addPaymentMethodMandatoryFields($fields, string $gatewayName, st return $fields; } + + + public function switchFields($data) + { + if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_in3') { + $fieldPosted = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if ($fieldPosted) { + $data['billing_phone'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_phone']; + } + } + if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_bancomatpay') { + $fieldPosted = filter_input(INPUT_POST, 'billing_phone_bancomatpay', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if ($fieldPosted) { + $data['billing_phone'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_phone']; + } + } + if (isset($data['payment_method']) && $data['payment_method'] === 'mollie_wc_gateway_billie') { + $fieldPosted = filter_input(INPUT_POST, 'billing_company_billie', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + if ($fieldPosted) { + $data['billing_company'] = !empty($fieldPosted) ? $fieldPosted : $data['billing_company']; + } + } + return $data; + } } diff --git a/src/PaymentMethods/Bancomatpay.php b/src/PaymentMethods/Bancomatpay.php new file mode 100644 index 00000000..dd3d33fe --- /dev/null +++ b/src/PaymentMethods/Bancomatpay.php @@ -0,0 +1,36 @@ + 'bancomatpay', + 'defaultTitle' => __('Bancomat Pay', 'mollie-payments-for-woocommerce'), + 'settingsDescription' => '', + 'defaultDescription' => '', + 'paymentFields' => true, + 'instructions' => false, + 'supports' => [ + 'products', + 'refunds', + ], + 'filtersOnBuild' => false, + 'confirmationDelayed' => false, + 'errorMessage' => __( + 'Required field is empty. Phone field is required.', + 'mollie-payments-for-woocommerce' + ), + 'phonePlaceholder' => __('Please enter your phone here. +00..', 'mollie-payments-for-woocommerce'), + ]; + } + + public function getFormFields($generalFormFields): array + { + return $generalFormFields; + } +} diff --git a/src/PaymentMethods/Billie.php b/src/PaymentMethods/Billie.php index 720aed88..369f4952 100644 --- a/src/PaymentMethods/Billie.php +++ b/src/PaymentMethods/Billie.php @@ -16,7 +16,7 @@ protected function getConfig(): array 'mollie-payments-for-woocommerce' ), 'defaultDescription' => '', - 'paymentFields' => false, + 'paymentFields' => true, 'instructions' => false, 'supports' => [ 'products', diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php new file mode 100644 index 00000000..a274e451 --- /dev/null +++ b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php @@ -0,0 +1,56 @@ +getOrderIdOnPayForOrderPage(); + $showPhoneField = empty($order->get_billing_phone()); + } + + if (is_checkout() && !is_checkout_pay_page()) { + $showPhoneField = true; + } + + if ($showPhoneField) { + $this->phoneNumber(); + } + } + + protected function getOrderIdOnPayForOrderPage() + { + global $wp; + $orderId = absint($wp->query_vars['order-pay']); + return wc_get_order($orderId); + } + + protected function phoneNumber() + { + ?> +

+ + + + +

+ getOrderIdOnPayForOrderPage(); + $showCompanyField = empty($order->get_billing_company()); + } + + if (is_checkout() && !is_checkout_pay_page()) { + $showCompanyField = true; + } + + if ($showCompanyField) { + $this->company(); + } + } + + protected function getOrderIdOnPayForOrderPage() + { + global $wp; + $orderId = absint($wp->query_vars['order-pay']); + return wc_get_order($orderId); + } + + protected function company() + { + ?> +

+ + + + +

+ checkout()->get_checkout_fields(); - - if (!isset($checkoutFields["billing"][self::FIELD_PHONE])) { $showPhoneField = true; - } - - if (!isset($checkoutFields["billing"][self::FIELD_BIRTHDATE])) { $showBirthdateField = true; - } } if ($showPhoneField) { diff --git a/src/Shared/SharedDataDictionary.php b/src/Shared/SharedDataDictionary.php index eb722439..c544c593 100644 --- a/src/Shared/SharedDataDictionary.php +++ b/src/Shared/SharedDataDictionary.php @@ -33,6 +33,7 @@ class SharedDataDictionary 'Mollie_WC_Gateway_Directdebit', 'Mollie_WC_Gateway_Blik', 'Mollie_WC_Gateway_Twint', + 'Mollie_WC_Gateway_Bancomatpay', ]; public const MOLLIE_OPTIONS_NAMES = [ diff --git a/webpack.config.js b/webpack.config.js index 81a5f614..1ae240bf 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -30,7 +30,6 @@ function configJavaScript ({ basePath }) .addEntry('mollieBlockIndex.min', './resources/js/mollieBlockIndex.js') .addEntry('paypalButtonBlockComponent.min', './resources/js/paypalButtonBlockComponent.js') .addEntry('applepayButtonBlockComponent.min', './resources/js/applepayButtonBlockComponent.js') - .addEntry('mollieBillie.min', './resources/js/mollieBillie.js') .enableSourceMaps(!Encore.isProduction()) return extractEncoreConfig('javascript-configuration')