Skip to content

Commit 6e58720

Browse files
committed
add client name and version to all headers. Closes #37
1 parent 6244c3a commit 6e58720

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ $config = new \igorbunov\Checkbox\Config([
4343
\igorbunov\Checkbox\Config::LOGIN => 'логин кассира',
4444
\igorbunov\Checkbox\Config::PASSWORD => 'пароль кассира', //or
4545
\igorbunov\Checkbox\Config::PINCODE => 02301230440,
46-
\igorbunov\Checkbox\Config::LICENSE_KEY => 'ключ лицензии кассы'
46+
\igorbunov\Checkbox\Config::LICENSE_KEY => 'ключ лицензии кассы',
47+
\igorbunov\Checkbox\Config::HEADER_CLIENT_NAME => 'Igorbunov Custom SDK', // не обязательный (Igorbunov Custom SDK по умолчанию)
48+
\igorbunov\Checkbox\Config::HEADER_CLIENT_VERSION => '1.3.7', // не обязательный
4749
]);
4850
```
4951

@@ -599,4 +601,3 @@ composer unit-tests
599601
600602
composer all-tests
601603
```
602-

src/CheckboxJsonApi.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
namespace igorbunov\Checkbox;
44

55
use GuzzleHttp\Client;
6-
use igorbunov\Checkbox\Errors\AlreadyOpenedShift;
7-
use igorbunov\Checkbox\Errors\BadRequest;
86
use igorbunov\Checkbox\Errors\BadRequestExceptionFactory;
97
use igorbunov\Checkbox\Errors\EmptyResponse;
108
use igorbunov\Checkbox\Errors\InvalidCredentials;
11-
use igorbunov\Checkbox\Errors\NoActiveShift;
129
use igorbunov\Checkbox\Errors\Validation;
1310
use igorbunov\Checkbox\Mappers\Cashier\CashierMapper;
1411
use igorbunov\Checkbox\Mappers\CashRegisters\CashRegisterInfoMapper;
@@ -51,7 +48,6 @@
5148
use igorbunov\Checkbox\Models\Transactions\Transactions;
5249
use igorbunov\Checkbox\Models\Transactions\TransactionsQueryParams;
5350
use Psr\Http\Message\ResponseInterface;
54-
use Psr\Http\Message\StreamInterface;
5551

5652
class CheckboxJsonApi
5753
{
@@ -99,7 +95,9 @@ public function __construct(Config $config, int $connectTimeoutSeconds = 5)
9995
'connect_timeout' => $this->connectTimeout,
10096
'headers' => [
10197
'Content-Type' => 'application/json',
102-
'X-License-Key' => $this->config->get('licenseKey')
98+
'X-License-Key' => $this->config->get(Config::LICENSE_KEY),
99+
'X-Client-Name' => $this->config->get(Config::HEADER_CLIENT_NAME),
100+
'X-Client-Version' => $this->config->get(Config::HEADER_CLIENT_VERSION),
103101
]
104102
];
105103
}
@@ -586,14 +584,10 @@ public function getAllTaxes(): ?GoodTaxes
586584

587585
public function createXReport(): ?ZReport
588586
{
589-
$options = $this->requestOptions;
590-
$options['headers']['X-Client-Name'] = 'Igorbunov Custom SDK';
591-
$options['headers']['X-Client-Version'] = '1.0.0';
592-
593587
$response = $this->sendRequest(
594588
self::METHOD_POST,
595589
$this->routes->createXReport(),
596-
$options
590+
$this->requestOptions
597591
);
598592

599593
$jsonResponse = json_decode($response->getBody()->getContents(), true);

src/Config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Config
1414
public const PASSWORD = 'password';
1515
public const PINCODE = 'pin_code';
1616
public const LICENSE_KEY = 'licenseKey';
17+
public const HEADER_CLIENT_NAME = 'header_client_name';
18+
public const HEADER_CLIENT_VERSION = 'header_client_version';
1719

1820
/**
1921
* Constructor
@@ -24,6 +26,11 @@ class Config
2426
public function __construct(array $data)
2527
{
2628
$this->data = $data;
29+
30+
if (!array_key_exists(self::HEADER_CLIENT_NAME, $data)) {
31+
$data[self::HEADER_CLIENT_NAME] = 'Igorbunov Custom SDK';
32+
$data[self::HEADER_CLIENT_VERSION] = '1.3.7';
33+
}
2734
}
2835

2936
public function get(string $name): string

0 commit comments

Comments
 (0)