From a38da28c9e0f1ad04926ca576067b089b523cdd9 Mon Sep 17 00:00:00 2001 From: carmenmaymo Date: Wed, 22 May 2024 08:21:30 +0200 Subject: [PATCH] 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)) {