Skip to content

Commit d8bf64b

Browse files
authored
Merge pull request #22 from mindbox-moscow/v2.2.0
V2.2.0
2 parents 8d2e434 + 422d5ee commit d8bf64b

7 files changed

Lines changed: 37 additions & 13 deletions

File tree

src/Clients/AbstractMindboxClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@ final protected function parseRawResponse(MindboxRequest $request, HttpClientRaw
284284
$this->logger->error($message, $context);
285285
$body = $context['response']['body'];
286286
$arBody = json_decode($body, true);
287-
throw new \Mindbox\Exceptions\MindboxBadRequestException(substr($arBody['errorMessage'], strpos($arBody['errorMessage'], ":") + 1));
287+
if ($arBody) {
288+
$message = substr($arBody['errorMessage'], strpos($arBody['errorMessage'], ":") + 1);
289+
} else {
290+
$message = 'Bad request';
291+
}
292+
throw new \Mindbox\Exceptions\MindboxBadRequestException($message);
288293
case 409:
289294
$this->logger->error($message, $context);
290295
throw new \Mindbox\Exceptions\MindboxConflictException('Conflict');

src/Clients/MindboxClientFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function createMindboxClient(
4545
throw new MindboxConfigException('Endpoint id cant`t be empty for v3 API');
4646
}
4747

48-
return new MindboxClientV3($endpointId, $secretKey, $httpClient, $logger);
48+
return new MindboxClientV3($endpointId, $secretKey, $httpClient, $logger, $domain);
4949
case 'v2.1':
5050
if (empty($domain)) {
5151
throw new MindboxConfigException('Domain cant`t be empty for v2.1 API');

src/Clients/MindboxClientV3.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@ class MindboxClientV3 extends AbstractMindboxClient
2222
/**
2323
* Базовый URL на который будут отправляться запросы.
2424
*/
25-
const BASE_V3_URL = 'https://api.mindbox.ru/v3/operations/';
25+
const BASE_V3_URL = 'https://api.mindbox.{{domainZone}}/v3/operations/';
2626

2727
/**
2828
* Секретный ключ.
2929
*/
3030
const SECRET_KEY_NAME = 'Mindbox secretKey';
3131

32+
/**
33+
* @var string Доменная зона API.
34+
*/
35+
private $domainZone;
36+
3237
/**
3338
* @var string Уникальный идентификатор сайта/мобильного приложения/и т.п.
3439
*/
@@ -37,14 +42,16 @@ class MindboxClientV3 extends AbstractMindboxClient
3742
/**
3843
* Конструктор MindboxRequest.
3944
*
40-
* @param string $endpointId Уникальный идентификатор сайта/мобильного приложения/и т.п.
41-
* @param string $secretKey Секретный ключ.
42-
* @param IHttpClient $httpClient Экземпляр HTTP клиента.
43-
* @param LoggerInterface $logger Экземпляр логгера.
45+
* @param string $endpointId Уникальный идентификатор сайта/мобильного приложения/и т.п.
46+
* @param string $secretKey Секретный ключ.
47+
* @param IHttpClient $httpClient Экземпляр HTTP клиента.
48+
* @param LoggerInterface $logger Экземпляр логгера.
49+
* @param string $domainZone
4450
*/
45-
public function __construct($endpointId, $secretKey, IHttpClient $httpClient, LoggerInterface $logger)
51+
public function __construct($endpointId, $secretKey, IHttpClient $httpClient, LoggerInterface $logger, $domainZone)
4652
{
4753
parent::__construct($secretKey, $httpClient, $logger);
54+
$this->domainZone = $domainZone;
4855
$this->endpointId = $endpointId;
4956
}
5057

@@ -89,7 +96,8 @@ private function getCustomerIP()
8996
*/
9097
protected function prepareUrl($url, array $queryParams, $isSync = true)
9198
{
92-
return static::BASE_V3_URL . ($isSync ? 'sync' : 'async') . '?' . http_build_query($queryParams);
99+
$domain = str_replace('{{domainZone}}', $this->domainZone, static::BASE_V3_URL);
100+
return $domain . ($isSync ? 'sync' : 'async') . '?' . http_build_query($queryParams);
93101
}
94102

95103
/**

src/Mindbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function __construct(array $config, LoggerInterface $logger)
8383
'v3',
8484
$this->config['endpointId'],
8585
$this->config['secretKey'],
86-
$this->config['domain'],
86+
$this->config['domainZone'],
8787
$httpClient,
8888
$logger
8989
);

tests/Clients/AbstractMindboxClientTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ class AbstractMindboxClientTest extends TestCase
2626
*/
2727
protected $secret = 'secret';
2828

29+
/**
30+
* @var string
31+
*/
32+
protected $domain = 'ru';
33+
2934
/**
3035
* @var string
3136
*/
@@ -53,9 +58,10 @@ class AbstractMindboxClientTest extends TestCase
5358

5459
public function setUp()
5560
{
61+
$this->domain = $this->domain;
5662
$this->httpClientStub = $this->getHttpClientStub();
5763
$this->loggerStub = $this->getLoggerStub();
58-
$this->client = $this->getClient($this->secret, $this->httpClientStub, $this->loggerStub);
64+
$this->client = $this->getClient($this->secret, $this->httpClientStub, $this->loggerStub, $this->domain);
5965
$this->dtoStub = $this->getDTOStub();
6066
}
6167

@@ -278,7 +284,7 @@ protected function getClient($secret, $httpClient, $loggerClient)
278284
'prepareBody',
279285
'prepareResponseBody'
280286
])
281-
->setConstructorArgs([$secret, $httpClient, $loggerClient])
287+
->setConstructorArgs([$secret, $httpClient, $loggerClient, $this->domain])
282288
->getMock();
283289

284290
$clientStub->expects($this->any())

tests/Clients/MindboxClientV3Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function expectedArgsForSendProvider()
104104
*/
105105
protected function getClient($secret, $httpClient, $loggerClient)
106106
{
107-
$client = new MindboxClientV3($this->endpointId, $secret, $httpClient, $loggerClient);
107+
$client = new MindboxClientV3($this->endpointId, $secret, $httpClient, $loggerClient, $this->domain);
108108

109109
return $client;
110110
}

tests/MindboxTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class MindboxTest extends TestCase
2929
'endpointId' => 'test',
3030
'secretKey' => 'test',
3131
'domain' => 'test',
32+
'domainZone' => 'test',
3233
];
3334

3435
public function setUp()
@@ -47,27 +48,31 @@ public function incorrectConfigProvider()
4748
'endpointId' => '',
4849
'secretKey' => 'test',
4950
'domain' => 'test',
51+
'domainZone' => 'test',
5052
],
5153
],
5254
[
5355
[
5456
'endpointId' => 'test',
5557
'secretKey' => '',
5658
'domain' => 'test',
59+
'domainZone' => 'test',
5760
],
5861
],
5962
[
6063
[
6164
'endpointId' => 'test',
6265
'secretKey' => 'test',
6366
'domain' => '',
67+
'domainZone' => '',
6468
],
6569
],
6670
[
6771
[
6872
'endpointId' => 'test',
6973
'secretKey' => 'test',
7074
'domain' => 'test',
75+
'domainZone' => 'test',
7176
'httpClient' => 'test',
7277
],
7378
],

0 commit comments

Comments
 (0)