Переименования классов для пущей простоты
This commit is contained in:
@@ -35,9 +35,9 @@ abstract class AtolClient
|
||||
protected array $request;
|
||||
|
||||
/**
|
||||
* @var KktResponse|null Последний ответ сервера АТОЛ
|
||||
* @var AtolResponse|null Последний ответ сервера АТОЛ
|
||||
*/
|
||||
protected ?KktResponse $response;
|
||||
protected ?AtolResponse $response;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
@@ -263,7 +263,7 @@ abstract class AtolClient
|
||||
'login' => $this->getLogin() ?? throw new EmptyLoginException(),
|
||||
'pass' => $this->getPassword() ?? throw new EmptyPasswordException(),
|
||||
]);
|
||||
if (!$result->isValid() || !$result->getContent()->token) {
|
||||
if (!$result->isSuccessful() || !$result->getContent()->token) {
|
||||
throw new AuthFailedException($result);
|
||||
}
|
||||
return $result->getContent()?->token;
|
||||
@@ -276,7 +276,7 @@ abstract class AtolClient
|
||||
* @param string $url URL
|
||||
* @param array|null $data Данные для передачи
|
||||
* @param array|null $options Параметры Guzzle
|
||||
* @return KktResponse
|
||||
* @return AtolResponse
|
||||
* @throws GuzzleException
|
||||
* @see https://guzzle.readthedocs.io/en/latest/request-options.html
|
||||
*/
|
||||
@@ -285,7 +285,7 @@ abstract class AtolClient
|
||||
string $url,
|
||||
?array $data = null,
|
||||
?array $options = null
|
||||
): KktResponse {
|
||||
): AtolResponse {
|
||||
$http_method = strtoupper(trim($http_method));
|
||||
$options['headers'] = array_merge($this->getHeaders(), $options['headers'] ?? []);
|
||||
$http_method != 'GET' && $options['json'] = $data;
|
||||
@@ -294,7 +294,7 @@ abstract class AtolClient
|
||||
'url' => $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
|
||||
*/
|
||||
abstract protected function getMainEndpoint(): string;
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ use Stringable;
|
||||
* @property mixed $error
|
||||
* @package AtolOnline\Api
|
||||
*/
|
||||
class KktResponse implements JsonSerializable, Stringable
|
||||
class AtolResponse implements JsonSerializable, Stringable
|
||||
{
|
||||
/**
|
||||
* @var int Код ответа сервера
|
||||
@@ -104,7 +104,7 @@ class KktResponse implements JsonSerializable, Stringable
|
||||
* @return bool
|
||||
*/
|
||||
#[Pure]
|
||||
public function isValid(): bool
|
||||
public function isSuccessful(): bool
|
||||
{
|
||||
return !empty($this->getCode())
|
||||
&& !empty($this->getContent())
|
||||
@@ -38,7 +38,7 @@ use Ramsey\Uuid\Uuid;
|
||||
/**
|
||||
* Класс фискализатора для регистрации документов на ККТ
|
||||
*/
|
||||
class KktFiscalizer extends AtolClient
|
||||
class Fiscalizer extends AtolClient
|
||||
{
|
||||
/**
|
||||
* @var string|null Группа ККТ
|
||||
@@ -139,7 +139,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Receipt $receipt Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -149,7 +149,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -159,7 +159,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Receipt $receipt Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -169,7 +169,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Correction $correction Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -189,7 +189,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -199,7 +199,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Receipt $receipt Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -209,7 +209,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -219,7 +219,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Receipt $receipt Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -229,7 +229,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -239,7 +239,7 @@ class KktFiscalizer extends AtolClient
|
||||
*
|
||||
* @param Correction $correction Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -249,7 +249,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -258,14 +258,14 @@ class KktFiscalizer extends AtolClient
|
||||
* Проверяет статус чека на ККТ один раз
|
||||
*
|
||||
* @param string $uuid UUID регистрации
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
* @throws GuzzleException
|
||||
* @throws InvalidUuidException
|
||||
*/
|
||||
public function getDocumentStatus(string $uuid): ?KktResponse
|
||||
public function getDocumentStatus(string $uuid): ?AtolResponse
|
||||
{
|
||||
!Uuid::isValid($uuid = trim($uuid)) && throw new InvalidUuidException($uuid);
|
||||
return $this->auth()
|
||||
@@ -280,19 +280,19 @@ class KktFiscalizer extends AtolClient
|
||||
* @param string $uuid UUID регистрации
|
||||
* @param int $retry_count Количество попыток
|
||||
* @param int $timeout Таймаут в секундах между попытками
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
* @throws GuzzleException
|
||||
* @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;
|
||||
do {
|
||||
$response = $this->getDocumentStatus($uuid);
|
||||
if ($response->isValid() && $response->getContent()->status == 'done') {
|
||||
if ($response->isSuccessful() && $response->getContent()->status == 'done') {
|
||||
break;
|
||||
} else {
|
||||
sleep($timeout);
|
||||
@@ -308,7 +308,7 @@ class KktFiscalizer extends AtolClient
|
||||
* @param string $api_method Метод API
|
||||
* @param Receipt|Correction $document Документ
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -322,7 +322,7 @@ class KktFiscalizer extends AtolClient
|
||||
string $api_method,
|
||||
Receipt|Correction $document,
|
||||
?string $external_id = null
|
||||
): ?KktResponse {
|
||||
): ?AtolResponse {
|
||||
$this->isTestMode() && $document->getCompany()
|
||||
->setInn(TestEnvParams::FFD105()['inn'])
|
||||
->setPaymentAddress(TestEnvParams::FFD105()['payment_address']);
|
||||
@@ -27,7 +27,7 @@ use JetBrains\PhpStorm\Pure;
|
||||
*
|
||||
* @see https://online.atol.ru/files/API_service_information.pdf Документация
|
||||
*/
|
||||
class KktMonitor extends AtolClient
|
||||
class Monitor extends AtolClient
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
@@ -56,14 +56,14 @@ class KktMonitor extends AtolClient
|
||||
*
|
||||
* @param int|null $limit
|
||||
* @param int|null $offset
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws GuzzleException
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
* @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 = [];
|
||||
!is_null($limit) && $params['limit'] = $limit;
|
||||
@@ -95,11 +95,11 @@ class KktMonitor extends AtolClient
|
||||
* Получает от API информацию о конкретной ККТ по её серийному номеру
|
||||
*
|
||||
* @param string $serial_number
|
||||
* @return KktResponse
|
||||
* @return AtolResponse
|
||||
* @throws GuzzleException
|
||||
* @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(
|
||||
'GET',
|
||||
@@ -10,8 +10,8 @@
|
||||
namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\{
|
||||
Api\KktFiscalizer,
|
||||
Api\KktResponse,
|
||||
Api\AtolResponse,
|
||||
Api\Fiscalizer,
|
||||
Collections\Payments,
|
||||
Collections\Vats,
|
||||
Constants\Constraints};
|
||||
@@ -211,9 +211,9 @@ class Correction extends Entity
|
||||
/**
|
||||
* Регистрирует коррекцию прихода по текущему документу
|
||||
*
|
||||
* @param KktFiscalizer $fiscalizer Объект фискализатора
|
||||
* @param Fiscalizer $fiscalizer Объект фискализатора
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -223,7 +223,7 @@ class Correction extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -231,9 +231,9 @@ class Correction extends Entity
|
||||
/**
|
||||
* Регистрирует коррекцию расхода по текущему документу
|
||||
*
|
||||
* @param KktFiscalizer $fiscalizer Объект фискализатора
|
||||
* @param Fiscalizer $fiscalizer Объект фискализатора
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -243,7 +243,7 @@ class Correction extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ abstract class Entity implements JsonSerializable, Stringable, Arrayable, ArrayA
|
||||
'correction_info' => "\AtolOnline\Entities\CorrectionInfo",
|
||||
'payments' => "array",
|
||||
'vats' => "\AtolOnline\Collections\Vats|null",
|
||||
'cashier' => "\null|string"
|
||||
'cashier' => "null|string",
|
||||
])]
|
||||
public function toArray()
|
||||
{
|
||||
|
||||
@@ -11,8 +11,8 @@ declare(strict_types = 1);
|
||||
|
||||
namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\Api\KktFiscalizer;
|
||||
use AtolOnline\Api\KktResponse;
|
||||
use AtolOnline\Api\AtolResponse;
|
||||
use AtolOnline\Api\Fiscalizer;
|
||||
use AtolOnline\Collections\Items;
|
||||
use AtolOnline\Collections\Payments;
|
||||
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)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -389,7 +389,7 @@ final class Receipt extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -397,9 +397,9 @@ final class Receipt extends Entity
|
||||
/**
|
||||
* Регистрирует возврат прихода по текущему документу
|
||||
*
|
||||
* @param KktFiscalizer $fiscalizer Объект фискализатора
|
||||
* @param Fiscalizer $fiscalizer Объект фискализатора
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -409,7 +409,7 @@ final class Receipt extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -417,9 +417,9 @@ final class Receipt extends Entity
|
||||
/**
|
||||
* Регистрирует расход по текущему документу
|
||||
*
|
||||
* @param KktFiscalizer $fiscalizer Объект фискализатора
|
||||
* @param Fiscalizer $fiscalizer Объект фискализатора
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -429,7 +429,7 @@ final class Receipt extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
@@ -437,9 +437,9 @@ final class Receipt extends Entity
|
||||
/**
|
||||
* Регистрирует возврат расхода по текущему документу
|
||||
*
|
||||
* @param KktFiscalizer $fiscalizer Объект фискализатора
|
||||
* @param Fiscalizer $fiscalizer Объект фискализатора
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан новый UUID)
|
||||
* @return KktResponse|null
|
||||
* @return AtolResponse|null
|
||||
* @throws AuthFailedException
|
||||
* @throws EmptyLoginException
|
||||
* @throws EmptyPasswordException
|
||||
@@ -449,7 +449,7 @@ final class Receipt extends Entity
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @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);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ declare(strict_types = 1);
|
||||
|
||||
namespace AtolOnline\Exceptions;
|
||||
|
||||
use AtolOnline\Api\KktResponse;
|
||||
use AtolOnline\Api\AtolResponse;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
|
||||
@@ -23,11 +23,11 @@ class AuthFailedException extends Exception
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @param KktResponse $response
|
||||
* @param AtolResponse $response
|
||||
* @param string $message
|
||||
*/
|
||||
#[Pure]
|
||||
public function __construct(KktResponse $response, string $message = '')
|
||||
public function __construct(AtolResponse $response, string $message = '')
|
||||
{
|
||||
parent::__construct(($message ?: 'Ошибка авторизации: ') . ': ' . $response);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user