2021-11-17 16:01:53 +00:00
|
|
|
|
<?php
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
|
|
|
|
*
|
|
|
|
|
* This code is licensed under MIT.
|
|
|
|
|
* Этот код распространяется по лицензии MIT.
|
|
|
|
|
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
declare(strict_types = 1);
|
|
|
|
|
|
|
|
|
|
namespace AtolOnline\Api;
|
|
|
|
|
|
2021-11-20 15:38:19 +00:00
|
|
|
|
use AtolOnline\Entities\Kkt;
|
|
|
|
|
use AtolOnline\Exceptions\EmptyMonitorDataException;
|
|
|
|
|
use AtolOnline\Exceptions\NotEnoughMonitorDataException;
|
2021-11-17 16:01:53 +00:00
|
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
2021-11-19 10:29:09 +00:00
|
|
|
|
use Illuminate\Support\Collection;
|
2021-11-17 16:01:53 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Класс для мониторинга ККТ
|
|
|
|
|
*
|
|
|
|
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация
|
|
|
|
|
*/
|
|
|
|
|
class KktMonitor extends AtolClient
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
protected function getAuthEndpoint(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->isTestMode()
|
|
|
|
|
? 'https://testonline.atol.ru/api/auth/v1/gettoken'
|
|
|
|
|
: 'https://online.atol.ru/api/auth/v1/gettoken';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
|
|
|
|
*/
|
|
|
|
|
protected function getMainEndpoint(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->isTestMode()
|
|
|
|
|
? 'https://testonline.atol.ru/api/kkt/v1'
|
|
|
|
|
: 'https://online.atol.ru/api/kkt/v1';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получает от API информацию обо всех ККТ и ФН в рамках группы
|
|
|
|
|
*
|
|
|
|
|
* @param int|null $limit
|
|
|
|
|
* @param int|null $offset
|
|
|
|
|
* @return KktResponse
|
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9
|
|
|
|
|
*/
|
|
|
|
|
protected function fetchAll(?int $limit = null, ?int $offset = null): KktResponse
|
|
|
|
|
{
|
|
|
|
|
$params = [];
|
2021-11-22 06:52:27 +00:00
|
|
|
|
!is_null($limit) && $params['limit'] = $limit;
|
|
|
|
|
!is_null($offset) && $params['offset'] = $offset;
|
2021-11-17 16:01:53 +00:00
|
|
|
|
return $this->sendRequest('GET', self::getUrlToMethod('cash-registers'), $params);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает информацию обо всех ККТ и ФН в рамках группы
|
|
|
|
|
*
|
|
|
|
|
* @param int|null $limit
|
|
|
|
|
* @param int|null $offset
|
2021-11-19 10:29:09 +00:00
|
|
|
|
* @return Collection
|
2021-11-17 16:01:53 +00:00
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9
|
|
|
|
|
*/
|
2021-11-19 10:29:09 +00:00
|
|
|
|
public function getAll(?int $limit = null, ?int $offset = null): Collection
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
2021-11-20 15:38:19 +00:00
|
|
|
|
$collection = collect($this->fetchAll($limit, $offset)->getContent());
|
|
|
|
|
return $collection->map(fn($data) => new Kkt($data));
|
2021-11-17 16:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Получает от API информацию о конкретной ККТ по её серийному номеру
|
|
|
|
|
*
|
|
|
|
|
* @param string $serial_number
|
|
|
|
|
* @return KktResponse
|
|
|
|
|
* @throws GuzzleException
|
|
|
|
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 11
|
|
|
|
|
*/
|
|
|
|
|
protected function fetchOne(string $serial_number): KktResponse
|
|
|
|
|
{
|
|
|
|
|
return $this->sendRequest(
|
|
|
|
|
'GET',
|
|
|
|
|
self::getUrlToMethod('cash-registers') . '/' . trim($serial_number),
|
|
|
|
|
options: [
|
|
|
|
|
'headers' => [
|
|
|
|
|
'Accept' => 'application/hal+json',
|
|
|
|
|
],
|
|
|
|
|
]
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Возвращает информацию о конкретной ККТ по её серийному номеру
|
|
|
|
|
*
|
|
|
|
|
* @param string $serial_number
|
2021-11-20 15:38:19 +00:00
|
|
|
|
* @return Kkt
|
2021-11-17 16:01:53 +00:00
|
|
|
|
* @throws GuzzleException
|
2021-11-20 15:38:19 +00:00
|
|
|
|
* @throws EmptyMonitorDataException
|
|
|
|
|
* @throws NotEnoughMonitorDataException
|
2021-11-17 16:01:53 +00:00
|
|
|
|
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 11
|
|
|
|
|
*/
|
2021-11-20 15:38:19 +00:00
|
|
|
|
public function getOne(string $serial_number): Kkt
|
2021-11-17 16:01:53 +00:00
|
|
|
|
{
|
2021-11-20 15:38:19 +00:00
|
|
|
|
return new Kkt($this->fetchOne($serial_number)->getContent()->data);
|
2021-11-17 16:01:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|