Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7558cb6638 | |||
| d3fe2cba9a | |||
| e70a65fa44 |
@@ -9,8 +9,7 @@
|
||||
|
||||
namespace AtolOnline\Api;
|
||||
|
||||
use AtolOnline\{Entities\Company,
|
||||
Entities\Document,
|
||||
use AtolOnline\{Entities\Document,
|
||||
Exceptions\AtolCorrectionInfoException,
|
||||
Exceptions\AtolInvalidUuidException,
|
||||
Exceptions\AtolKktLoginEmptyException,
|
||||
@@ -365,6 +364,28 @@ class Kkt extends Client
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает текущий токен авторизации
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthToken(): ?string
|
||||
{
|
||||
return $this->auth_token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает заранее известный токен авторизации
|
||||
*
|
||||
* @param string|null $auth_token
|
||||
* @return $this
|
||||
*/
|
||||
public function setAuthToken(?string $auth_token)
|
||||
{
|
||||
$this->auth_token = $auth_token;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Сбрасывает настройки ККТ по умолчанию
|
||||
*/
|
||||
@@ -474,39 +495,24 @@ class Kkt extends Client
|
||||
* @param string $api_method Метод API
|
||||
* @param string $type Тип документа: receipt, correction
|
||||
* @param \AtolOnline\Entities\Document $document Объект документа
|
||||
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
|
||||
* @return \AtolOnline\Api\KktResponse
|
||||
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
||||
* @throws \Exception
|
||||
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
protected function registerDocument(string $api_method, string $type, Document $document)
|
||||
protected function registerDocument(string $api_method, string $type, Document $document, ?string $external_id = null)
|
||||
{
|
||||
$type = trim($type);
|
||||
if (!in_array($type, ['receipt', 'correction'])) {
|
||||
throw new AtolWrongDocumentTypeException($type);
|
||||
}
|
||||
$this->auth();
|
||||
if ($this->isTestMode()) {
|
||||
$document->setCompany((new Company())
|
||||
->setInn('5544332219')
|
||||
->setPaymentAddress('https://v4.online.atol.ru')
|
||||
);
|
||||
$data['timestamp'] = date('d.m.y H:i:s');
|
||||
$data['external_id'] = $external_id ?: Uuid::uuid4()->toString();
|
||||
$data[$type] = $document;
|
||||
if ($this->getCallbackUrl()) {
|
||||
$data['service'] = ['callback_url' => $this->getCallbackUrl()];
|
||||
}
|
||||
$data = [
|
||||
'timestamp' => date('d.m.y H:i:s'),
|
||||
'external_id' => Uuid::uuid4()->toString(),
|
||||
'service' => ['callback_url' => $this->getCallbackUrl()],
|
||||
$type => $document,
|
||||
];
|
||||
return $this->sendAtolRequest('POST', trim($api_method), $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает текущий токен авторизации
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthToken(): ?string
|
||||
{
|
||||
return $this->auth_token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ class ItemArray extends Entity
|
||||
protected function validateCount(?array $items = null): bool
|
||||
{
|
||||
if ((!empty($items) && count($items) >= self::MAX_COUNT) || count($this->items) >= self::MAX_COUNT) {
|
||||
throw new AtolTooManyItemsException(self::MAX_COUNT);
|
||||
throw new AtolTooManyItemsException(count($items), self::MAX_COUNT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\Api\SellSchema;
|
||||
use AtolOnline\Exceptions\AtolTooManyPaymentsException;
|
||||
|
||||
/**
|
||||
@@ -19,6 +18,11 @@ use AtolOnline\Exceptions\AtolTooManyPaymentsException;
|
||||
*/
|
||||
class PaymentArray extends Entity
|
||||
{
|
||||
/**
|
||||
* Максимальное количество элементов массива
|
||||
*/
|
||||
public const MAX_COUNT = 10;
|
||||
|
||||
/**
|
||||
* @var Payment[] Массив оплат
|
||||
*/
|
||||
@@ -99,9 +103,8 @@ class PaymentArray extends Entity
|
||||
*/
|
||||
protected function validateCount(?array $payments = null): bool
|
||||
{
|
||||
$max_items = SellSchema::get()->properties->receipt->properties->payments->maxItems;
|
||||
if ((!empty($payments) && count($payments) >= $max_items) || count($this->payments) >= $max_items) {
|
||||
throw new AtolTooManyPaymentsException($max_items);
|
||||
if ((!empty($payments) && count($payments) >= self::MAX_COUNT) || count($this->payments) >= self::MAX_COUNT) {
|
||||
throw new AtolTooManyPaymentsException(count($payments), self::MAX_COUNT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\Api\SellSchema;
|
||||
use AtolOnline\Exceptions\AtolTooManyVatsException;
|
||||
|
||||
/**
|
||||
@@ -19,6 +18,11 @@ use AtolOnline\Exceptions\AtolTooManyVatsException;
|
||||
*/
|
||||
class VatArray extends Entity
|
||||
{
|
||||
/**
|
||||
* Максимальное количество элементов массива
|
||||
*/
|
||||
public const MAX_COUNT = 6;
|
||||
|
||||
/**
|
||||
* @var Vat[] Массив ставок НДС
|
||||
*/
|
||||
@@ -103,9 +107,8 @@ class VatArray extends Entity
|
||||
*/
|
||||
protected function validateCount(?array $vats = null): bool
|
||||
{
|
||||
$max_items = SellSchema::get()->properties->receipt->properties->vats->maxItems;
|
||||
if ((!empty($vats) && count($vats) >= $max_items) || count($this->vats) >= $max_items) {
|
||||
throw new AtolTooManyVatsException(count($vats), $max_items);
|
||||
if ((!empty($vats) && count($vats) >= self::MAX_COUNT) || count($this->vats) >= self::MAX_COUNT) {
|
||||
throw new AtolTooManyVatsException(count($vats), self::MAX_COUNT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user