Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c14b680be4 | |||
| 7558cb6638 | |||
| d3fe2cba9a | |||
| e70a65fa44 | |||
| ba5166f2cf | |||
| 93f5186b15 | |||
| f2b4952aa5 | |||
| 7899daf421 | |||
| 4cf6e81d5f | |||
| 9d7dd75cd9 | |||
| 4d7e5dd76e | |||
| 0f658d38a9 |
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,104 +222,115 @@ class Kkt extends Client
|
|||||||
* Регистрирует документ прихода
|
* Регистрирует документ прихода
|
||||||
*
|
*
|
||||||
* @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 \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sell(Document $document)
|
public function sell(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if ($document->getCorrectionInfo()) {
|
if ($document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
||||||
}
|
}
|
||||||
return $this->registerDocument('sell', 'receipt', $document);
|
return $this->registerDocument('sell', 'receipt', $document, $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Регистрирует документ возврата прихода
|
* Регистрирует документ возврата прихода
|
||||||
*
|
*
|
||||||
* @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\AtolPriceTooHighException Слишком большая сумма
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException Слишком большая сумма
|
||||||
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
|
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
|
||||||
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
||||||
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
||||||
*/
|
*/
|
||||||
public function sellRefund(Document $document)
|
public function sellRefund(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if ($document->getCorrectionInfo()) {
|
if ($document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
||||||
}
|
}
|
||||||
return $this->registerDocument('sell_refund', 'receipt', $document->clearVats());
|
return $this->registerDocument('sell_refund', 'receipt', $document->clearVats(), $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Регистрирует документ коррекции прихода
|
* Регистрирует документ коррекции прихода
|
||||||
*
|
*
|
||||||
* @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 \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
|
||||||
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
|
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
public function sellCorrection(Document $document)
|
public function sellCorrection(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if (!$document->getCorrectionInfo()) {
|
if (!$document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException();
|
throw new AtolCorrectionInfoException();
|
||||||
}
|
}
|
||||||
$document->setClient(null)->setItems([]);
|
$document->setClient(null)->setItems([]);
|
||||||
return $this->registerDocument('sell_correction', 'correction', $document);
|
return $this->registerDocument('sell_correction', 'correction', $document, $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Регистрирует документ расхода
|
* Регистрирует документ расхода
|
||||||
*
|
*
|
||||||
* @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 \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
public function buy(Document $document)
|
public function buy(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if ($document->getCorrectionInfo()) {
|
if ($document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
||||||
}
|
}
|
||||||
return $this->registerDocument('buy', 'receipt', $document);
|
return $this->registerDocument('buy', 'receipt', $document, $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Регистрирует документ возврата расхода
|
* Регистрирует документ возврата расхода
|
||||||
*
|
*
|
||||||
* @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\AtolPriceTooHighException Слишком большая сумма
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException Слишком большая сумма
|
||||||
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
|
* @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС
|
||||||
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
* @throws \AtolOnline\Exceptions\AtolWrongDocumentTypeException Некорректный тип документа
|
||||||
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе есть данные коррекции
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
public function buyRefund(Document $document)
|
public function buyRefund(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if ($document->getCorrectionInfo()) {
|
if ($document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
throw new AtolCorrectionInfoException('Некорректная операция над документом коррекции');
|
||||||
}
|
}
|
||||||
return $this->registerDocument('buy_refund', 'receipt', $document->clearVats());
|
return $this->registerDocument('buy_refund', 'receipt', $document->clearVats(), $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Регистрирует документ коррекции расхода
|
* Регистрирует документ коррекции расхода
|
||||||
*
|
*
|
||||||
* @param Document $document
|
* @param 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 \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
|
* @throws \AtolOnline\Exceptions\AtolCorrectionInfoException В документе отсутствуют данные коррекции
|
||||||
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
|
* @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
public function buyCorrection(Document $document)
|
public function buyCorrection(Document $document, ?string $external_id = null)
|
||||||
{
|
{
|
||||||
if (!$document->getCorrectionInfo()) {
|
if (!$document->getCorrectionInfo()) {
|
||||||
throw new AtolCorrectionInfoException();
|
throw new AtolCorrectionInfoException();
|
||||||
}
|
}
|
||||||
$document->setClient(null)->setItems([]);
|
$document->setClient(null)->setItems([]);
|
||||||
return $this->registerDocument('buy_correction', 'correction', $document);
|
return $this->registerDocument('buy_correction', 'correction', $document, $external_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -364,6 +375,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 +423,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 +462,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 +483,7 @@ class Kkt extends Client
|
|||||||
* Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов
|
* Производит авторизацию на ККТ и получает токен доступа для дальнейших HTTP-запросов
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
|
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||||
*/
|
*/
|
||||||
protected function auth()
|
protected function auth()
|
||||||
{
|
{
|
||||||
@@ -468,36 +503,27 @@ 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ class KktResponse implements JsonSerializable
|
|||||||
/**
|
/**
|
||||||
* Возвращает объект результата запроса
|
* Возвращает объект результата запроса
|
||||||
*
|
*
|
||||||
* @return \stdClass
|
* @return stdClass|null
|
||||||
*/
|
*/
|
||||||
public function getContent(): stdClass
|
public function getContent(): ?stdClass
|
||||||
{
|
{
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,9 +199,9 @@ class Document extends Entity
|
|||||||
/**
|
/**
|
||||||
* Возвращает заданного клиента (покупателя)
|
* Возвращает заданного клиента (покупателя)
|
||||||
*
|
*
|
||||||
* @return Client
|
* @return Client|null
|
||||||
*/
|
*/
|
||||||
public function getClient(): Client
|
public function getClient(): ?Client
|
||||||
{
|
{
|
||||||
return $this->client;
|
return $this->client;
|
||||||
}
|
}
|
||||||
@@ -221,9 +221,9 @@ class Document extends Entity
|
|||||||
/**
|
/**
|
||||||
* Возвращает заданную компанию (продавца)
|
* Возвращает заданную компанию (продавца)
|
||||||
*
|
*
|
||||||
* @return Company
|
* @return Company|null
|
||||||
*/
|
*/
|
||||||
public function getCompany(): Company
|
public function getCompany(): ?Company
|
||||||
{
|
{
|
||||||
return $this->company;
|
return $this->company;
|
||||||
}
|
}
|
||||||
@@ -388,7 +388,7 @@ class Document extends Entity
|
|||||||
$doc->payments->add($payment);
|
$doc->payments->add($payment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($array['total'] != $doc->calcTotal()) {
|
if (isset($array['total']) && $array['total'] != $doc->calcTotal()) {
|
||||||
throw new AtolException('Real total sum not equals to provided in JSON one');
|
throw new AtolException('Real total sum not equals to provided in JSON one');
|
||||||
}
|
}
|
||||||
return $doc;
|
return $doc;
|
||||||
@@ -401,16 +401,24 @@ class Document extends Entity
|
|||||||
*/
|
*/
|
||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
$json['company'] = $this->getCompany()->jsonSerialize();// обязательно
|
if ($this->getCompany()) {
|
||||||
$json['payments'] = $this->payments->jsonSerialize(); // обязательно
|
$json['company'] = $this->getCompany()->jsonSerialize(); // обязательно
|
||||||
|
}
|
||||||
|
if ($this->getPayments()) {
|
||||||
|
$json['payments'] = $this->payments->jsonSerialize(); // обязательно
|
||||||
|
}
|
||||||
if ($this->getCashier()) {
|
if ($this->getCashier()) {
|
||||||
$json['cashier'] = $this->getCashier();
|
$json['cashier'] = $this->getCashier();
|
||||||
}
|
}
|
||||||
if ($this->getCorrectionInfo()) {
|
if ($this->getCorrectionInfo()) {
|
||||||
$json['correction_info'] = $this->getCorrectionInfo()->jsonSerialize(); // обязательно для коррекционных
|
$json['correction_info'] = $this->getCorrectionInfo()->jsonSerialize(); // обязательно для коррекционных
|
||||||
} else {
|
} else {
|
||||||
$json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных
|
if ($this->getClient()) {
|
||||||
$json['items'] = $this->items->jsonSerialize(); // обязательно для некоррекционных
|
$json['client'] = $this->getClient()->jsonSerialize(); // обязательно для некоррекционных
|
||||||
|
}
|
||||||
|
if ($this->getItems()) {
|
||||||
|
$json['items'] = $this->items->jsonSerialize(); // обязательно для некоррекционных
|
||||||
|
}
|
||||||
$json['total'] = $this->calcTotal(); // обязательно для некоррекционных
|
$json['total'] = $this->calcTotal(); // обязательно для некоррекционных
|
||||||
}
|
}
|
||||||
if ($this->getVats()) {
|
if ($this->getVats()) {
|
||||||
@@ -418,4 +426,4 @@ class Document extends Entity
|
|||||||
}
|
}
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,22 @@ class BasicTestCase extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function tearDown(): void
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
//parent::tearDown();
|
//parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Возвращает случайную строку указанной длины
|
||||||
|
*
|
||||||
|
* @param int $length
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function randomString($length = 8)
|
||||||
|
{
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$string = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$string .= $characters[mt_rand(0, strlen($characters) - 1)];
|
||||||
|
}
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -85,10 +85,7 @@ class ItemTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует установку ставки НДС разными путями
|
* Тестирует установку ставки НДС разными путями
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testSetVat()
|
public function testSetVat()
|
||||||
{
|
{
|
||||||
@@ -102,25 +99,21 @@ class ItemTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинном наименовании
|
* Тестирует исключение о слишком длинном наименовании
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolNameTooLongException()
|
public function testAtolNameTooLongException()
|
||||||
{
|
{
|
||||||
$item = new Item();
|
$item = new Item();
|
||||||
$this->expectException(AtolNameTooLongException::class);
|
$this->expectException(AtolNameTooLongException::class);
|
||||||
$item->setName('Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан Банан');
|
$item->setName(self::randomString(130));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком высоком количестве
|
* Тестирует исключение о слишком высоком количестве
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
* @throws \AtolOnline\Exceptions\AtolTooManyException
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
* @throws \AtolOnline\Exceptions\AtolUnitTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolQuantityTooHighException()
|
public function testAtolQuantityTooHighException()
|
||||||
{
|
{
|
||||||
@@ -132,10 +125,7 @@ class ItemTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком высокой цене
|
* Тестирует исключение о слишком высокой цене
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
* @throws \AtolOnline\Exceptions\AtolPriceTooHighException
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolPriceTooHighException()
|
public function testAtolPriceTooHighException()
|
||||||
{
|
{
|
||||||
@@ -147,11 +137,7 @@ class ItemTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинных польз. данных
|
* Тестирует исключение о слишком длинных польз. данных
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolUserdataTooLongException
|
* @throws \AtolOnline\Exceptions\AtolUserdataTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolUserdataTooLongException()
|
public function testAtolUserdataTooLongException()
|
||||||
{
|
{
|
||||||
@@ -163,10 +149,7 @@ class ItemTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинной единице измерения
|
* Тестирует исключение о слишком длинной единице измерения
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolNameTooLongException
|
* @throws \AtolOnline\Exceptions\AtolUnitTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolPriceTooHighException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolTooManyException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolUnitTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolUnitTooLongException()
|
public function testAtolUnitTooLongException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ class ClientTest extends BasicTestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Тестирует установку параметров
|
* Тестирует установку параметров
|
||||||
*
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
@@ -48,30 +42,18 @@ class ClientTest extends BasicTestCase
|
|||||||
* Тестирует исключение о слишком длинном имени
|
* Тестирует исключение о слишком длинном имени
|
||||||
*
|
*
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolNameTooLongException()
|
public function testAtolNameTooLongException()
|
||||||
{
|
{
|
||||||
$customer = new Client();
|
$customer = new Client();
|
||||||
$this->expectException(AtolNameTooLongException::class);
|
$this->expectException(AtolNameTooLongException::class);
|
||||||
$customer->setName('John Doe John Doe John Doe John Doe John Doe '.
|
$customer->setName(self::randomString(257));
|
||||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
|
||||||
'Doe John Doe John Doe John Doe John DoeJohn Doe John Doe John Doe '.
|
|
||||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
|
||||||
'Doe John Doe John Doe John Doe John Doe John Doe John Doe');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинном телефоне
|
* Тестирует исключение о слишком длинном телефоне
|
||||||
*
|
*
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolPhoneTooLongException()
|
public function testAtolPhoneTooLongException()
|
||||||
{
|
{
|
||||||
@@ -84,42 +66,32 @@ class ClientTest extends BasicTestCase
|
|||||||
* Тестирует исключение о слишком длинной почте
|
* Тестирует исключение о слишком длинной почте
|
||||||
*
|
*
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolEmailTooLongException()
|
public function testAtolEmailTooLongException()
|
||||||
{
|
{
|
||||||
$customer = new Client();
|
$customer = new Client();
|
||||||
$this->expectException(AtolEmailTooLongException::class);
|
$this->expectException(AtolEmailTooLongException::class);
|
||||||
$customer->setEmail('johnjohnjohnjohnjohnjohndoedoedoedoe@exampleexampleexampleexample.com');
|
$customer->setEmail(self::randomString(65));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о некорректной почте
|
* Тестирует исключение о некорректной почте
|
||||||
*
|
*
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolEmailValidateException()
|
public function testAtolEmailValidateException()
|
||||||
{
|
{
|
||||||
$customer = new Client();
|
$customer = new Client();
|
||||||
$this->expectException(AtolEmailValidateException::class);
|
$this->expectException(AtolEmailValidateException::class);
|
||||||
$customer->setEmail('John Doe');
|
$customer->setEmail(self::randomString(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о некорректной длине ИНН
|
* Тестирует исключение о некорректной длине ИНН
|
||||||
*
|
*
|
||||||
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolNameTooLongException
|
|
||||||
* @throws \AtolOnline\Exceptions\AtolPhoneTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolInnWrongLengthException()
|
public function testAtolInnWrongLengthException()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ class CompanyTest extends BasicTestCase
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Тестирует установку параметров через конструктор
|
* Тестирует установку параметров через конструктор
|
||||||
*
|
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testConstructor()
|
public function testConstructor()
|
||||||
{
|
{
|
||||||
@@ -46,10 +41,7 @@ class CompanyTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о некорректной длине ИНН
|
* Тестирует исключение о некорректной длине ИНН
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
* @throws \AtolOnline\Exceptions\AtolInnWrongLengthException
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolInnWrongLengthException()
|
public function testAtolInnWrongLengthException()
|
||||||
{
|
{
|
||||||
@@ -62,49 +54,38 @@ class CompanyTest extends BasicTestCase
|
|||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинном платёжном адресе
|
* Тестирует исключение о слишком длинном платёжном адресе
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
* @throws \AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolPaymentAddressTooLongException()
|
public function testAtolPaymentAddressTooLongException()
|
||||||
{
|
{
|
||||||
$company = new Company();
|
$company = new Company();
|
||||||
$this->expectException(AtolPaymentAddressTooLongException::class);
|
$this->expectException(AtolPaymentAddressTooLongException::class);
|
||||||
$company->setPaymentAddress('John Doe John Doe John Doe John Doe '.
|
$company->setPaymentAddress(self::randomString(257));
|
||||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
|
||||||
'Doe John Doe John Doe John Doe John DoeJohn Doe John Doe John Doe John Doe '.
|
|
||||||
'John Doe John Doe John Doe John Doe John Doe John Doe John Doe John Doe John '.
|
|
||||||
'Doe John Doe John Doe John Doe John Doe');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о слишком длинной почте
|
* Тестирует исключение о слишком длинной почте
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolEmailTooLongException()
|
public function testAtolEmailTooLongException()
|
||||||
{
|
{
|
||||||
$company = new Company();
|
$company = new Company();
|
||||||
$this->expectException(AtolEmailTooLongException::class);
|
$this->expectException(AtolEmailTooLongException::class);
|
||||||
$company->setEmail('johnjohnjohnjohnjohnjohndoedoedoedoe@exampleexampleexampleexample.com');
|
$company->setEmail(self::randomString(65));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Тестирует исключение о некорректной почте
|
* Тестирует исключение о некорректной почте
|
||||||
*
|
*
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailValidateException
|
* @throws \AtolOnline\Exceptions\AtolEmailTooLongException
|
||||||
* @throws AtolOnline\Exceptions\AtolEmailTooLongException
|
* @throws \AtolOnline\Exceptions\AtolEmailValidateException
|
||||||
* @throws AtolOnline\Exceptions\AtolInnWrongLengthException
|
|
||||||
* @throws AtolOnline\Exceptions\AtolPaymentAddressTooLongException
|
|
||||||
*/
|
*/
|
||||||
public function testAtolEmailValidateException()
|
public function testAtolEmailValidateException()
|
||||||
{
|
{
|
||||||
$company = new Company();
|
$company = new Company();
|
||||||
$this->expectException(AtolEmailValidateException::class);
|
$this->expectException(AtolEmailValidateException::class);
|
||||||
$company->setEmail('John Doe');
|
$company->setEmail(self::randomString(15));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user