Переименования классов для пущей простоты

pull/15/head
Anthony Axenov 2021-12-19 22:29:17 +08:00
parent 71d1f2900c
commit fdc5ab112a
10 changed files with 199 additions and 216 deletions

View File

@ -35,9 +35,9 @@ abstract class AtolClient
protected array $request; protected array $request;
/** /**
* @var KktResponse|null Последний ответ сервера АТОЛ * @var AtolResponse|null Последний ответ сервера АТОЛ
*/ */
protected ?KktResponse $response; protected ?AtolResponse $response;
/** /**
* @var bool Флаг тестового режима * @var bool Флаг тестового режима
@ -106,9 +106,9 @@ abstract class AtolClient
/** /**
* Возвращает последний ответ сервера * Возвращает последний ответ сервера
* *
* @return KktResponse|null * @return AtolResponse|null
*/ */
public function getLastResponse(): ?KktResponse public function getLastResponse(): ?AtolResponse
{ {
return $this->response; return $this->response;
} }
@ -263,7 +263,7 @@ abstract class AtolClient
'login' => $this->getLogin() ?? throw new EmptyLoginException(), 'login' => $this->getLogin() ?? throw new EmptyLoginException(),
'pass' => $this->getPassword() ?? throw new EmptyPasswordException(), 'pass' => $this->getPassword() ?? throw new EmptyPasswordException(),
]); ]);
if (!$result->isValid() || !$result->getContent()->token) { if (!$result->isSuccessful() || !$result->getContent()->token) {
throw new AuthFailedException($result); throw new AuthFailedException($result);
} }
return $result->getContent()?->token; return $result->getContent()?->token;
@ -276,7 +276,7 @@ abstract class AtolClient
* @param string $url URL * @param string $url URL
* @param array|null $data Данные для передачи * @param array|null $data Данные для передачи
* @param array|null $options Параметры Guzzle * @param array|null $options Параметры Guzzle
* @return KktResponse * @return AtolResponse
* @throws GuzzleException * @throws GuzzleException
* @see https://guzzle.readthedocs.io/en/latest/request-options.html * @see https://guzzle.readthedocs.io/en/latest/request-options.html
*/ */
@ -285,7 +285,7 @@ abstract class AtolClient
string $url, string $url,
?array $data = null, ?array $data = null,
?array $options = null ?array $options = null
): KktResponse { ): AtolResponse {
$http_method = strtoupper(trim($http_method)); $http_method = strtoupper(trim($http_method));
$options['headers'] = array_merge($this->getHeaders(), $options['headers'] ?? []); $options['headers'] = array_merge($this->getHeaders(), $options['headers'] ?? []);
$http_method != 'GET' && $options['json'] = $data; $http_method != 'GET' && $options['json'] = $data;
@ -294,7 +294,7 @@ abstract class AtolClient
'url' => $url, 'url' => $url,
], $options); ], $options);
$response = $this->http->request($http_method, $url, $options); $response = $this->http->request($http_method, $url, $options);
return $this->response = new KktResponse($response); return $this->response = new AtolResponse($response);
} }
/** /**
@ -328,5 +328,4 @@ abstract class AtolClient
* @return string * @return string
*/ */
abstract protected function getMainEndpoint(): string; abstract protected function getMainEndpoint(): string;
} }

View File

@ -27,7 +27,7 @@ use Stringable;
* @property mixed $error * @property mixed $error
* @package AtolOnline\Api * @package AtolOnline\Api
*/ */
class KktResponse implements JsonSerializable, Stringable class AtolResponse implements JsonSerializable, Stringable
{ {
/** /**
* @var int Код ответа сервера * @var int Код ответа сервера
@ -104,7 +104,7 @@ class KktResponse implements JsonSerializable, Stringable
* @return bool * @return bool
*/ */
#[Pure] #[Pure]
public function isValid(): bool public function isSuccessful(): bool
{ {
return !empty($this->getCode()) return !empty($this->getCode())
&& !empty($this->getContent()) && !empty($this->getContent())

View File

@ -38,7 +38,7 @@ use Ramsey\Uuid\Uuid;
/** /**
* Класс фискализатора для регистрации документов на ККТ * Класс фискализатора для регистрации документов на ККТ
*/ */
class KktFiscalizer extends AtolClient class Fiscalizer extends AtolClient
{ {
/** /**
* @var string|null Группа ККТ * @var string|null Группа ККТ
@ -139,7 +139,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Receipt $receipt Объект документа * @param Receipt $receipt Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -149,7 +149,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sell(Receipt $receipt, ?string $external_id = null): ?KktResponse public function sell(Receipt $receipt, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('sell', $receipt, $external_id); return $this->registerDocument('sell', $receipt, $external_id);
} }
@ -159,7 +159,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Receipt $receipt Объект документа * @param Receipt $receipt Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -169,7 +169,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sellRefund(Receipt $receipt, ?string $external_id = null): ?KktResponse public function sellRefund(Receipt $receipt, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('sell_refund', $receipt, $external_id); return $this->registerDocument('sell_refund', $receipt, $external_id);
} }
@ -179,7 +179,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Correction $correction Объект документа * @param Correction $correction Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -189,7 +189,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sellCorrect(Correction $correction, ?string $external_id = null): ?KktResponse public function sellCorrect(Correction $correction, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('sell_correction', $correction, $external_id); return $this->registerDocument('sell_correction', $correction, $external_id);
} }
@ -199,7 +199,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Receipt $receipt Объект документа * @param Receipt $receipt Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -209,7 +209,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buy(Receipt $receipt, ?string $external_id = null): ?KktResponse public function buy(Receipt $receipt, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('buy', $receipt, $external_id); return $this->registerDocument('buy', $receipt, $external_id);
} }
@ -219,7 +219,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Receipt $receipt Объект документа * @param Receipt $receipt Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -229,7 +229,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buyRefund(Receipt $receipt, ?string $external_id = null): ?KktResponse public function buyRefund(Receipt $receipt, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('buy_refund', $receipt, $external_id); return $this->registerDocument('buy_refund', $receipt, $external_id);
} }
@ -239,7 +239,7 @@ class KktFiscalizer extends AtolClient
* *
* @param Correction $correction Объект документа * @param Correction $correction Объект документа
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -249,7 +249,7 @@ class KktFiscalizer extends AtolClient
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buyCorrect(Correction $correction, ?string $external_id = null): ?KktResponse public function buyCorrect(Correction $correction, ?string $external_id = null): ?AtolResponse
{ {
return $this->registerDocument('buy_correction', $correction, $external_id); return $this->registerDocument('buy_correction', $correction, $external_id);
} }
@ -258,14 +258,14 @@ class KktFiscalizer extends AtolClient
* Проверяет статус чека на ККТ один раз * Проверяет статус чека на ККТ один раз
* *
* @param string $uuid UUID регистрации * @param string $uuid UUID регистрации
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidUuidException * @throws InvalidUuidException
*/ */
public function getDocumentStatus(string $uuid): ?KktResponse public function getDocumentStatus(string $uuid): ?AtolResponse
{ {
!Uuid::isValid($uuid = trim($uuid)) && throw new InvalidUuidException($uuid); !Uuid::isValid($uuid = trim($uuid)) && throw new InvalidUuidException($uuid);
return $this->auth() return $this->auth()
@ -280,19 +280,19 @@ class KktFiscalizer extends AtolClient
* @param string $uuid UUID регистрации * @param string $uuid UUID регистрации
* @param int $retry_count Количество попыток * @param int $retry_count Количество попыток
* @param int $timeout Таймаут в секундах между попытками * @param int $timeout Таймаут в секундах между попытками
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidUuidException * @throws InvalidUuidException
*/ */
public function pollDocumentStatus(string $uuid, int $retry_count = 5, int $timeout = 1): ?KktResponse public function pollDocumentStatus(string $uuid, int $retry_count = 5, int $timeout = 1): ?AtolResponse
{ {
$try = 0; $try = 0;
do { do {
$response = $this->getDocumentStatus($uuid); $response = $this->getDocumentStatus($uuid);
if ($response->isValid() && $response->getContent()->status == 'done') { if ($response->isSuccessful() && $response->getContent()->status == 'done') {
break; break;
} else { } else {
sleep($timeout); sleep($timeout);
@ -308,7 +308,7 @@ class KktFiscalizer extends AtolClient
* @param string $api_method Метод API * @param string $api_method Метод API
* @param Receipt|Correction $document Документ * @param Receipt|Correction $document Документ
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -322,7 +322,7 @@ class KktFiscalizer extends AtolClient
string $api_method, string $api_method,
Receipt|Correction $document, Receipt|Correction $document,
?string $external_id = null ?string $external_id = null
): ?KktResponse { ): ?AtolResponse {
$this->isTestMode() && $document->getCompany() $this->isTestMode() && $document->getCompany()
->setInn(TestEnvParams::FFD105()['inn']) ->setInn(TestEnvParams::FFD105()['inn'])
->setPaymentAddress(TestEnvParams::FFD105()['payment_address']); ->setPaymentAddress(TestEnvParams::FFD105()['payment_address']);

View File

@ -27,7 +27,7 @@ use JetBrains\PhpStorm\Pure;
* *
* @see https://online.atol.ru/files/API_service_information.pdf Документация * @see https://online.atol.ru/files/API_service_information.pdf Документация
*/ */
class KktMonitor extends AtolClient class Monitor extends AtolClient
{ {
/** /**
* @inheritDoc * @inheritDoc
@ -56,14 +56,14 @@ class KktMonitor extends AtolClient
* *
* @param int|null $limit * @param int|null $limit
* @param int|null $offset * @param int|null $offset
* @return KktResponse|null * @return AtolResponse|null
* @throws GuzzleException * @throws GuzzleException
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9 * @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 9
*/ */
protected function fetchAll(?int $limit = null, ?int $offset = null): ?KktResponse protected function fetchAll(?int $limit = null, ?int $offset = null): ?AtolResponse
{ {
$params = []; $params = [];
!is_null($limit) && $params['limit'] = $limit; !is_null($limit) && $params['limit'] = $limit;
@ -95,11 +95,11 @@ class KktMonitor extends AtolClient
* Получает от API информацию о конкретной ККТ по её серийному номеру * Получает от API информацию о конкретной ККТ по её серийному номеру
* *
* @param string $serial_number * @param string $serial_number
* @return KktResponse * @return AtolResponse
* @throws GuzzleException * @throws GuzzleException
* @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 11 * @see https://online.atol.ru/files/API_service_information.pdf Документация, стр 11
*/ */
protected function fetchOne(string $serial_number): KktResponse protected function fetchOne(string $serial_number): AtolResponse
{ {
return $this->sendRequest( return $this->sendRequest(
'GET', 'GET',

View File

@ -10,8 +10,8 @@
namespace AtolOnline\Entities; namespace AtolOnline\Entities;
use AtolOnline\{ use AtolOnline\{
Api\KktFiscalizer, Api\AtolResponse,
Api\KktResponse, Api\Fiscalizer,
Collections\Payments, Collections\Payments,
Collections\Vats, Collections\Vats,
Constants\Constraints}; Constants\Constraints};
@ -211,9 +211,9 @@ class Correction extends Entity
/** /**
* Регистрирует коррекцию прихода по текущему документу * Регистрирует коррекцию прихода по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -223,7 +223,7 @@ class Correction extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sellCorrect(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function sellCorrect(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->sellCorrect($this, $external_id); return $fiscalizer->sellCorrect($this, $external_id);
} }
@ -231,9 +231,9 @@ class Correction extends Entity
/** /**
* Регистрирует коррекцию расхода по текущему документу * Регистрирует коррекцию расхода по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -243,7 +243,7 @@ class Correction extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buyCorrect(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function buyCorrect(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->buyCorrect($this, $external_id); return $fiscalizer->buyCorrect($this, $external_id);
} }

View File

@ -38,7 +38,7 @@ abstract class Entity implements JsonSerializable, Stringable, Arrayable, ArrayA
'correction_info' => "\AtolOnline\Entities\CorrectionInfo", 'correction_info' => "\AtolOnline\Entities\CorrectionInfo",
'payments' => "array", 'payments' => "array",
'vats' => "\AtolOnline\Collections\Vats|null", 'vats' => "\AtolOnline\Collections\Vats|null",
'cashier' => "\null|string" 'cashier' => "null|string",
])] ])]
public function toArray() public function toArray()
{ {

View File

@ -11,8 +11,8 @@ declare(strict_types = 1);
namespace AtolOnline\Entities; namespace AtolOnline\Entities;
use AtolOnline\Api\KktFiscalizer; use AtolOnline\Api\AtolResponse;
use AtolOnline\Api\KktResponse; use AtolOnline\Api\Fiscalizer;
use AtolOnline\Collections\Items; use AtolOnline\Collections\Items;
use AtolOnline\Collections\Payments; use AtolOnline\Collections\Payments;
use AtolOnline\Collections\Vats; use AtolOnline\Collections\Vats;
@ -377,9 +377,9 @@ final class Receipt extends Entity
/** /**
* Регистрирует приход по текущему документу * Регистрирует приход по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -389,7 +389,7 @@ final class Receipt extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sell(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function sell(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->sell($this, $external_id); return $fiscalizer->sell($this, $external_id);
} }
@ -397,9 +397,9 @@ final class Receipt extends Entity
/** /**
* Регистрирует возврат прихода по текущему документу * Регистрирует возврат прихода по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -409,7 +409,7 @@ final class Receipt extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function sellRefund(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function sellRefund(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->sellRefund($this, $external_id); return $fiscalizer->sellRefund($this, $external_id);
} }
@ -417,9 +417,9 @@ final class Receipt extends Entity
/** /**
* Регистрирует расход по текущему документу * Регистрирует расход по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -429,7 +429,7 @@ final class Receipt extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buy(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function buy(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->buy($this, $external_id); return $fiscalizer->buy($this, $external_id);
} }
@ -437,9 +437,9 @@ final class Receipt extends Entity
/** /**
* Регистрирует возврат расхода по текущему документу * Регистрирует возврат расхода по текущему документу
* *
* @param KktFiscalizer $fiscalizer Объект фискализатора * @param Fiscalizer $fiscalizer Объект фискализатора
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID) * @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
* @return KktResponse|null * @return AtolResponse|null
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -449,7 +449,7 @@ final class Receipt extends Entity
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
*/ */
public function buyRefund(KktFiscalizer $fiscalizer, ?string $external_id = null): ?KktResponse public function buyRefund(Fiscalizer $fiscalizer, ?string $external_id = null): ?AtolResponse
{ {
return $fiscalizer->buyRefund($this, $external_id); return $fiscalizer->buyRefund($this, $external_id);
} }

View File

@ -11,7 +11,7 @@ declare(strict_types = 1);
namespace AtolOnline\Exceptions; namespace AtolOnline\Exceptions;
use AtolOnline\Api\KktResponse; use AtolOnline\Api\AtolResponse;
use Exception; use Exception;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
@ -23,11 +23,11 @@ class AuthFailedException extends Exception
/** /**
* Конструктор * Конструктор
* *
* @param KktResponse $response * @param AtolResponse $response
* @param string $message * @param string $message
*/ */
#[Pure] #[Pure]
public function __construct(KktResponse $response, string $message = '') public function __construct(AtolResponse $response, string $message = '')
{ {
parent::__construct(($message ?: 'Ошибка авторизации: ') . ': ' . $response); parent::__construct(($message ?: 'Ошибка авторизации: ') . ': ' . $response);
} }

View File

@ -16,7 +16,7 @@ use AtolOnline\{
Tests\BasicTestCase}; Tests\BasicTestCase};
use AtolOnline\Api\{ use AtolOnline\Api\{
AtolClient, AtolClient,
KktFiscalizer}; Fiscalizer};
use AtolOnline\Exceptions\{ use AtolOnline\Exceptions\{
AuthFailedException, AuthFailedException,
EmptyCorrectionNumberException, EmptyCorrectionNumberException,
@ -39,8 +39,6 @@ use AtolOnline\Exceptions\{
TooHighPaymentSumException, TooHighPaymentSumException,
TooLongCallbackUrlException, TooLongCallbackUrlException,
TooLongItemNameException, TooLongItemNameException,
TooLongLoginException,
TooLongPasswordException,
TooLongPaymentAddressException, TooLongPaymentAddressException,
TooManyException}; TooManyException};
use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Exception\GuzzleException;
@ -48,7 +46,7 @@ use GuzzleHttp\Exception\GuzzleException;
/** /**
* Набор тестов для проверки работы фискализатора * Набор тестов для проверки работы фискализатора
*/ */
class KktFiscalizerTest extends BasicTestCase class FiscalizerTest extends BasicTestCase
{ {
/** /**
* @var array Массив UUID-ов результатов регистрации документов для переиспользования * @var array Массив UUID-ов результатов регистрации документов для переиспользования
@ -60,13 +58,13 @@ class KktFiscalizerTest extends BasicTestCase
* Тестирует успешное создание объекта фискализатора без аргументов конструктора * Тестирует успешное создание объекта фискализатора без аргументов конструктора
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer * @covers \AtolOnline\Api\Fiscalizer
*/ */
public function testConstructorWithourArgs(): void public function testConstructorWithourArgs(): void
{ {
$fisc = new KktFiscalizer(); $fisc = new Fiscalizer();
$this->assertIsObject($fisc); $this->assertIsObject($fisc);
$this->assertIsSameClass(KktFiscalizer::class, $fisc); $this->assertIsSameClass(Fiscalizer::class, $fisc);
$this->assertExtendsClasses([AtolClient::class], $fisc); $this->assertExtendsClasses([AtolClient::class], $fisc);
} }
@ -74,41 +72,41 @@ class KktFiscalizerTest extends BasicTestCase
* Тестирует установку и возврат группы ККТ * Тестирует установку и возврат группы ККТ
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer * @covers \AtolOnline\Api\Fiscalizer
* @covers \AtolOnline\Api\KktFiscalizer::getGroup * @covers \AtolOnline\Api\Fiscalizer::getGroup
* @covers \AtolOnline\Api\KktFiscalizer::setGroup * @covers \AtolOnline\Api\Fiscalizer::setGroup
*/ */
public function testGroup(): void public function testGroup(): void
{ {
// test mode // test mode
$this->assertEquals( $this->assertEquals(
TestEnvParams::FFD105()['group'], TestEnvParams::FFD105()['group'],
(new KktFiscalizer(group: 'group'))->getGroup() (new Fiscalizer(group: 'group'))->getGroup()
); );
// prod mode // prod mode
$this->assertEquals('group', (new KktFiscalizer(false, group: 'group'))->getGroup()); $this->assertEquals('group', (new Fiscalizer(false, group: 'group'))->getGroup());
$this->assertNull((new KktFiscalizer(false))->getGroup()); $this->assertNull((new Fiscalizer(false))->getGroup());
} }
/** /**
* Тестирует выброс исключения при попытке передать пустую группу ККТ в конструктор * Тестирует выброс исключения при попытке передать пустую группу ККТ в конструктор
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer * @covers \AtolOnline\Api\Fiscalizer
* @covers \AtolOnline\Api\KktFiscalizer::setGroup * @covers \AtolOnline\Api\Fiscalizer::setGroup
* @covers \AtolOnline\Exceptions\EmptyGroupException * @covers \AtolOnline\Exceptions\EmptyGroupException
*/ */
public function testEmptyGroupException(): void public function testEmptyGroupException(): void
{ {
$this->expectException(EmptyGroupException::class); $this->expectException(EmptyGroupException::class);
new KktFiscalizer(group: "\n\r \0\t"); new Fiscalizer(group: "\n\r \0\t");
} }
/** /**
* Тестирует выброс исключения при попытке установить слишком длинный адрес колбека * Тестирует выброс исключения при попытке установить слишком длинный адрес колбека
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer::setCallbackUrl * @covers \AtolOnline\Api\Fiscalizer::setCallbackUrl
* @covers \AtolOnline\Exceptions\TooLongCallbackUrlException * @covers \AtolOnline\Exceptions\TooLongCallbackUrlException
* @throws InvalidCallbackUrlException * @throws InvalidCallbackUrlException
* @throws TooLongCallbackUrlException * @throws TooLongCallbackUrlException
@ -116,14 +114,14 @@ class KktFiscalizerTest extends BasicTestCase
public function testTooLongCallbackUrlException(): void public function testTooLongCallbackUrlException(): void
{ {
$this->expectException(TooLongCallbackUrlException::class); $this->expectException(TooLongCallbackUrlException::class);
(new KktFiscalizer())->setCallbackUrl(Helpers::randomStr(Constraints::MAX_LENGTH_CALLBACK_URL + 1)); (new Fiscalizer())->setCallbackUrl(Helpers::randomStr(Constraints::MAX_LENGTH_CALLBACK_URL + 1));
} }
/** /**
* Тестирует выброс исключения при попытке установить слишком длинный адрес колбека * Тестирует выброс исключения при попытке установить слишком длинный адрес колбека
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer::setCallbackUrl * @covers \AtolOnline\Api\Fiscalizer::setCallbackUrl
* @covers \AtolOnline\Exceptions\InvalidCallbackUrlException * @covers \AtolOnline\Exceptions\InvalidCallbackUrlException
* @throws InvalidCallbackUrlException * @throws InvalidCallbackUrlException
* @throws TooLongCallbackUrlException * @throws TooLongCallbackUrlException
@ -131,7 +129,7 @@ class KktFiscalizerTest extends BasicTestCase
public function testInvalidCallbackUrlException(): void public function testInvalidCallbackUrlException(): void
{ {
$this->expectException(InvalidCallbackUrlException::class); $this->expectException(InvalidCallbackUrlException::class);
(new KktFiscalizer())->setCallbackUrl(Helpers::randomStr()); (new Fiscalizer())->setCallbackUrl(Helpers::randomStr());
} }
/** /**
@ -139,15 +137,15 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @param mixed $param * @param mixed $param
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer::setCallbackUrl * @covers \AtolOnline\Api\Fiscalizer::setCallbackUrl
* @covers \AtolOnline\Api\KktFiscalizer::getCallbackUrl * @covers \AtolOnline\Api\Fiscalizer::getCallbackUrl
* @dataProvider providerNullableStrings * @dataProvider providerNullableStrings
* @throws InvalidCallbackUrlException * @throws InvalidCallbackUrlException
* @throws TooLongCallbackUrlException * @throws TooLongCallbackUrlException
*/ */
public function testNullableCallbackUrl(mixed $param): void public function testNullableCallbackUrl(mixed $param): void
{ {
$this->assertNull((new KktFiscalizer())->setCallbackUrl($param)->getCallbackUrl()); $this->assertNull((new Fiscalizer())->setCallbackUrl($param)->getCallbackUrl());
} }
/** /**
@ -155,11 +153,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt::sell * @covers \AtolOnline\Entities\Receipt::sell
* @covers \AtolOnline\Api\KktFiscalizer::sell * @covers \AtolOnline\Api\Fiscalizer::sell
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws EmptyItemsException * @throws EmptyItemsException
@ -175,16 +173,14 @@ class KktFiscalizerTest extends BasicTestCase
* @throws TooHighItemPriceException * @throws TooHighItemPriceException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws TooManyException * @throws TooManyException
* @throws GuzzleException * @throws GuzzleException
*/ */
public function testSell(): void public function testSell(): void
{ {
$fisc_result = $this->newReceipt()->sell(new KktFiscalizer()); $fisc_result = $this->newReceipt()->sell(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
@ -194,11 +190,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt::sellRefund * @covers \AtolOnline\Entities\Receipt::sellRefund
* @covers \AtolOnline\Api\KktFiscalizer::sellRefund * @covers \AtolOnline\Api\Fiscalizer::sellRefund
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws EmptyItemsException * @throws EmptyItemsException
@ -214,16 +210,14 @@ class KktFiscalizerTest extends BasicTestCase
* @throws TooHighItemPriceException * @throws TooHighItemPriceException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws TooManyException * @throws TooManyException
* @throws GuzzleException * @throws GuzzleException
*/ */
public function testSellRefund(): void public function testSellRefund(): void
{ {
$fisc_result = $this->newReceipt()->sellRefund(new KktFiscalizer()); $fisc_result = $this->newReceipt()->sellRefund(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
@ -233,11 +227,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Correction::sellCorrect * @covers \AtolOnline\Entities\Correction::sellCorrect
* @covers \AtolOnline\Api\KktFiscalizer::sellCorrect * @covers \AtolOnline\Api\Fiscalizer::sellCorrect
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -248,18 +242,16 @@ class KktFiscalizerTest extends BasicTestCase
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws NegativePaymentSumException * @throws NegativePaymentSumException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws EmptyCorrectionNumberException * @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException * @throws InvalidCorrectionDateException
*/ */
public function testSellCorrect(): void public function testSellCorrect(): void
{ {
$fisc_result = $this->newCorrection()->sellCorrect(new KktFiscalizer()); $fisc_result = $this->newCorrection()->sellCorrect(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; //self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
/** /**
@ -267,11 +259,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt::buy * @covers \AtolOnline\Entities\Receipt::buy
* @covers \AtolOnline\Api\KktFiscalizer::buy * @covers \AtolOnline\Api\Fiscalizer::buy
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws EmptyItemsException * @throws EmptyItemsException
@ -287,18 +279,16 @@ class KktFiscalizerTest extends BasicTestCase
* @throws TooHighItemPriceException * @throws TooHighItemPriceException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws TooManyException * @throws TooManyException
* @throws GuzzleException * @throws GuzzleException
*/ */
public function testBuy(): void public function testBuy(): void
{ {
$fisc_result = $this->newReceipt()->buy(new KktFiscalizer()); $fisc_result = $this->newReceipt()->buy(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; //self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
/** /**
@ -306,11 +296,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Receipt::buyRefund * @covers \AtolOnline\Entities\Receipt::buyRefund
* @covers \AtolOnline\Api\KktFiscalizer::buyRefund * @covers \AtolOnline\Api\Fiscalizer::buyRefund
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyItemNameException * @throws EmptyItemNameException
* @throws EmptyItemsException * @throws EmptyItemsException
@ -326,18 +316,16 @@ class KktFiscalizerTest extends BasicTestCase
* @throws TooHighItemPriceException * @throws TooHighItemPriceException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongItemNameException * @throws TooLongItemNameException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws TooManyException * @throws TooManyException
* @throws GuzzleException * @throws GuzzleException
*/ */
public function testBuyRefund(): void public function testBuyRefund(): void
{ {
$fisc_result = $this->newReceipt()->buyRefund(new KktFiscalizer()); $fisc_result = $this->newReceipt()->buyRefund(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; //self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
/** /**
@ -345,11 +333,11 @@ class KktFiscalizerTest extends BasicTestCase
* *
* @return void * @return void
* @covers \AtolOnline\Entities\Correction::buyCorrect * @covers \AtolOnline\Entities\Correction::buyCorrect
* @covers \AtolOnline\Api\KktFiscalizer::buyCorrect * @covers \AtolOnline\Api\Fiscalizer::buyCorrect
* @covers \AtolOnline\Api\KktFiscalizer::getFullUrl * @covers \AtolOnline\Api\Fiscalizer::getFullUrl
* @covers \AtolOnline\Api\KktFiscalizer::getAuthEndpoint * @covers \AtolOnline\Api\Fiscalizer::getAuthEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::getMainEndpoint * @covers \AtolOnline\Api\Fiscalizer::getMainEndpoint
* @covers \AtolOnline\Api\KktFiscalizer::registerDocument * @covers \AtolOnline\Api\Fiscalizer::registerDocument
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -360,37 +348,34 @@ class KktFiscalizerTest extends BasicTestCase
* @throws InvalidPaymentAddressException * @throws InvalidPaymentAddressException
* @throws NegativePaymentSumException * @throws NegativePaymentSumException
* @throws TooHighPaymentSumException * @throws TooHighPaymentSumException
* @throws TooLongLoginException
* @throws TooLongPasswordException
* @throws TooLongPaymentAddressException * @throws TooLongPaymentAddressException
* @throws EmptyCorrectionNumberException * @throws EmptyCorrectionNumberException
* @throws InvalidCorrectionDateException * @throws InvalidCorrectionDateException
*/ */
public function testBuyCorrect(): void public function testBuyCorrect(): void
{ {
$fisc_result = $this->newCorrection()->buyCorrect(new KktFiscalizer()); $fisc_result = $this->newCorrection()->buyCorrect(new Fiscalizer());
$this->assertTrue($fisc_result->isValid()); $this->assertTrue($fisc_result->isSuccessful());
$this->assertEquals('wait', $fisc_result->getContent()->status); $this->assertEquals('wait', $fisc_result->getContent()->status);
self::$registered_uuids[] = $fisc_result->getContent()->uuid; //self::$registered_uuids[] = $fisc_result->getContent()->uuid;
} }
/** /**
* Тестирует разовое получение статуса фискализации документа * Тестирует разовое получение статуса фискализации документа
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer::getDocumentStatus * @covers \AtolOnline\Api\Fiscalizer::getDocumentStatus
* @depends testSell
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidUuidException * @throws InvalidUuidException
* @throws TooLongLoginException
* @throws TooLongPasswordException
*/ */
public function testGetDocumentStatus(): void public function testGetDocumentStatus(): void
{ {
$fisc_status = (new KktFiscalizer())->getDocumentStatus(self::$registered_uuids[0]); $fisc_status = (new Fiscalizer())->getDocumentStatus(array_shift(self::$registered_uuids));
$this->assertTrue($fisc_status->isValid()); $this->assertTrue($fisc_status->isSuccessful());
$this->assertTrue(in_array($fisc_status->getContent()->status, ['wait', 'done'])); $this->assertTrue(in_array($fisc_status->getContent()->status, ['wait', 'done']));
} }
@ -398,20 +383,18 @@ class KktFiscalizerTest extends BasicTestCase
* Тестирует опрос API на получение статуса фискализации документа * Тестирует опрос API на получение статуса фискализации документа
* *
* @return void * @return void
* @covers \AtolOnline\Api\KktFiscalizer::pollDocumentStatus * @covers \AtolOnline\Api\Fiscalizer::pollDocumentStatus
* @depends testSellRefund
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws GuzzleException * @throws GuzzleException
* @throws InvalidUuidException * @throws InvalidUuidException
* @throws TooLongLoginException
* @throws TooLongPasswordException
*/ */
public function testPollDocumentStatus(): void public function testPollDocumentStatus(): void
{ {
$fisc_status = (new KktFiscalizer())->pollDocumentStatus(self::$registered_uuids[1]); $fisc_status = (new Fiscalizer())->pollDocumentStatus(array_shift(self::$registered_uuids));
$this->assertTrue($fisc_status->isValid()); $this->assertTrue($fisc_status->isSuccessful());
$this->assertEquals('done', $fisc_status->getContent()->status); $this->assertEquals('done', $fisc_status->getContent()->status);
} }
} }

View File

@ -10,8 +10,8 @@
namespace AtolOnline\Tests\Api; namespace AtolOnline\Tests\Api;
use AtolOnline\Api\AtolClient; use AtolOnline\Api\AtolClient;
use AtolOnline\Api\KktMonitor; use AtolOnline\Api\AtolResponse;
use AtolOnline\Api\KktResponse; use AtolOnline\Api\Monitor;
use AtolOnline\Entities\Kkt; use AtolOnline\Entities\Kkt;
use AtolOnline\Exceptions\AuthFailedException; use AtolOnline\Exceptions\AuthFailedException;
use AtolOnline\Exceptions\EmptyLoginException; use AtolOnline\Exceptions\EmptyLoginException;
@ -29,20 +29,20 @@ use GuzzleHttp\Exception\GuzzleException;
/** /**
* Набор тестов для проверки работы API-клиента на примере монитора ККТ * Набор тестов для проверки работы API-клиента на примере монитора ККТ
*/ */
class KktMonitorTest extends BasicTestCase class MonitorTest extends BasicTestCase
{ {
/** /**
* Возвращает объект монитора для тестирования с тестовым API АТОЛ * Возвращает объект монитора для тестирования с тестовым API АТОЛ
* *
* @return KktMonitor * @return Monitor
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws TooLongLoginException * @throws TooLongLoginException
* @throws TooLongPasswordException * @throws TooLongPasswordException
*/ */
private function newTestClient(): KktMonitor private function newTestClient(): Monitor
{ {
return (new KktMonitor(true)) return (new Monitor(true))
->setLogin(TestEnvParams::FFD105()['login']) ->setLogin(TestEnvParams::FFD105()['login'])
->setPassword(TestEnvParams::FFD105()['password']); ->setPassword(TestEnvParams::FFD105()['password']);
} }
@ -50,24 +50,24 @@ class KktMonitorTest extends BasicTestCase
/** /**
* Тестирует успешное создание объекта монитора без аргументов конструктора * Тестирует успешное создание объекта монитора без аргументов конструктора
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
*/ */
public function testConstructorWithoutArgs(): void public function testConstructorWithoutArgs(): void
{ {
$client = new KktMonitor(); $client = new Monitor();
$this->assertIsObject($client); $this->assertIsObject($client);
$this->assertIsSameClass(KktMonitor::class, $client); $this->assertIsSameClass(Monitor::class, $client);
$this->assertExtendsClasses([AtolClient::class], $client); $this->assertExtendsClasses([AtolClient::class], $client);
} }
/** /**
* Тестирует успешное создание объекта монитора с аргументами конструктора * Тестирует успешное создание объекта монитора с аргументами конструктора
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Api\Monitor::setLogin
* @covers \AtolOnline\Api\KktMonitor::getLogin * @covers \AtolOnline\Api\Monitor::getLogin
* @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Api\Monitor::setPassword
* @covers \AtolOnline\Api\KktMonitor::getPassword * @covers \AtolOnline\Api\Monitor::getPassword
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws TooLongLoginException * @throws TooLongLoginException
@ -75,27 +75,28 @@ class KktMonitorTest extends BasicTestCase
*/ */
public function testConstructorWithArgs(): void public function testConstructorWithArgs(): void
{ {
$client = new KktMonitor(false, 'login', 'password', []); $client = new Monitor(false, 'login', 'password', []);
$this->assertIsObject($client); $this->assertIsObject($client);
$this->assertIsSameClass($client, KktMonitor::class); $this->assertIsSameClass($client, Monitor::class);
$this->assertExtendsClasses([AtolClient::class], $client); $this->assertExtendsClasses([AtolClient::class], $client);
} }
//
/** /**
* Тестирует установку и возврат логина * Тестирует установку и возврат логина
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::getLogin * @covers \AtolOnline\Api\Monitor::getLogin
* @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Api\Monitor::setLogin
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws TooLongLoginException * @throws TooLongLoginException
*/ */
public function testLogin(): void public function testLogin(): void
{ {
$client = new KktMonitor(false, login: 'login'); $client = new Monitor(false, login: 'login');
$this->assertEquals('login', $client->getLogin()); $this->assertEquals('login', $client->getLogin());
$client = new KktMonitor(); $client = new Monitor();
$this->assertEquals(TestEnvParams::FFD105()['login'], $client->getLogin()); $this->assertEquals(TestEnvParams::FFD105()['login'], $client->getLogin());
$client->setLogin('login'); $client->setLogin('login');
@ -105,21 +106,21 @@ class KktMonitorTest extends BasicTestCase
/** /**
* Тестирует исключение при попытке передать пустой логин в конструктор * Тестирует исключение при попытке передать пустой логин в конструктор
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Api\Monitor::setLogin
* @covers \AtolOnline\Exceptions\EmptyLoginException * @covers \AtolOnline\Exceptions\EmptyLoginException
*/ */
public function testEmptyLoginException(): void public function testEmptyLoginException(): void
{ {
$this->expectException(EmptyLoginException::class); $this->expectException(EmptyLoginException::class);
new KktMonitor(login: ''); new Monitor(login: '');
} }
/** /**
* Тестирует исключение при попытке передать слишком длинный логин в конструктор * Тестирует исключение при попытке передать слишком длинный логин в конструктор
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::setLogin * @covers \AtolOnline\Api\Monitor::setLogin
* @covers \AtolOnline\Exceptions\TooLongLoginException * @covers \AtolOnline\Exceptions\TooLongLoginException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -129,24 +130,24 @@ class KktMonitorTest extends BasicTestCase
public function testTooLongLoginException(): void public function testTooLongLoginException(): void
{ {
$this->expectException(TooLongLoginException::class); $this->expectException(TooLongLoginException::class);
new KktMonitor(login: Helpers::randomStr(101)); new Monitor(login: Helpers::randomStr(101));
} }
/** /**
* Тестирует установку и возврат пароля * Тестирует установку и возврат пароля
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::getPassword * @covers \AtolOnline\Api\Monitor::getPassword
* @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Api\Monitor::setPassword
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws TooLongPasswordException * @throws TooLongPasswordException
*/ */
public function testPassword(): void public function testPassword(): void
{ {
$client = new KktMonitor(false, password: 'password'); $client = new Monitor(false, password: 'password');
$this->assertEquals('password', $client->getPassword()); $this->assertEquals('password', $client->getPassword());
$client = new KktMonitor(); $client = new Monitor();
$this->assertEquals(TestEnvParams::FFD105()['password'], $client->getPassword()); $this->assertEquals(TestEnvParams::FFD105()['password'], $client->getPassword());
$client->setPassword('password'); $client->setPassword('password');
@ -156,21 +157,21 @@ class KktMonitorTest extends BasicTestCase
/** /**
* Тестирует исключение при попытке передать пустой пароль в конструктор * Тестирует исключение при попытке передать пустой пароль в конструктор
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Api\Monitor::setPassword
* @covers \AtolOnline\Exceptions\EmptyPasswordException * @covers \AtolOnline\Exceptions\EmptyPasswordException
*/ */
public function testEmptyPasswordException(): void public function testEmptyPasswordException(): void
{ {
$this->expectException(EmptyPasswordException::class); $this->expectException(EmptyPasswordException::class);
new KktMonitor(password: ''); new Monitor(password: '');
} }
/** /**
* Тестирует исключение при попытке передать слишком длинный пароль в конструктор * Тестирует исключение при попытке передать слишком длинный пароль в конструктор
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::setPassword * @covers \AtolOnline\Api\Monitor::setPassword
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
* @throws TooLongLoginException * @throws TooLongLoginException
@ -179,34 +180,34 @@ class KktMonitorTest extends BasicTestCase
public function testConstructorWithLongPassword(): void public function testConstructorWithLongPassword(): void
{ {
$this->expectException(TooLongPasswordException::class); $this->expectException(TooLongPasswordException::class);
new KktMonitor(password: Helpers::randomStr(101)); new Monitor(password: Helpers::randomStr(101));
} }
/** /**
* Тестирует установку тестового режима * Тестирует установку тестового режима
* *
* @covers \AtolOnline\Api\KktMonitor::__construct * @covers \AtolOnline\Api\Monitor::__construct
* @covers \AtolOnline\Api\KktMonitor::isTestMode * @covers \AtolOnline\Api\Monitor::isTestMode
* @covers \AtolOnline\Api\KktMonitor::setTestMode * @covers \AtolOnline\Api\Monitor::setTestMode
*/ */
public function testTestMode(): void public function testTestMode(): void
{ {
$client = new KktMonitor(); $client = new Monitor();
$this->assertTrue($client->isTestMode()); $this->assertTrue($client->isTestMode());
$client = new KktMonitor(true); $client = new Monitor(true);
$this->assertTrue($client->isTestMode()); $this->assertTrue($client->isTestMode());
$client = new KktMonitor(false); $client = new Monitor(false);
$this->assertFalse($client->isTestMode()); $this->assertFalse($client->isTestMode());
$client = (new KktMonitor())->setTestMode(); $client = (new Monitor())->setTestMode();
$this->assertTrue($client->isTestMode()); $this->assertTrue($client->isTestMode());
$client = (new KktMonitor())->setTestMode(true); $client = (new Monitor())->setTestMode(true);
$this->assertTrue($client->isTestMode()); $this->assertTrue($client->isTestMode());
$client = (new KktMonitor())->setTestMode(false); $client = (new Monitor())->setTestMode(false);
$this->assertFalse($client->isTestMode()); $this->assertFalse($client->isTestMode());
} }
@ -214,10 +215,10 @@ class KktMonitorTest extends BasicTestCase
* Тестирует авторизацию * Тестирует авторизацию
* *
* @covers \AtolOnline\Api\AtolClient::getHeaders * @covers \AtolOnline\Api\AtolClient::getHeaders
* @covers \AtolOnline\Api\KktMonitor::sendRequest * @covers \AtolOnline\Api\Monitor::sendRequest
* @covers \AtolOnline\Api\KktMonitor::getAuthEndpoint * @covers \AtolOnline\Api\Monitor::getAuthEndpoint
* @covers \AtolOnline\Api\KktMonitor::doAuth * @covers \AtolOnline\Api\Monitor::doAuth
* @covers \AtolOnline\Api\KktMonitor::auth * @covers \AtolOnline\Api\Monitor::auth
* @covers \AtolOnline\Exceptions\AuthFailedException * @covers \AtolOnline\Exceptions\AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
* @throws EmptyPasswordException * @throws EmptyPasswordException
@ -237,8 +238,8 @@ class KktMonitorTest extends BasicTestCase
* Тестирует возврат токена после авторизации * Тестирует возврат токена после авторизации
* *
* @depends testAuth * @depends testAuth
* @covers \AtolOnline\Api\KktMonitor::setToken * @covers \AtolOnline\Api\Monitor::setToken
* @covers \AtolOnline\Api\KktMonitor::getToken * @covers \AtolOnline\Api\Monitor::getToken
* @covers \AtolOnline\Exceptions\AuthFailedException * @covers \AtolOnline\Exceptions\AuthFailedException
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
@ -249,7 +250,7 @@ class KktMonitorTest extends BasicTestCase
*/ */
public function testGetToken(): void public function testGetToken(): void
{ {
$client = new KktMonitor(); $client = new Monitor();
$this->assertNull($client->getToken()); $this->assertNull($client->getToken());
$this->skipIfMonitoringIsOffline(); $this->skipIfMonitoringIsOffline();
@ -262,7 +263,7 @@ class KktMonitorTest extends BasicTestCase
* Тестирует возврат объекта последнего ответа от API * Тестирует возврат объекта последнего ответа от API
* *
* @depends testAuth * @depends testAuth
* @covers \AtolOnline\Api\KktMonitor::getLastResponse * @covers \AtolOnline\Api\Monitor::getLastResponse
* @covers \AtolOnline\Exceptions\AuthFailedException * @covers \AtolOnline\Exceptions\AuthFailedException
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
@ -276,17 +277,17 @@ class KktMonitorTest extends BasicTestCase
$this->skipIfMonitoringIsOffline(); $this->skipIfMonitoringIsOffline();
$client = $this->newTestClient(); $client = $this->newTestClient();
$client->auth(); $client->auth();
$this->assertIsSameClass(KktResponse::class, $client->getLastResponse()); $this->assertIsSameClass(AtolResponse::class, $client->getLastResponse());
} }
/** /**
* [Мониторинг] Тестирует получение данных о всех ККТ * [Мониторинг] Тестирует получение данных о всех ККТ
* *
* @depends testAuth * @depends testAuth
* @covers \AtolOnline\Api\KktMonitor::getMainEndpoint * @covers \AtolOnline\Api\Monitor::getMainEndpoint
* @covers \AtolOnline\Api\AtolClient::getUrlToMethod * @covers \AtolOnline\Api\AtolClient::getUrlToMethod
* @covers \AtolOnline\Api\KktMonitor::fetchAll * @covers \AtolOnline\Api\Monitor::fetchAll
* @covers \AtolOnline\Api\KktMonitor::getAll * @covers \AtolOnline\Api\Monitor::getAll
* @covers \AtolOnline\Exceptions\AuthFailedException * @covers \AtolOnline\Exceptions\AuthFailedException
* @throws AuthFailedException * @throws AuthFailedException
* @throws EmptyLoginException * @throws EmptyLoginException
@ -312,10 +313,10 @@ class KktMonitorTest extends BasicTestCase
* [Мониторинг] Тестирует получение данных о конкретной ККТ * [Мониторинг] Тестирует получение данных о конкретной ККТ
* *
* @depends testAuth * @depends testAuth
* @covers \AtolOnline\Api\KktMonitor::getMainEndpoint * @covers \AtolOnline\Api\Monitor::getMainEndpoint
* @covers \AtolOnline\Api\AtolClient::getUrlToMethod * @covers \AtolOnline\Api\AtolClient::getUrlToMethod
* @covers \AtolOnline\Api\KktMonitor::fetchOne * @covers \AtolOnline\Api\Monitor::fetchOne
* @covers \AtolOnline\Api\KktMonitor::getOne * @covers \AtolOnline\Api\Monitor::getOne
* @covers \AtolOnline\Entities\Kkt::__construct * @covers \AtolOnline\Entities\Kkt::__construct
* @covers \AtolOnline\Entities\Kkt::__get * @covers \AtolOnline\Entities\Kkt::__get
* @covers \AtolOnline\Entities\Kkt::jsonSerialize * @covers \AtolOnline\Entities\Kkt::jsonSerialize