From 79d1e6c6944bab4f77660dacdd63e44ac1631822 Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Wed, 3 Jul 2024 11:45:40 +0200 Subject: [PATCH] refs #46924 pui error: invalid phone --- classes/API/Client/HttpClient.php | 1 + classes/PUI/DataUserForm.php | 12 +++++++++++- services/FormatterPaypal.php | 13 +++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/classes/API/Client/HttpClient.php b/classes/API/Client/HttpClient.php index 77fa52cc..5c13f79d 100644 --- a/classes/API/Client/HttpClient.php +++ b/classes/API/Client/HttpClient.php @@ -179,6 +179,7 @@ protected function makeCall($ch) $response->setContent($data); $response->setCode($code); + $response->setHeaders($headers); return $response; } diff --git a/classes/PUI/DataUserForm.php b/classes/PUI/DataUserForm.php index 80c103f9..bc33499a 100644 --- a/classes/PUI/DataUserForm.php +++ b/classes/PUI/DataUserForm.php @@ -29,6 +29,7 @@ use DateTime; use PayPal; +use PaypalAddons\services\FormatterPaypal; if (!defined('_PS_VERSION_')) { exit; @@ -50,6 +51,15 @@ class DataUserForm /** @var string */ protected $birth; + /** + * @var FormatterPaypal + */ + protected $formatter; + + public function __construct() + { + $this->formatter = new FormatterPaypal(); + } /** * @return string @@ -106,7 +116,7 @@ public function getPhone() */ public function setPhone($phone) { - $this->phone = (string) $phone; + $this->phone = $this->formatter->formatPhoneNumber((string) $phone); return $this; } diff --git a/services/FormatterPaypal.php b/services/FormatterPaypal.php index cdceba84..3eca3cbf 100644 --- a/services/FormatterPaypal.php +++ b/services/FormatterPaypal.php @@ -37,4 +37,17 @@ public function formatPaypalString($str) { return \Tools::substr($str, 0, 126); } + + public function formatPhoneNumber($phone) + { + return implode( + '', + array_filter( + str_split($phone), + function ($number) { + return in_array($number, ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']); + } + ) + ); + } }