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..f3401af9 100644 --- a/src/Gateway/GatewayModule.php +++ b/src/Gateway/GatewayModule.php @@ -686,18 +686,19 @@ 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) { 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' ); - } 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 +316xxxxxxxx', '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; @@ -822,7 +821,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) @@ -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..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. Phone 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'), ]; } 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',