Большие доработки по фискилизации

- у `AtolClient` теперь возможно получить последний отправленный запрос `getLastRequest()`
- у `AtolClient::auth()` удалены аргументы за ненадобностью
- улучшен `Client::jsonSerialize()`
- исправлен `Receipt::jsonSerialize()`
- у `Receipt` и `Correction` появились методы фискализации, вкусный сахарок
- удалён енам `DocumentTypes` за ненадобностью
- исправлены тесты монитора и документов
- рабочий фискализатор с получением результатов и покрытием
This commit is contained in:
2021-12-18 14:45:00 +08:00
parent b4cc0fec53
commit 71d1f2900c
33 changed files with 969 additions and 336 deletions

View File

@@ -29,6 +29,16 @@ use JetBrains\PhpStorm\Pure;
*/
abstract class AtolClient
{
/**
* @var array Последний запрос к серверу АТОЛ
*/
protected array $request;
/**
* @var KktResponse|null Последний ответ сервера АТОЛ
*/
protected ?KktResponse $response;
/**
* @var bool Флаг тестового режима
*/
@@ -54,11 +64,6 @@ abstract class AtolClient
*/
private ?string $token = null;
/**
* @var KktResponse|null Последний ответ сервера АТОЛ
*/
private ?KktResponse $response;
/**
* Конструктор
*
@@ -88,6 +93,26 @@ abstract class AtolClient
!is_null($password) && $this->setPassword($password);
}
/**
* Возвращает последний запрос к серверу
*
* @return array
*/
public function getLastRequest(): array
{
return $this->request;
}
/**
* Возвращает последний ответ сервера
*
* @return KktResponse|null
*/
public function getLastResponse(): ?KktResponse
{
return $this->response;
}
/**
* Возвращает установленный флаг тестового режима
*
@@ -132,16 +157,6 @@ abstract class AtolClient
return $this;
}
/**
* Возвращает последний ответ сервера
*
* @return KktResponse|null
*/
public function getResponse(): ?KktResponse
{
return $this->response;
}
/**
* Возвращает логин доступа к API
*
@@ -273,36 +288,29 @@ abstract class AtolClient
): KktResponse {
$http_method = strtoupper(trim($http_method));
$options['headers'] = array_merge($this->getHeaders(), $options['headers'] ?? []);
if ($http_method != 'GET') {
$options['json'] = $data;
}
$http_method != 'GET' && $options['json'] = $data;
$this->request = array_merge([
'method' => $http_method,
'url' => $url,
], $options);
$response = $this->http->request($http_method, $url, $options);
return $this->response = new KktResponse($response);
}
/**
* Выполняет авторизацию на сервере АТОЛ
*
* Авторизация выполнится только если неизвестен токен
*
* @param string|null $login
* @param string|null $password
* @return bool
* @throws AuthFailedException
* @throws TooLongLoginException
* @throws EmptyLoginException
* @throws EmptyPasswordException
* @throws TooLongPasswordException
* @throws GuzzleException
*/
public function auth(?string $login = null, ?string $password = null): bool
public function auth(): bool
{
if (empty($this->getToken())) {
!is_null($login) && $this->setLogin($login);
!is_null($password) && $this->setPassword($password);
if ($token = $this->doAuth()) {
$this->setToken($token);
}
if (empty($this->getToken()) && $token = $this->doAuth()) {
$this->setToken($token);
}
return !empty($this->getToken());
}
@@ -320,4 +328,5 @@ abstract class AtolClient
* @return string
*/
abstract protected function getMainEndpoint(): string;
}