From 2164df95406c08f079b5254e4d798f89e17a2015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=A1=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 19 Apr 2024 14:40:09 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D1=8F?= =?UTF-8?q?=D1=8E=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=203?= =?UTF-8?q?=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8,=20=D0=B4=D0=BB=D1=8F?= =?UTF-8?q?=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BB?= =?UTF-8?q?=D1=8E=D0=B1=D0=BE=D0=B3=D0=BE=20=D0=B4=D0=BE=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0.=20=D0=9E=D0=B1=D1=80=D0=B0=D1=82=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Clients/MindboxClientV3.php | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Clients/MindboxClientV3.php b/src/Clients/MindboxClientV3.php index 17661bb..bb59cb8 100644 --- a/src/Clients/MindboxClientV3.php +++ b/src/Clients/MindboxClientV3.php @@ -22,18 +22,17 @@ class MindboxClientV3 extends AbstractMindboxClient /** * Базовый URL на который будут отправляться запросы. */ - const BASE_V3_URL = 'https://api.mindbox.{{domainZone}}/v3/operations/'; + const BASE_V3_URL = 'https://{{url}}/v3/operations/'; - const TMP_V3_URL = 'https://api-ru.mindbox.cloud/v3/operations/'; /** * Имя схемы авторизации по секретному ключу. */ const SECRET_KEY_AUTHORIZATION_SCHEME_NAME = 'SecretKey'; /** - * @var string Доменная зона API. + * @var string URL */ - private $domainZone; + private $url; /** * @var string Уникальный идентификатор сайта/мобильного приложения/и т.п. @@ -48,11 +47,12 @@ class MindboxClientV3 extends AbstractMindboxClient * @param IHttpClient $httpClient Экземпляр HTTP клиента. * @param LoggerInterface $logger Экземпляр логгера. * @param string $domainZone + * @param string $domain */ - public function __construct($endpointId, $secretKey, IHttpClient $httpClient, LoggerInterface $logger, $domainZone) + public function __construct($endpointId, $secretKey, IHttpClient $httpClient, LoggerInterface $logger, $domainZone, $domain = 'api.mindbox') { parent::__construct($secretKey, $httpClient, $logger); - $this->domainZone = $domainZone; + $this->url = $this->getApiUrl($domain, $domainZone); $this->endpointId = $endpointId; } @@ -97,11 +97,7 @@ private function getCustomerIP() */ protected function prepareUrl($url, array $queryParams, $isSync = true) { - $domain = $this->getApiUrl(); - - $domain = str_replace('{{domainZone}}', $this->domainZone, $domain); - - return $domain . ($isSync ? 'sync' : 'async') . '?' . http_build_query($queryParams); + return $this->url . ($isSync ? 'sync' : 'async') . '?' . http_build_query($queryParams); } /** @@ -171,19 +167,16 @@ protected function prepareResponseBody($rawBody) } /** - * Временное решение для старых хостингов + * Преобразование API URL * * @return string */ - protected function getApiUrl() + protected function getApiUrl(string $domain, string $domainZone) { - $return = self:: BASE_V3_URL; - switch ($this->domainZone) { - case 'api-ru': - $return = self::TMP_V3_URL; - break; - } + $domainZone = $domainZone == 'api-ru' ? 'cloud' : $domainZone; + + $url = str_replace('{{url}}', $domain . '.' . $domainZone, self:: BASE_V3_URL); - return $return; + return $url; } } From 5506afe3a9900ca2308fd579bac64ed2cab53755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=A1=D0=B5=D0=BB?= =?UTF-8?q?=D0=B8=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 23 Apr 2024 16:00:19 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B8=20=D0=B4=D0=BE=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Clients/MindboxClientV3.php | 2 +- tests/Clients/AbstractMindboxClientTest.php | 10 ++++++++-- tests/Clients/MindboxClientV3Test.php | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Clients/MindboxClientV3.php b/src/Clients/MindboxClientV3.php index bb59cb8..ac55b0c 100644 --- a/src/Clients/MindboxClientV3.php +++ b/src/Clients/MindboxClientV3.php @@ -173,7 +173,7 @@ protected function prepareResponseBody($rawBody) */ protected function getApiUrl(string $domain, string $domainZone) { - $domainZone = $domainZone == 'api-ru' ? 'cloud' : $domainZone; + $domainZone = $domainZone === 'api-ru' ? 'cloud' : $domainZone; $url = str_replace('{{url}}', $domain . '.' . $domainZone, self:: BASE_V3_URL); diff --git a/tests/Clients/AbstractMindboxClientTest.php b/tests/Clients/AbstractMindboxClientTest.php index 6c5ccad..f6f338b 100644 --- a/tests/Clients/AbstractMindboxClientTest.php +++ b/tests/Clients/AbstractMindboxClientTest.php @@ -29,7 +29,12 @@ class AbstractMindboxClientTest extends TestCase /** * @var string */ - protected $domain = 'ru'; + protected $domainZone = 'ru'; + + /** + * @var string + */ + protected $domain = 'api.mindbox'; /** * @var string @@ -59,6 +64,7 @@ class AbstractMindboxClientTest extends TestCase public function setUp(): void { $this->domain = $this->domain; + $this->domainZone = $this->domainZone; $this->httpClientStub = $this->getHttpClientStub(); $this->loggerStub = $this->getLoggerStub(); $this->client = $this->getClient($this->secret, $this->httpClientStub, $this->loggerStub, $this->domain); @@ -284,7 +290,7 @@ protected function getClient($secret, $httpClient, $loggerClient) 'prepareBody', 'prepareResponseBody' ]) - ->setConstructorArgs([$secret, $httpClient, $loggerClient, $this->domain]) + ->setConstructorArgs([$secret, $httpClient, $loggerClient, $this->domainZone, $this->domain]) ->getMock(); $clientStub->expects($this->any()) diff --git a/tests/Clients/MindboxClientV3Test.php b/tests/Clients/MindboxClientV3Test.php index 08106c2..6a6247a 100644 --- a/tests/Clients/MindboxClientV3Test.php +++ b/tests/Clients/MindboxClientV3Test.php @@ -104,7 +104,7 @@ public function expectedArgsForSendProvider() */ protected function getClient($secret, $httpClient, $loggerClient) { - $client = new MindboxClientV3($this->endpointId, $secret, $httpClient, $loggerClient, $this->domain); + $client = new MindboxClientV3($this->endpointId, $secret, $httpClient, $loggerClient, $this->domainZone, $this->domain); return $client; }