Skip to content

Commit

Permalink
Merge branch 'WP-90-main' into 'main'
Browse files Browse the repository at this point in the history
fix: recreate branch from main

See merge request ecommerce_modules/cms/wordpress/wordpress!45
  • Loading branch information
DEMAxx committed Nov 21, 2024
2 parents 564dce5 + 7f88713 commit 794af78
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 195 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"require": {
"php": "^7.4",
"composer/installers": "~2.0",
"giggsey/libphonenumber-for-php": "^8.13",
"paragonie/paserk": "^1.1",
"paragonie/paseto": "^2.4"
},
Expand Down
187 changes: 3 additions & 184 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions src/Actions/OrderCreateAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ private function createOrder(array $packages): array
private function buildRequestData(): array
{
$countryCode = $this->order->country ?: 'RU';
$recipientNumber = $this->order->phone;
PhoneValidator::new()($recipientNumber, $countryCode);
$recipientNumber = PhoneValidator::new()($this->order->phone, $countryCode);

$deliveryMethod = $this->shipping->getMethod();

Expand Down
15 changes: 15 additions & 0 deletions src/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ public function orderHistory(int $orderId): array
)->data();
}

/**
* @throws ApiException
* @throws CoreAuthException
* @throws \Cdek\Exceptions\CacheException
*/
public function validatePhone(string $phone, ?string $country = null): string
{
return HttpClient::sendJsonRequest(
$this->getEndpoint('validate/phone'),
'GET',
$this->getToken(),
['phone' => $phone, 'country' => $country],
)->data()['phone'];
}

/**
* @throws ShopRegistrationException
* @throws CoreAuthException
Expand Down
14 changes: 6 additions & 8 deletions src/Validator/PhoneValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,23 @@

namespace Cdek\Validator {

use Cdek\CoreApi;
use Cdek\Exceptions\External\HttpClientException;
use Cdek\Exceptions\InvalidPhoneException;
use Cdek\Traits\CanBeCreated;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberUtil;

class PhoneValidator
{
use CanBeCreated;

/**
* @throws \Cdek\Exceptions\InvalidPhoneException
*/
public function __invoke(string $phone, string $countryCode = null): void
public function __invoke(string $phone, string $countryCode = null): string
{
$phoneNumUtil = PhoneNumberUtil::getInstance();
try {
if (!$phoneNumUtil->isValidNumber($phoneNumUtil->parse($phone, $countryCode))) {
throw new InvalidPhoneException($phone);
}
} catch (NumberParseException $e) {
return (new CoreApi)->validatePhone($phone, $countryCode);
} catch (HttpClientException $e) {
throw new InvalidPhoneException($phone);
}
}
Expand Down

0 comments on commit 794af78

Please sign in to comment.