Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/piwoo 469 in3 phone number null #906

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 18 additions & 22 deletions src/Gateway/GatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,8 @@ 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(
Expand All @@ -718,7 +717,8 @@ public function in3FieldsMandatoryPayForOrder($order)
),
'error'
);
} else {
}
if ($phoneValid) {
$order->set_billing_phone($phoneValue);
}
}
Expand Down Expand Up @@ -794,29 +794,27 @@ 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;
if (!$fieldPosted) {
$errors->add(
'validation',
sprintf(
__('%s is a required field.', 'woocommerce'),
__('%s is a required field. Valid phone format +000000000', 'woocommerce'),
"<strong>$fieldLabel</strong>"
)
);
return $fields;
}

if (!$this->isPhoneValid($fieldPosted)) {
$errors->add(
'validation',
sprintf(
__('%s is not a valid phone number. Valid phone format +00000000000', 'woocommerce'),
"<strong>$fieldLabel</strong>"
)
);
$fields['billing_phone'] = null;
return $fields;
} else {
$fields['billing_phone'] = $fieldPosted;
Expand All @@ -834,7 +832,7 @@ public function addPaymentMethodMandatoryFieldsBirthVerification(
if ($fields['payment_method'] !== $gatewayName) {
return $fields;
}
if (isset($fields['billing_birthdate']) && $this->isBirthValid($fields['billing_birthdate'])) {
if (!empty($fields['billing_birthdate']) && $this->isBirthValid($fields['billing_birthdate'])) {
return $fields;
}
$fieldPosted = filter_input(INPUT_POST, $field, FILTER_SANITIZE_SPECIAL_CHARS) ?? false;
Expand Down Expand Up @@ -883,7 +881,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);
}

private function isBirthValid($billing_birthdate)
Expand All @@ -906,17 +904,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
);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Payment/MollieObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,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;
Expand Down
2 changes: 1 addition & 1 deletion src/PaymentMethods/In3.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function getConfig(): array
'confirmationDelayed' => false,
'orderMandatory' => true,
'errorMessage' => __(
'Required field is empty or invalid. 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'),
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Functional/Payment/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function processPayment_Order_success(){
->willReturn('');
$wcOrder->expects($this->any())
->method('get_billing_phone')
->willReturn('+1234567890');
->willReturn('+34345678900');
/*
* Execute Test
*/
Expand Down Expand Up @@ -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' => '+12345678900',
'get_shipping_address_1' => 'shippingstreetAndNumber',
'get_shipping_address_2' => 'shippingstreetAdditional',
'get_shipping_postcode' => 'shippingpostalCode',
Expand Down
Loading