Skip to content

Commit a04e20a

Browse files
authored
Merge pull request #16 from mindbox-moscow/MBM-8
MBM-8
2 parents 2da8ca3 + 2930b04 commit a04e20a

15 files changed

+90
-84
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ before_install:
2525
install:
2626
- travis_retry composer install --prefer-dist --no-interaction
2727

28+
before_script:
29+
- export XDEBUG_MODE=coverage
30+
2831
# Run scripts
2932
script:
3033
- vendor/bin/phpcs

docs/structure/Mindbox-DTO-V2-Requests-SubscriptionRequestDTO.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,6 @@ Methods
190190

191191

192192

193-
### getValueByDefault
194-
195-
string Mindbox\DTO\V2\Requests\SubscriptionRequestDTO::getValueByDefault()
196-
197-
198-
199-
200-
201-
* Visibility: **public**
202-
203-
204-
205-
206193
### setValueByDefault
207194

208195
mixed Mindbox\DTO\V2\Requests\SubscriptionRequestDTO::setValueByDefault(mixed $valueByDefault)

docs/structure/Mindbox-DTO-V3-Requests-SubscriptionRequestDTO.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,6 @@ Methods
190190

191191

192192

193-
### getValueByDefault
194-
195-
string Mindbox\DTO\V3\Requests\SubscriptionRequestDTO::getValueByDefault()
196-
197-
198-
199-
200-
201-
* Visibility: **public**
202-
203-
204-
205193

206194
### setValueByDefault
207195

src/Clients/AbstractMindboxClient.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ abstract class AbstractMindboxClient
5151
*/
5252
protected $responseType;
5353

54+
/**
55+
* @var array $headers Поля хедера для запроса.
56+
*/
57+
protected $headers;
58+
5459
/**
5560
* Конструктор AbstractMindboxClient.
5661
*
@@ -64,6 +69,7 @@ public function __construct($secretKey, IHttpClient $httpClient, LoggerInterface
6469
$this->httpClient = $httpClient;
6570
$this->logger = $logger;
6671
$this->responseType = MindboxResponse::class;
72+
$this->headers = $this->getDefaultHeaders();
6773
}
6874

6975
/**
@@ -184,17 +190,11 @@ abstract protected function prepareUrl($additionalUrl, array $queryParams, $isSy
184190
/**
185191
* Подготовка массива заголовков запроса.
186192
*
187-
* @param bool $addDeviceUUID Флаг: добавлять ли в запрос DeviceUUID.
188-
*
189193
* @return array
190194
*/
191-
protected function prepareHeaders($addDeviceUUID = true)
195+
protected function prepareHeaders()
192196
{
193-
return [
194-
'Accept' => 'application/json',
195-
'Content-Type' => 'application/json',
196-
'Authorization' => $this->prepareAuthorizationHeader(),
197-
];
197+
return $this->headers;
198198
}
199199

200200
/**
@@ -378,4 +378,37 @@ public function setResponseType($type)
378378
}
379379
$this->responseType = $type;
380380
}
381+
382+
/**
383+
* Возвращает стандартные заголовки запроса.
384+
*
385+
* @return array
386+
*/
387+
protected function getDefaultHeaders()
388+
{
389+
return [
390+
'Accept' => 'application/json',
391+
'Content-Type' => 'application/json',
392+
'Authorization' => $this->prepareAuthorizationHeader(),
393+
'Mindbox-Integration' => 'PhpSDK',
394+
'Mindbox-Integration-Version' => '1.0'
395+
];
396+
}
397+
398+
/**
399+
* Добавляет заголовок запроса.
400+
*
401+
* @param array $headers Заголовок или массив заголовков.
402+
*
403+
* Пример:
404+
*
405+
* ['Mindbox-Integration' => 'PhpSDK']
406+
*
407+
*/
408+
public function addHeaders(array $headers)
409+
{
410+
if (is_array($headers)) {
411+
$this->headers = array_merge($this->headers, $headers);
412+
}
413+
}
381414
}

src/DTO/V2/Requests/SubscriptionRequestDTO.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ public function setBrand($brand)
4545
$this->setField('brand', $brand);
4646
}
4747

48-
/**
49-
* @return string
50-
*/
51-
public function getValueByDefault()
52-
{
53-
return $this->getField('valueByDefault');
54-
}
55-
5648
/**
5749
* @param mixed $valueByDefault
5850
*/

src/DTO/V3/Requests/SubscriptionRequestDTO.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ public function setBrand($brand)
4545
$this->setField('brand', $brand);
4646
}
4747

48-
/**
49-
* @return string
50-
*/
51-
public function getValueByDefault()
52-
{
53-
return $this->getField('valueByDefault');
54-
}
55-
5648
/**
5749
* @param mixed $valueByDefault
5850
*/

src/Helpers/CustomerHelper.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,32 @@ public function confirmMobile(
360360
*
361361
* @return \Mindbox\Clients\AbstractMindboxClient
362362
*/
363+
public function subscribeCustomer(
364+
CustomerRequestDTO $customer,
365+
$operationName,
366+
$addDeviceUUID = false,
367+
$isSync = true
368+
) {
369+
$operation = $this->createOperation();
370+
$operation->setCustomer($customer);
371+
372+
$this->client->setResponseType(MindboxCustomerResponse::class);
373+
374+
return $this->client->prepareRequest('POST', $operationName, $operation, '', [], $isSync, $addDeviceUUID);
375+
}
376+
377+
/**
378+
* Выполняет вызов стандартной операции Website.Subscribe:
379+
*
380+
* @see https://developers.mindbox.ru/v3.0/docs/json
381+
*
382+
* @param CustomerRequestDTO $customer Объект, содержащий данные потребителя для запроса.
383+
* @param string $operationName Название операции.
384+
* @param bool $addDeviceUUID Флаг, сообщающий о необходимости передать в запросе DeviceUUID.
385+
* @param bool $isSync Флаг, сообщающий о необходимости выполнять запрос синхронно/асинхронно.
386+
*
387+
* @return \Mindbox\Clients\AbstractMindboxClient
388+
*/
363389
public function subscribe(
364390
CustomerRequestDTO $customer,
365391
$operationName,

src/Mindbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function __construct(array $config, LoggerInterface $logger)
102102
*
103103
* @param array $config Массив, содержащий конфигурацию.
104104
*/
105-
protected function setConfig(array $config)
105+
private function setConfig(array $config)
106106
{
107107
$this->config = array_merge($this->getDefaultConfig(), $config);
108108
}

tests/Clients/AbstractMindboxClientTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AbstractMindboxClientTest extends TestCase
2929
/**
3030
* @var string
3131
*/
32-
private $authHeader = 'authHeader';
32+
private $authHeader = null;
3333

3434
/**
3535
* @var \PHPUnit\Framework\MockObject\MockObject|\Mindbox\HttpClients\AbstractHttpClient
@@ -80,6 +80,8 @@ public function expectedArgsForSendProvider()
8080
'Accept' => 'application/json',
8181
'Content-Type' => 'application/json',
8282
'Authorization' => $this->authHeader,
83+
'Mindbox-Integration' => 'PhpSDK',
84+
'Mindbox-Integration-Version' => '1.0'
8385
],
8486
],
8587
],
@@ -98,8 +100,11 @@ public function expectedArgsForSendProvider()
98100
'body' => $this->getDTOStub()->toJson(),
99101
'headers' => [
100102
'Accept' => 'application/json',
101-
'Content-Type' => 'application/json',
103+
'Content-Type' => 'application/json',
102104
'Authorization' => $this->authHeader,
105+
'Mindbox-Integration' => 'PhpSDK',
106+
'Mindbox-Integration-Version' => '1.0'
107+
103108
],
104109
],
105110
],

tests/Clients/MindboxClientV2Test.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function expectedArgsForSendProvider()
3131
'Accept' => 'application/xml',
3232
'Content-Type' => 'application/xml',
3333
'Authorization' => 'DirectCrm key="' . $this->secret . '"',
34+
'Mindbox-Integration' => 'PhpSDK',
35+
'Mindbox-Integration-Version' => '1.0'
3436
],
3537
],
3638
],
@@ -51,6 +53,8 @@ public function expectedArgsForSendProvider()
5153
'Accept' => 'application/xml',
5254
'Content-Type' => 'application/xml',
5355
'Authorization' => 'DirectCrm key="' . $this->secret . '"',
56+
'Mindbox-Integration' => 'PhpSDK',
57+
'Mindbox-Integration-Version' => '1.0'
5458
],
5559
],
5660
],

0 commit comments

Comments
 (0)