From 6b9e2f453fa39f7281ce53e2708ae90ac2766902 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Fri, 17 May 2024 11:50:55 +0200 Subject: [PATCH 01/12] Add PIWOO-469 out of release --- .idea/WooCommerce.iml | 5 --- .idea/php.xml | 10 ++++-- src/Gateway/GatewayModule.php | 35 +++++++++---------- src/Payment/MollieOrder.php | 4 +-- src/PaymentMethods/In3.php | 2 +- .../Functional/Payment/PaymentServiceTest.php | 4 +-- 6 files changed, 28 insertions(+), 32 deletions(-) diff --git a/.idea/WooCommerce.iml b/.idea/WooCommerce.iml index 9aa75e6b..44b2cf64 100644 --- a/.idea/WooCommerce.iml +++ b/.idea/WooCommerce.iml @@ -3,11 +3,6 @@ - - - - - diff --git a/.idea/php.xml b/.idea/php.xml index 34031bf4..d7c33327 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -130,12 +130,16 @@ + + + + - - + + @@ -261,4 +265,4 @@ - + \ No newline at end of file diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index ad652069..e16ea476 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -686,7 +686,7 @@ public function in3FieldsMandatoryPayForOrder($order) ); } $phoneValue = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - $phoneValue = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : false; + $phoneValid = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : null; $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); if (!$phoneValue) { @@ -697,7 +697,8 @@ public function in3FieldsMandatoryPayForOrder($order) ), 'error' ); - } else { + } + if ($phoneValid) { $order->set_billing_phone($phoneValue); } } @@ -773,7 +774,11 @@ public function addPaymentMethodMandatoryFieldsPhoneVerification( if ($fields['payment_method'] !== $gatewayName) { return $fields; } - if (isset($fields['billing_phone']) && $this->isPhoneValid($fields['billing_phone'])) { + if (!empty($fields['billing_phone']) && $this->isPhoneValid($fields['billing_phone'])) { + return $fields; + } + if (!empty($fields['billing_phone']) && !$this->isPhoneValid($fields['billing_phone'])) { + $fields['billing_phone'] = null; return $fields; } $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; @@ -781,7 +786,7 @@ public function addPaymentMethodMandatoryFieldsPhoneVerification( $errors->add( 'validation', sprintf( - __('%s is a required field.', 'woocommerce'), + __('%s is a required field. Valid phone format +000000000', 'woocommerce'), "$fieldLabel" ) ); @@ -789,13 +794,7 @@ public function addPaymentMethodMandatoryFieldsPhoneVerification( } if (!$this->isPhoneValid($fieldPosted)) { - $errors->add( - 'validation', - sprintf( - __('%s is not a valid phone number. Valid phone format +00000000000', 'woocommerce'), - "$fieldLabel" - ) - ); + $fields['billing_phone'] = null; return $fields; } else { $fields['billing_phone'] = $fieldPosted; @@ -835,17 +834,15 @@ public function addPhoneWhenRest($arrayContext) if (!empty($billingPhone) && $this->isPhoneValid($billingPhone)) { return; } + if (!empty($billingPhone) && !$this->isPhoneValid($billingPhone)) { + $context->order->set_billing_phone(null); + $context->order->save(); + return; + } $billingPhone = $context->payment_data['billing_phone']; - if ($billingPhone) { + if ($billingPhone && $this->isPhoneValid($billingPhone)) { $context->order->set_billing_phone($billingPhone); $context->order->save(); - } else { - $message = __('Please introduce a valid phone number. +00000000000', 'mollie-payments-for-woocommerce'); - throw new RouteException( - 'woocommerce_rest_checkout_process_payment_error', - $message, - 402 - ); } } } diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index 4a3e0feb..af449cea 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -1227,8 +1227,8 @@ protected function getFormatedPhoneNumber(string $phone) //remove whitespaces and all non numerical characters except + $phone = preg_replace('/[^0-9+]+/', '', $phone); - //check that $phone is in E164 format - if ($phone !== null && preg_match('/^\+[1-9]\d{1,14}$/', $phone)) { + //check that $phone is in E164 format or can be changed by api + if ($phone !== null && preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { return $phone; } return null; diff --git a/src/PaymentMethods/In3.php b/src/PaymentMethods/In3.php index be4b7ec3..31aa9039 100644 --- a/src/PaymentMethods/In3.php +++ b/src/PaymentMethods/In3.php @@ -23,7 +23,7 @@ public function getConfig(): array 'confirmationDelayed' => false, 'orderMandatory' => true, 'errorMessage' => __( - 'Required field is empty. Phone and birthdate fields are required.', + 'Required field is empty or invalid. Phone (+00..) and birthdate fields are required.', 'mollie-payments-for-woocommerce' ), 'phonePlaceholder' => __('Please enter your phone here. +00..', 'mollie-payments-for-woocommerce'), diff --git a/tests/php/Functional/Payment/PaymentServiceTest.php b/tests/php/Functional/Payment/PaymentServiceTest.php index 4aef1f34..52e7e8bc 100644 --- a/tests/php/Functional/Payment/PaymentServiceTest.php +++ b/tests/php/Functional/Payment/PaymentServiceTest.php @@ -118,7 +118,7 @@ public function processPayment_Order_success(){ ->willReturn(''); $wcOrder->expects($this->any()) ->method('get_billing_phone') - ->willReturn('+1234567890'); + ->willReturn('+34345678900'); /* * Execute Test */ @@ -225,7 +225,7 @@ private function wcOrder($id, $orderKey) 'get_billing_city' => 'billingcity', 'get_billing_state' => 'billingregion', 'get_billing_country' => 'billingcountry', - 'get_billing_phone' => '+1234567890', + 'get_billing_phone' => '+34345678900', 'get_shipping_address_1' => 'shippingstreetAndNumber', 'get_shipping_address_2' => 'shippingstreetAdditional', 'get_shipping_postcode' => 'shippingpostalCode', From 57f6253ba7f327bbdf34eb306e5621ff6a963a8e Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Sat, 18 May 2024 09:42:04 +0200 Subject: [PATCH 02/12] Change message strings --- src/Gateway/GatewayModule.php | 4 ++-- src/PaymentMethods/In3.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index e16ea476..1964dd38 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -692,7 +692,7 @@ public function in3FieldsMandatoryPayForOrder($order) if (!$phoneValue) { wc_add_notice( sprintf( - __('%s is a required field. Valid phone format +000000000', 'mollie-payments-for-woocommerce'), + __('%s is a required field. Valid phone format +316xxxxxxxx', 'mollie-payments-for-woocommerce'), "$phoneLabel" ), 'error' @@ -786,7 +786,7 @@ public function addPaymentMethodMandatoryFieldsPhoneVerification( $errors->add( 'validation', sprintf( - __('%s is a required field. Valid phone format +000000000', 'woocommerce'), + __('%s is a required field. Valid phone format +316xxxxxxxx', 'woocommerce'), "$fieldLabel" ) ); diff --git a/src/PaymentMethods/In3.php b/src/PaymentMethods/In3.php index 31aa9039..51e5d7bf 100644 --- a/src/PaymentMethods/In3.php +++ b/src/PaymentMethods/In3.php @@ -23,10 +23,10 @@ public function getConfig(): array 'confirmationDelayed' => false, 'orderMandatory' => true, 'errorMessage' => __( - 'Required field is empty or invalid. Phone (+00..) and birthdate fields are required.', + 'Required field is empty or invalid. Phone (+316xxxxxxxx) and birthdate fields are required.', 'mollie-payments-for-woocommerce' ), - 'phonePlaceholder' => __('Please enter your phone here. +00..', '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'), ]; } From c5651d1efa64cd7c03cb1f448b1c1460c23aa210 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Sat, 18 May 2024 10:31:11 +0200 Subject: [PATCH 03/12] Phone not required in checkout with in3 --- resources/js/blocks/molliePaymentMethod.js | 3 +-- src/Gateway/GatewayModule.php | 27 +++------------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 3eeb5bc0..2c9d4965 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -173,12 +173,11 @@ const MollieComponent = (props) => { phoneLabel.innerText = phoneString } } - let isPhoneEmpty = (billing.billingData.phone === '' && shippingData.shippingAddress.phone === '') && inputPhone === ''; let isBirthdateEmpty = inputBirthdate === '' const unsubscribeProcessing = onCheckoutValidation( () => { - if (activePaymentMethod === 'mollie_wc_gateway_in3' && (isPhoneEmpty || isBirthdateEmpty)) { + if (activePaymentMethod === 'mollie_wc_gateway_in3' && isBirthdateEmpty) { return { errorMessage: item.errorMessage, }; diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index 1964dd38..ec63db43 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -687,17 +687,7 @@ public function in3FieldsMandatoryPayForOrder($order) } $phoneValue = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; $phoneValid = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : null; - $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); - if (!$phoneValue) { - wc_add_notice( - sprintf( - __('%s is a required field. Valid phone format +316xxxxxxxx', 'mollie-payments-for-woocommerce'), - "$phoneLabel" - ), - 'error' - ); - } if ($phoneValid) { $order->set_billing_phone($phoneValue); } @@ -782,23 +772,12 @@ public function addPaymentMethodMandatoryFieldsPhoneVerification( return $fields; } $fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - if (!$fieldPosted) { - $errors->add( - 'validation', - sprintf( - __('%s is a required field. Valid phone format +316xxxxxxxx', 'woocommerce'), - "$fieldLabel" - ) - ); - return $fields; - } - if (!$this->isPhoneValid($fieldPosted)) { - $fields['billing_phone'] = null; - return $fields; - } else { + if ($fieldPosted && !$this->isPhoneValid($fieldPosted)) { $fields['billing_phone'] = $fieldPosted; + return $fields; } + $fields['billing_phone'] = null; return $fields; } From 9142ecbf9d8a92d85bea3aa54b37897c7876bc76 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Sat, 18 May 2024 11:00:29 +0200 Subject: [PATCH 04/12] Phone and birthdate not required in checkout with in3 --- resources/js/blocks/molliePaymentMethod.js | 29 ---------------------- src/Gateway/GatewayModule.php | 19 ++------------ 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 2c9d4965..97990f49 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -161,35 +161,6 @@ const MollieComponent = (props) => { }, [activePaymentMethod, onCheckoutValidation, billing.billingData, item, companyNameString, inputCompany]); - useEffect(() => { - let phoneLabel = getPhoneField()?.labels?.[0] ?? null; - if (!phoneLabel || phoneLabel.length === 0) { - return - } - if (activePaymentMethod === 'mollie_wc_gateway_in3') { - phoneLabel.innerText = item.phonePlaceholder - } else { - if (phoneString !== false) { - phoneLabel.innerText = phoneString - } - } - let isBirthdateEmpty = inputBirthdate === '' - const unsubscribeProcessing = onCheckoutValidation( - - () => { - if (activePaymentMethod === 'mollie_wc_gateway_in3' && isBirthdateEmpty) { - return { - errorMessage: item.errorMessage, - }; - } - } - ); - return () => { - unsubscribeProcessing() - }; - - }, [activePaymentMethod, onCheckoutValidation, billing.billingData, shippingData.shippingAddress, item, phoneString, inputBirthdate, inputPhone]); - onSubmitLocal = onSubmit const updateIssuer = ( changeEvent ) => { selectIssuer( changeEvent.target.value ) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index ec63db43..e1a7711f 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -655,11 +655,8 @@ public function in3FieldsMandatory($fields, $errors) { $gatewayName = "mollie_wc_gateway_in3"; $phoneField = 'billing_phone_in3'; - $birthdateField = self::FIELD_IN3_BIRTHDATE; $phoneLabel = __('Phone', 'mollie-payments-for-woocommerce'); - $birthDateLabel = __('Birthdate', 'mollie-payments-for-woocommerce'); - $fields = $this->addPaymentMethodMandatoryFieldsPhoneVerification($fields, $gatewayName, $phoneField, $phoneLabel, $errors); - return $this->addPaymentMethodMandatoryFields($fields, $gatewayName, $birthdateField, $birthDateLabel, $errors); + return $this->addPaymentMethodMandatoryFieldsPhoneVerification($fields, $gatewayName, $phoneField, $phoneLabel, $errors); } /** @@ -673,18 +670,6 @@ public function in3FieldsMandatoryPayForOrder($order) return; } - $birthdateValue = filter_input(INPUT_POST, self::FIELD_IN3_BIRTHDATE, FILTER_SANITIZE_SPECIAL_CHARS) ?? false; - $birthDateLabel = __('Birthdate', 'mollie-payments-for-woocommerce'); - - if (!$birthdateValue) { - wc_add_notice( - sprintf( - __('%s is a required field.', 'woocommerce'), - "$birthDateLabel" - ), - 'error' - ); - } $phoneValue = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; $phoneValid = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : null; @@ -800,7 +785,7 @@ public function switchFields($data) private function isPhoneValid($billing_phone) { - return preg_match('/^\+[1-9]\d{10,13}$/', $billing_phone); + return preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $billing_phone); } public function addPhoneWhenRest($arrayContext) From db762ccb3cabc0236031e9f9cf793bc82063f0f1 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Sat, 18 May 2024 15:41:11 +0200 Subject: [PATCH 05/12] Remove * phone birth string --- .../PaymentFieldsStrategies/In3FieldsStrategy.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php index 3c0fdcff..3ae776f3 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php @@ -51,7 +51,6 @@ protected function dateOfBirth() ?>

Date: Sat, 18 May 2024 15:42:52 +0200 Subject: [PATCH 06/12] Change placeholder strings --- .../PaymentFieldsStrategies/BancomatpayFieldsStrategy.php | 2 +- .../PaymentFieldsStrategies/In3FieldsStrategy.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php index 0952e392..777f9fe1 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/BancomatpayFieldsStrategy.php @@ -46,7 +46,7 @@ protected function phoneNumber($phoneValue)

diff --git a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php index 3ae776f3..abdd3d23 100644 --- a/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php +++ b/src/PaymentMethods/PaymentFieldsStrategies/In3FieldsStrategy.php @@ -69,7 +69,7 @@ protected function phoneNumber($phoneValue)

From 698f28db5ef7a36ba16d322e0527c16bc4c4a04a Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Sun, 19 May 2024 10:40:13 +0200 Subject: [PATCH 07/12] Show phone field only if hidden Added some style to block custom field --- resources/js/blocks/molliePaymentMethod.js | 12 ++++---- resources/js/mollieBlockIndex.js | 8 ++++-- resources/scss/mollie-block-custom-field.scss | 28 +++++++++++++++++++ src/Assets/AssetsModule.php | 8 ++++++ src/Gateway/GatewayModule.php | 13 ++++----- webpack.config.js | 1 + 6 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 resources/scss/mollie-block-custom-field.scss diff --git a/resources/js/blocks/molliePaymentMethod.js b/resources/js/blocks/molliePaymentMethod.js index 97990f49..bbf305e3 100644 --- a/resources/js/blocks/molliePaymentMethod.js +++ b/resources/js/blocks/molliePaymentMethod.js @@ -185,12 +185,14 @@ const MollieComponent = (props) => { function fieldMarkup(id, fieldType, label, action, value) { const className = "wc-block-components-text-input wc-block-components-address-form__" + id; - return
-
+ return
+ + +
} - if (item.name === "mollie_wc_gateway_billie"){ - if(isCompanyFieldVisible) { + if (item.name === "mollie_wc_gateway_billie") { + if (isCompanyFieldVisible) { return; } const companyField = item.companyPlaceholder ? item.companyPlaceholder : "Company name"; @@ -201,7 +203,7 @@ const MollieComponent = (props) => { let fields = []; const birthdateField = item.birthdatePlaceholder ? item.birthdatePlaceholder : "Birthdate"; fields.push(fieldMarkup("billing-birthdate", "date", birthdateField, updateBirthdate, inputBirthdate)); - if (!isPhoneFieldVisible) { + if (isPhoneFieldVisible === false) { const phoneField = item.phonePlaceholder ? item.phonePlaceholder : "Phone"; fields.push(fieldMarkup("billing-phone-in3", "tel", phoneField, updatePhone, inputPhone)); } diff --git a/resources/js/mollieBlockIndex.js b/resources/js/mollieBlockIndex.js index 8f4f9e3c..b919acb3 100644 --- a/resources/js/mollieBlockIndex.js +++ b/resources/js/mollieBlockIndex.js @@ -22,9 +22,11 @@ import molliePaymentMethod from './blocks/molliePaymentMethod' function getPhoneField() { - const shippingPhone = shipping_address.phone ?? false; - const billingPhone = billing_address.phone ?? false - return billingPhone || shippingPhone; + const phoneFieldDataset = document.querySelector('[data-show-phone-field]'); + if (!phoneFieldDataset) { + return true; + } + return phoneFieldDataset.dataset.showPhoneField !== "false" } const isCompanyFieldVisible = getCompanyField(); diff --git a/resources/scss/mollie-block-custom-field.scss b/resources/scss/mollie-block-custom-field.scss new file mode 100644 index 00000000..7d73bd89 --- /dev/null +++ b/resources/scss/mollie-block-custom-field.scss @@ -0,0 +1,28 @@ +/* Style the container to match WooCommerce styling */ +.custom-input { + margin-bottom: 1.5em; + display: flex; + flex-direction: column; +} + +.custom-input label { + margin-bottom: 0.5em; + font-weight: bold; +} + +#billing-birthdate, +#billing-phone-in3 { + width: 100%; + padding: 0.75em; + border: 1px solid #ccc; + border-radius: 4px; + box-sizing: border-box; + font-size: 1em; + margin-bottom: 1.25em; +} + +#billing-birthdate { + -webkit-appearance: none; + -moz-appearance: none; + appearance: none; +} diff --git a/src/Assets/AssetsModule.php b/src/Assets/AssetsModule.php index da8c7a6e..66699511 100644 --- a/src/Assets/AssetsModule.php +++ b/src/Assets/AssetsModule.php @@ -34,6 +34,7 @@ public function enqueueBlockCheckoutScripts(Data $dataService, array $gatewayIns } wp_enqueue_script(MollieCheckoutBlocksSupport::getScriptHandle()); wp_enqueue_style('mollie-gateway-icons'); + wp_enqueue_style('mollie-block-custom-field'); MollieCheckoutBlocksSupport::localizeWCBlocksData($dataService, $gatewayInstances); } @@ -288,6 +289,13 @@ public function registerBlockScripts(string $pluginUrl, string $pluginPath): voi (string) filemtime($this->getPluginPath($pluginPath, '/public/js/mollieBlockIndex.min.js')), true ); + wp_register_style( + 'mollie-block-custom-field', + $this->getPluginUrl($pluginUrl, '/public/css/mollie-block-custom-field.min.css'), + [], + (string) filemtime($this->getPluginPath($pluginPath, '/public/css/mollie-block-custom-field.min.css')), + 'screen' + ); } /** diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index e1a7711f..a3d753a6 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -327,16 +327,13 @@ static function ($paymentContext) { } ); add_action('add_meta_boxes_woocommerce_page_wc-orders', [$this, 'addShopOrderMetabox'], 10); - add_filter('woocommerce_form_field_args', static function ($args, $key, $value) use ($container) { - if ($key !== 'billing_phone') { - return $args; - } - if ($args['required'] === true) { - update_option('mollie_wc_is_phone_required_flag', true); - } else { + add_filter('woocommerce_checkout_fields', static function ($fields) use ($container) { + if (!isset($fields['billing']['billing_phone'])) { update_option('mollie_wc_is_phone_required_flag', false); + } else { + update_option('mollie_wc_is_phone_required_flag', true); } - return $args; + return $fields; }, 10, 3); return true; } diff --git a/webpack.config.js b/webpack.config.js index 1ae240bf..e15815b4 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -46,6 +46,7 @@ function configCss ({ basePath }) .addStyleEntry('mollie-gateway-icons.min', './resources/scss/mollie-gateway-icons.scss') .addStyleEntry('unabledButton.min', './resources/scss/unabledButton.scss') .addStyleEntry('mollie-applepaydirect.min', './resources/scss/mollie-applepaydirect.scss') + .addStyleEntry('mollie-block-custom-field.min', './resources/scss/mollie-block-custom-field.scss') .enableSourceMaps(!Encore.isProduction()) return extractEncoreConfig('css-configuration') From 7e4c7573176648217ce8b6d1a97f3d0b115f0260 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Tue, 21 May 2024 20:01:59 +0200 Subject: [PATCH 08/12] Accept 06 and turn into +316 --- src/Gateway/GatewayModule.php | 2 +- src/Payment/MollieOrder.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index a3d753a6..3b2a3aa1 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -782,7 +782,7 @@ public function switchFields($data) private function isPhoneValid($billing_phone) { - return preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $billing_phone); + return preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$|^06\d{9,13}$/', $billing_phone); } public function addPhoneWhenRest($arrayContext) diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index af449cea..6eba9d3b 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -1226,9 +1226,22 @@ protected function getFormatedPhoneNumber(string $phone) { //remove whitespaces and all non numerical characters except + $phone = preg_replace('/[^0-9+]+/', '', $phone); + if (!is_string($phone)) { + return null; + } + //check if phone starts with 06 and replace with +316 + $startsWith06 = preg_match('/^06/', $phone); + if ($startsWith06) { + $prefix = '+316'; + $phone = substr($phone, 2); + if (!$phone) { + return null; + } + $phone = $prefix . $phone; + } //check that $phone is in E164 format or can be changed by api - if ($phone !== null && preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { + if (preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { return $phone; } return null; From a38da28c9e0f1ad04926ca576067b089b523cdd9 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 22 May 2024 08:21:30 +0200 Subject: [PATCH 09/12] Accept 06 and turn into +316 in paypage --- inc/utils.php | 14 ++++++++++++++ src/Gateway/GatewayModule.php | 1 + src/Payment/MollieOrder.php | 10 +--------- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/inc/utils.php b/inc/utils.php index 984e54f3..bdd68c75 100644 --- a/inc/utils.php +++ b/inc/utils.php @@ -222,3 +222,17 @@ function mollieDeleteWPTranslationFiles() } } } + +function transformPhoneToNLFormat($phone) +{ + $startsWith06 = preg_match('/^06/', $phone); + if ($startsWith06) { + $prefix = '+316'; + $phone = substr($phone, 2); + if (!$phone) { + return null; + } + $phone = $prefix . $phone; + } + return $phone; +} diff --git a/src/Gateway/GatewayModule.php b/src/Gateway/GatewayModule.php index 3b2a3aa1..e68da8d4 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -668,6 +668,7 @@ public function in3FieldsMandatoryPayForOrder($order) } $phoneValue = filter_input(INPUT_POST, 'billing_phone_in3', FILTER_SANITIZE_SPECIAL_CHARS) ?? false; + $phoneValue = transformPhoneToNLFormat($phoneValue); $phoneValid = $phoneValue && $this->isPhoneValid($phoneValue) ? $phoneValue : null; if ($phoneValid) { diff --git a/src/Payment/MollieOrder.php b/src/Payment/MollieOrder.php index 6eba9d3b..8c4a85f7 100644 --- a/src/Payment/MollieOrder.php +++ b/src/Payment/MollieOrder.php @@ -1230,15 +1230,7 @@ protected function getFormatedPhoneNumber(string $phone) return null; } //check if phone starts with 06 and replace with +316 - $startsWith06 = preg_match('/^06/', $phone); - if ($startsWith06) { - $prefix = '+316'; - $phone = substr($phone, 2); - if (!$phone) { - return null; - } - $phone = $prefix . $phone; - } + $phone = transformPhoneToNLFormat($phone); //check that $phone is in E164 format or can be changed by api if (preg_match('/^\+[1-9]\d{10,13}$|^[1-9]\d{9,13}$/', $phone)) { From 093d7c0cb8bda7fcbd91df049e62bf4aa456e7f8 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 22 May 2024 10:43:28 +0200 Subject: [PATCH 10/12] Fix issuer empty on block --- src/Gateway/MolliePaymentGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index 7047080a..455bdc03 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -1015,7 +1015,7 @@ public function getSelectedIssuer(): ?string { $issuer_id = $this->pluginId . '_issuer_' . $this->id; - $postedIssuer = filter_input(INPUT_POST, $issuer_id, FILTER_SANITIZE_SPECIAL_CHARS); + $postedIssuer = sanitize_text_field($_POST[$issuer_id] ?? ''); return !empty($postedIssuer) ? $postedIssuer : null; } From f01ec93c3d66edd08a8442f551e4dde745f88a27 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 22 May 2024 10:48:15 +0200 Subject: [PATCH 11/12] Use wc_clean instead --- src/Gateway/MolliePaymentGateway.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index 455bdc03..8e62598f 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -1014,8 +1014,8 @@ public function onOrderReceivedText($text, $order) public function getSelectedIssuer(): ?string { $issuer_id = $this->pluginId . '_issuer_' . $this->id; - - $postedIssuer = sanitize_text_field($_POST[$issuer_id] ?? ''); + //phpcs:ignore WordPress.Security.NonceVerification + $postedIssuer = wc_clean(wp_unslash($_POST[$issuer_id] ?? '')); return !empty($postedIssuer) ? $postedIssuer : null; } From 258f683f30ff87dd544116a2b5db20e7869dd035 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 22 May 2024 10:50:03 +0200 Subject: [PATCH 12/12] Fix cs --- src/Gateway/MolliePaymentGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gateway/MolliePaymentGateway.php b/src/Gateway/MolliePaymentGateway.php index 8e62598f..c9a72920 100644 --- a/src/Gateway/MolliePaymentGateway.php +++ b/src/Gateway/MolliePaymentGateway.php @@ -1014,7 +1014,7 @@ public function onOrderReceivedText($text, $order) public function getSelectedIssuer(): ?string { $issuer_id = $this->pluginId . '_issuer_' . $this->id; - //phpcs:ignore WordPress.Security.NonceVerification + //phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized $postedIssuer = wc_clean(wp_unslash($_POST[$issuer_id] ?? '')); return !empty($postedIssuer) ? $postedIssuer : null; }