Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7558cb6638 | |||
| d3fe2cba9a | |||
| e70a65fa44 | |||
| ba5166f2cf | |||
| 93f5186b15 | |||
| f2b4952aa5 | |||
| 7899daf421 |
@@ -172,7 +172,7 @@ class Kkt extends Client
|
|||||||
*/
|
*/
|
||||||
public function setCallbackUrl(string $url)
|
public function setCallbackUrl(string $url)
|
||||||
{
|
{
|
||||||
$this->kkt_config['prod']['callback_url'] = $url;
|
$this->kkt_config[$this->isTestMode() ? 'test' : 'prod']['callback_url'] = $url;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,6 +364,28 @@ class Kkt extends Client
|
|||||||
return $response;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Сбрасывает настройки ККТ по умолчанию
|
* Сбрасывает настройки ККТ по умолчанию
|
||||||
*/
|
*/
|
||||||
@@ -390,7 +412,7 @@ class Kkt extends Client
|
|||||||
{
|
{
|
||||||
$headers['Content-type'] = 'application/json; charset=utf-8';
|
$headers['Content-type'] = 'application/json; charset=utf-8';
|
||||||
if ($this->getAuthToken()) {
|
if ($this->getAuthToken()) {
|
||||||
$headers['Token'] = $this->auth_token;
|
$headers['Token'] = $this->getAuthToken();
|
||||||
}
|
}
|
||||||
return $headers;
|
return $headers;
|
||||||
}
|
}
|
||||||
@@ -429,6 +451,7 @@ class Kkt extends Client
|
|||||||
* @param mixed $data Данные для передачи
|
* @param mixed $data Данные для передачи
|
||||||
* @param array|null $options Параметры Guzzle
|
* @param array|null $options Параметры Guzzle
|
||||||
* @return \AtolOnline\Api\KktResponse
|
* @return \AtolOnline\Api\KktResponse
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
* @see https://guzzle.readthedocs.io/en/latest/request-options.html
|
* @see https://guzzle.readthedocs.io/en/latest/request-options.html
|
||||||
*/
|
*/
|
||||||
protected function sendAtolRequest(string $http_method, string $api_method, $data = null, array $options = null)
|
protected function sendAtolRequest(string $http_method, string $api_method, $data = null, array $options = null)
|
||||||
@@ -449,6 +472,7 @@ class Kkt extends Client
|
|||||||
* Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов
|
* Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
protected function auth()
|
protected function auth()
|
||||||
{
|
{
|
||||||
@@ -471,33 +495,24 @@ class Kkt extends Client
|
|||||||
* @param string $api_method Метод API
|
* @param string $api_method Метод API
|
||||||
* @param string $type Тип документа: receipt, correction
|
* @param string $type Тип документа: receipt, correction
|
||||||
* @param \AtolOnline\Entities\Document $document Объект документа
|
* @param \AtolOnline\Entities\Document $document Объект документа
|
||||||
|
* @param string|null $external_id Уникальный код документа (если не указан, то будет создан UUID)
|
||||||
* @return \AtolOnline\Api\KktResponse
|
* @return \AtolOnline\Api\KktResponse
|
||||||
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException
|
||||||
* @throws \Exception
|
* @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);
|
$type = trim($type);
|
||||||
if (!in_array($type, ['receipt', 'correction'])) {
|
if (!in_array($type, ['receipt', 'correction'])) {
|
||||||
throw new AtolWrongDocumentTypeException($type);
|
throw new AtolWrongDocumentTypeException($type);
|
||||||
}
|
}
|
||||||
$this->auth();
|
$this->auth();
|
||||||
$data = [
|
$data['timestamp'] = date('d.m.y H:i:s');
|
||||||
'timestamp' => date('d.m.y H:i:s'),
|
$data['external_id'] = $external_id ?: Uuid::uuid4()->toString();
|
||||||
'external_id' => Uuid::uuid4()->toString(),
|
$data[$type] = $document;
|
||||||
'service' => ['callback_url' => $this->getCallbackUrl()],
|
if ($this->getCallbackUrl()) {
|
||||||
$type => $document,
|
$data['service'] = ['callback_url' => $this->getCallbackUrl()];
|
||||||
];
|
}
|
||||||
return $this->sendAtolRequest('POST', trim($api_method), $data);
|
return $this->sendAtolRequest('POST', trim($api_method), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Возвращает текущий токен авторизации
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getAuthToken()
|
|
||||||
{
|
|
||||||
return $this->auth_token;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -405,7 +405,7 @@ class Document extends Entity
|
|||||||
$json['company'] = $this->getCompany()->jsonSerialize(); // обязательно
|
$json['company'] = $this->getCompany()->jsonSerialize(); // обязательно
|
||||||
}
|
}
|
||||||
if ($this->getPayments()) {
|
if ($this->getPayments()) {
|
||||||
$json['payments'] = $this->getPayments()->jsonSerialize(); // обязательно
|
$json['payments'] = $this->payments->jsonSerialize(); // обязательно
|
||||||
}
|
}
|
||||||
if ($this->getCashier()) {
|
if ($this->getCashier()) {
|
||||||
$json['cashier'] = $this->getCashier();
|
$json['cashier'] = $this->getCashier();
|
||||||
@@ -417,7 +417,7 @@ class Document extends Entity
|
|||||||
$json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных
|
$json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных
|
||||||
}
|
}
|
||||||
if ($this->getItems()) {
|
if ($this->getItems()) {
|
||||||
$json['items'] = $this->getItems()->jsonSerialize(); // обязательно для некоррекционных
|
$json['items'] = $this->items->jsonSerialize(); // обязательно для некоррекционных
|
||||||
}
|
}
|
||||||
$json['total'] = $this->calcTotal(); // обязательно для некоррекционных
|
$json['total'] = $this->calcTotal(); // обязательно для некоррекционных
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class ItemArray extends Entity
|
|||||||
protected function validateCount(?array $items = null): bool
|
protected function validateCount(?array $items = null): bool
|
||||||
{
|
{
|
||||||
if ((!empty($items) && count($items) >= self::MAX_COUNT) || count($this->items) >= self::MAX_COUNT) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace AtolOnline\Entities;
|
namespace AtolOnline\Entities;
|
||||||
|
|
||||||
use AtolOnline\Api\SellSchema;
|
|
||||||
use AtolOnline\Exceptions\AtolTooManyPaymentsException;
|
use AtolOnline\Exceptions\AtolTooManyPaymentsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +18,11 @@ use AtolOnline\Exceptions\AtolTooManyPaymentsException;
|
|||||||
*/
|
*/
|
||||||
class PaymentArray extends Entity
|
class PaymentArray extends Entity
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Максимальное количество элементов массива
|
||||||
|
*/
|
||||||
|
public const MAX_COUNT = 10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Payment[] Массив оплат
|
* @var Payment[] Массив оплат
|
||||||
*/
|
*/
|
||||||
@@ -99,9 +103,8 @@ class PaymentArray extends Entity
|
|||||||
*/
|
*/
|
||||||
protected function validateCount(?array $payments = null): bool
|
protected function validateCount(?array $payments = null): bool
|
||||||
{
|
{
|
||||||
$max_items = SellSchema::get()->properties->receipt->properties->payments->maxItems;
|
if ((!empty($payments) && count($payments) >= self::MAX_COUNT) || count($this->payments) >= self::MAX_COUNT) {
|
||||||
if ((!empty($payments) && count($payments) >= $max_items) || count($this->payments) >= $max_items) {
|
throw new AtolTooManyPaymentsException(count($payments), self::MAX_COUNT);
|
||||||
throw new AtolTooManyPaymentsException($max_items);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
|
|
||||||
namespace AtolOnline\Entities;
|
namespace AtolOnline\Entities;
|
||||||
|
|
||||||
use AtolOnline\Api\SellSchema;
|
|
||||||
use AtolOnline\Exceptions\AtolTooManyVatsException;
|
use AtolOnline\Exceptions\AtolTooManyVatsException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -19,6 +18,11 @@ use AtolOnline\Exceptions\AtolTooManyVatsException;
|
|||||||
*/
|
*/
|
||||||
class VatArray extends Entity
|
class VatArray extends Entity
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Максимальное количество элементов массива
|
||||||
|
*/
|
||||||
|
public const MAX_COUNT = 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Vat[] Массив ставок НДС
|
* @var Vat[] Массив ставок НДС
|
||||||
*/
|
*/
|
||||||
@@ -103,9 +107,8 @@ class VatArray extends Entity
|
|||||||
*/
|
*/
|
||||||
protected function validateCount(?array $vats = null): bool
|
protected function validateCount(?array $vats = null): bool
|
||||||
{
|
{
|
||||||
$max_items = SellSchema::get()->properties->receipt->properties->vats->maxItems;
|
if ((!empty($vats) && count($vats) >= self::MAX_COUNT) || count($this->vats) >= self::MAX_COUNT) {
|
||||||
if ((!empty($vats) && count($vats) >= $max_items) || count($this->vats) >= $max_items) {
|
throw new AtolTooManyVatsException(count($vats), self::MAX_COUNT);
|
||||||
throw new AtolTooManyVatsException(count($vats), $max_items);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user