Skip to content

Commit

Permalink
Merge pull request #342 from 202ecommerce/bugfix/46924-pui_invalid_ph…
Browse files Browse the repository at this point in the history
…one_number

refs #46924 pui error: invalid phone
  • Loading branch information
bogdan202 authored Jul 3, 2024
2 parents 39e8d10 + 79d1e6c commit 96aa918
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions classes/API/Client/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ protected function makeCall($ch)

$response->setContent($data);
$response->setCode($code);
$response->setHeaders($headers);

return $response;
}
Expand Down
12 changes: 11 additions & 1 deletion classes/PUI/DataUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

use DateTime;
use PayPal;
use PaypalAddons\services\FormatterPaypal;

if (!defined('_PS_VERSION_')) {
exit;
Expand All @@ -50,6 +51,15 @@ class DataUserForm

/** @var string */
protected $birth;
/**
* @var FormatterPaypal
*/
protected $formatter;

public function __construct()
{
$this->formatter = new FormatterPaypal();
}

/**
* @return string
Expand Down Expand Up @@ -106,7 +116,7 @@ public function getPhone()
*/
public function setPhone($phone)
{
$this->phone = (string) $phone;
$this->phone = $this->formatter->formatPhoneNumber((string) $phone);

return $this;
}
Expand Down
13 changes: 13 additions & 0 deletions services/FormatterPaypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
)
);
}
}

0 comments on commit 96aa918

Please sign in to comment.