Skip to content

Commit

Permalink
add client name and version to all headers. Closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
igorbunov committed Feb 17, 2025
1 parent 6244c3a commit 6e58720
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ $config = new \igorbunov\Checkbox\Config([
\igorbunov\Checkbox\Config::LOGIN => 'логин кассира',
\igorbunov\Checkbox\Config::PASSWORD => 'пароль кассира', //or
\igorbunov\Checkbox\Config::PINCODE => 02301230440,
\igorbunov\Checkbox\Config::LICENSE_KEY => 'ключ лицензии кассы'
\igorbunov\Checkbox\Config::LICENSE_KEY => 'ключ лицензии кассы',
\igorbunov\Checkbox\Config::HEADER_CLIENT_NAME => 'Igorbunov Custom SDK', // не обязательный (Igorbunov Custom SDK по умолчанию)
\igorbunov\Checkbox\Config::HEADER_CLIENT_VERSION => '1.3.7', // не обязательный
]);
```

Expand Down Expand Up @@ -599,4 +601,3 @@ composer unit-tests
composer all-tests
```

14 changes: 4 additions & 10 deletions src/CheckboxJsonApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace igorbunov\Checkbox;

use GuzzleHttp\Client;
use igorbunov\Checkbox\Errors\AlreadyOpenedShift;
use igorbunov\Checkbox\Errors\BadRequest;
use igorbunov\Checkbox\Errors\BadRequestExceptionFactory;
use igorbunov\Checkbox\Errors\EmptyResponse;
use igorbunov\Checkbox\Errors\InvalidCredentials;
use igorbunov\Checkbox\Errors\NoActiveShift;
use igorbunov\Checkbox\Errors\Validation;
use igorbunov\Checkbox\Mappers\Cashier\CashierMapper;
use igorbunov\Checkbox\Mappers\CashRegisters\CashRegisterInfoMapper;
Expand Down Expand Up @@ -51,7 +48,6 @@
use igorbunov\Checkbox\Models\Transactions\Transactions;
use igorbunov\Checkbox\Models\Transactions\TransactionsQueryParams;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;

class CheckboxJsonApi
{
Expand Down Expand Up @@ -99,7 +95,9 @@ public function __construct(Config $config, int $connectTimeoutSeconds = 5)
'connect_timeout' => $this->connectTimeout,
'headers' => [
'Content-Type' => 'application/json',
'X-License-Key' => $this->config->get('licenseKey')
'X-License-Key' => $this->config->get(Config::LICENSE_KEY),
'X-Client-Name' => $this->config->get(Config::HEADER_CLIENT_NAME),
'X-Client-Version' => $this->config->get(Config::HEADER_CLIENT_VERSION),
]
];
}
Expand Down Expand Up @@ -586,14 +584,10 @@ public function getAllTaxes(): ?GoodTaxes

public function createXReport(): ?ZReport
{
$options = $this->requestOptions;
$options['headers']['X-Client-Name'] = 'Igorbunov Custom SDK';
$options['headers']['X-Client-Version'] = '1.0.0';

$response = $this->sendRequest(
self::METHOD_POST,
$this->routes->createXReport(),
$options
$this->requestOptions
);

$jsonResponse = json_decode($response->getBody()->getContents(), true);
Expand Down
7 changes: 7 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class Config
public const PASSWORD = 'password';
public const PINCODE = 'pin_code';
public const LICENSE_KEY = 'licenseKey';
public const HEADER_CLIENT_NAME = 'header_client_name';
public const HEADER_CLIENT_VERSION = 'header_client_version';

/**
* Constructor
Expand All @@ -24,6 +26,11 @@ class Config
public function __construct(array $data)
{
$this->data = $data;

if (!array_key_exists(self::HEADER_CLIENT_NAME, $data)) {
$data[self::HEADER_CLIENT_NAME] = 'Igorbunov Custom SDK';
$data[self::HEADER_CLIENT_VERSION] = '1.3.7';
}
}

public function get(string $name): string
Expand Down

0 comments on commit 6e58720

Please sign in to comment.