diff --git a/src/AtolOnline/Api/Kkt.php b/src/AtolOnline/Api/Kkt.php index 2ab02ae..979e464 100644 --- a/src/AtolOnline/Api/Kkt.php +++ b/src/AtolOnline/Api/Kkt.php @@ -11,10 +11,10 @@ namespace AtolOnline\Api; use AtolOnline\{Entities\Document, Exceptions\AtolCorrectionInfoException, + Exceptions\AtolInvalidUuidException, Exceptions\AtolKktLoginEmptyException, Exceptions\AtolKktLoginTooLongException, Exceptions\AtolKktPasswordEmptyException, - Exceptions\AtolUuidValidateException, Exceptions\AtolWrongDocumentTypeException }; use GuzzleHttp\Client; @@ -327,13 +327,13 @@ class Kkt extends Client * * @param string $uuid UUID регистрации * @return \AtolOnline\Api\KktResponse - * @throws \AtolOnline\Exceptions\AtolUuidValidateException Некорректный UUID документа + * @throws \AtolOnline\Exceptions\AtolInvalidUuidException Некорректный UUID документа */ public function getDocumentStatus(string $uuid) { $uuid = trim($uuid); if (!Uuid::isValid($uuid)) { - throw new AtolUuidValidateException($uuid); + throw new AtolInvalidUuidException($uuid); } $this->auth(); return $this->sendAtolRequest('GET', 'report/'.$uuid); diff --git a/src/AtolOnline/Entities/Document.php b/src/AtolOnline/Entities/Document.php index d06d986..302812a 100644 --- a/src/AtolOnline/Entities/Document.php +++ b/src/AtolOnline/Entities/Document.php @@ -10,6 +10,8 @@ namespace AtolOnline\Entities; use AtolOnline\Exceptions\AtolCashierTooLongException; +use AtolOnline\Exceptions\AtolException; +use AtolOnline\Exceptions\AtolInvalidJsonException; /** * Класс, описывающий документ @@ -60,10 +62,6 @@ class Document extends Entity /** * Document constructor. - * - * @throws \AtolOnline\Exceptions\AtolTooManyItemsException Слишком много предметов расчёта - * @throws \AtolOnline\Exceptions\AtolTooManyPaymentsException Слишком много оплат - * @throws \AtolOnline\Exceptions\AtolTooManyVatsException Слишком много ставок НДС */ public function __construct() { @@ -82,10 +80,6 @@ class Document extends Entity public function clearVats() { $this->setVats([]); - foreach ($this->getItems() as &$item) { - $item->setVatType(null); - } - $this->calcTotal(); return $this; } @@ -98,11 +92,7 @@ class Document extends Entity */ public function addVat(Vat $vat) { - if (count($this->getVats()) == 0 && !$vat->getSum()) { - $vat->setSum($this->calcTotal()); - } $this->vats->add($vat); - $this->calcTotal(); return $this; } @@ -127,7 +117,6 @@ class Document extends Entity public function setVats(array $vats) { $this->vats->set($vats); - $this->calcTotal(); return $this; } @@ -271,8 +260,8 @@ class Document extends Entity public function setCashier(?string $cashier) { $cashier = trim($cashier); - if (strlen($cashier) > 64) { - throw new AtolCashierTooLongException($cashier); + if ((function_exists('mb_strlen') ? mb_strlen($cashier) : strlen($cashier)) > 64) { + throw new AtolCashierTooLongException($cashier, 64); } $this->cashier = $cashier; return $this; @@ -309,11 +298,10 @@ class Document extends Entity public function calcTotal() { $sum = 0; + $this->clearVats(); foreach ($this->items->get() as $item) { $sum += $item->calcSum(); - } - foreach ($this->vats->get() as $vat) { - $vat->setSum($sum); + $this->addVat(new Vat($item->getVat()->getType(), $item->getSum())); } return $this->total = round($sum, 2); } @@ -329,7 +317,89 @@ class Document extends Entity } /** - * @inheritDoc + * Собирает объект документа из сырой json-строки + * + * @param string $json + * @return \AtolOnline\Entities\Document + * @throws \AtolOnline\Exceptions\AtolEmailTooLongException + * @throws \AtolOnline\Exceptions\AtolEmailValidateException + * @throws \AtolOnline\Exceptions\AtolException + * @throws \AtolOnline\Exceptions\AtolInnWrongLengthException + * @throws \AtolOnline\Exceptions\AtolInvalidJsonException + * @throws \AtolOnline\Exceptions\AtolNameTooLongException + * @throws \AtolOnline\Exceptions\AtolPaymentAddressTooLongException + * @throws \AtolOnline\Exceptions\AtolPhoneTooLongException + * @throws \AtolOnline\Exceptions\AtolPriceTooHighException + * @throws \AtolOnline\Exceptions\AtolTooManyException + * @throws \AtolOnline\Exceptions\AtolTooManyItemsException + * @throws \AtolOnline\Exceptions\AtolTooManyPaymentsException + * @throws \AtolOnline\Exceptions\AtolUnitTooLongException + * @throws \AtolOnline\Exceptions\AtolUserdataTooLongException + */ + public static function fromRaw(string $json) + { + $object = json_decode($json); + if (json_last_error() !== JSON_ERROR_NONE) { + throw new AtolInvalidJsonException(); + } + $doc = new self(); + if ($object->company) { + $doc->setCompany(new Company( + $object->company->sno ?? null, + $object->company->inn ?? null, + $object->company->payment_address ?? null, + $object->company->email ?? null + )); + } + if ($object->client) { + $doc->setClient(new Client( + $object->client->name ?? null, + $object->client->phone ?? null, + $object->client->email ?? null, + $object->client->inn ?? null + )); + } + if ($object->items) { + foreach ($object->items as $obj_item) { + $item = new Item( + $obj_item->name ?? null, + $obj_item->price ?? null, + $obj_item->quantity ?? null, + $obj_item->measurement_unit ?? null, + $obj_item->vat->type ?? null, + $obj_item->payment_object ?? null, + $obj_item->payment_method ?? null + ); + if (!empty($obj_item->user_data)) { + $item->setUserData($obj_item->user_data ?? null); + } + $doc->addItem($item); + } + } + if ($object->payments) { + foreach ($object->payments as $obj_payment) { + $doc->payments->add(new Payment( + $obj_payment->type, + $obj_payment->sum + )); + } + } + //if ($object->vats) { + // foreach ($object->vats as $obj_vat) { + // $doc->vats->add(new Vat( + // $obj_vat->type + // )); + // } + //} + if ($object->total != $doc->calcTotal()) { + throw new AtolException('Real total sum not equals to provided in JSON one'); + } + return $doc; + } + + /** + * Возвращает массив для кодирования в json + * * @throws \Exception */ public function jsonSerialize() diff --git a/src/AtolOnline/Entities/Item.php b/src/AtolOnline/Entities/Item.php index 0d5457b..f421336 100644 --- a/src/AtolOnline/Entities/Item.php +++ b/src/AtolOnline/Entities/Item.php @@ -11,11 +11,10 @@ namespace AtolOnline\Entities; use AtolOnline\{Exceptions\AtolNameTooLongException, Exceptions\AtolPriceTooHighException, - Exceptions\AtolQuantityTooHighException, + Exceptions\AtolTooManyException, Exceptions\AtolUnitTooLongException, Exceptions\AtolUserdataTooLongException, - Traits\RublesKopeksConverter -}; + Traits\RublesKopeksConverter}; /** * Предмет расчёта (товар, услуга) @@ -83,7 +82,7 @@ class Item extends Entity * @param string|null $payment_method Способ расчёта * @throws AtolNameTooLongException Слишком длинное наименование * @throws AtolPriceTooHighException Слишком высокая цена за одну единицу - * @throws AtolQuantityTooHighException Слишком большое количество + * @throws AtolTooManyException Слишком большое количество * @throws AtolUnitTooLongException Слишком длинное название единицы измерения */ public function __construct( @@ -101,17 +100,17 @@ class Item extends Entity if ($price) { $this->setPrice($price); } - if ($payment_object) { - $this->setPaymentObject($payment_object); - } if ($quantity) { $this->setQuantity($quantity); } + if ($measurement_unit) { + $this->setMeasurementUnit($measurement_unit); + } if ($vat_type) { $this->setVatType($vat_type); } - if ($measurement_unit) { - $this->setMeasurementUnit($measurement_unit); + if ($payment_object) { + $this->setPaymentObject($payment_object); } if ($payment_method) { $this->setPaymentMethod($payment_method); @@ -188,7 +187,7 @@ class Item extends Entity * @param float $quantity Количество * @param string|null $measurement_unit Единица измерения количества * @return $this - * @throws AtolQuantityTooHighException Слишком большое количество + * @throws AtolTooManyException Слишком большое количество * @throws AtolPriceTooHighException Слишком высокая общая стоимость * @throws AtolUnitTooLongException Слишком длинное название единицы измерения */ @@ -196,7 +195,7 @@ class Item extends Entity { $quantity = round($quantity, 3); if ($quantity > 99999.999) { - throw new AtolQuantityTooHighException($quantity, 99999.999); + throw new AtolTooManyException($quantity, 99999.999); } $this->quantity = $quantity; $this->calcSum(); @@ -226,7 +225,7 @@ class Item extends Entity public function setMeasurementUnit(string $measurement_unit) { $measurement_unit = trim($measurement_unit); - if (strlen($measurement_unit) > 16) { + if ((function_exists('mb_strlen') ? mb_strlen($measurement_unit) : strlen($measurement_unit)) > 16) { throw new AtolUnitTooLongException($measurement_unit, 16); } $this->measurement_unit = $measurement_unit; diff --git a/src/AtolOnline/Entities/Vat.php b/src/AtolOnline/Entities/Vat.php index 6b1780c..29d81c6 100644 --- a/src/AtolOnline/Entities/Vat.php +++ b/src/AtolOnline/Entities/Vat.php @@ -26,12 +26,12 @@ class Vat extends Entity private $type; /** - * @var int Сумма в копейках, от которой пересчитывается размер налога + * @var int Сумма в копейках, от которой пересчитывается размер НДС */ private $sum_original = 0; /** - * @var int Сумма налога в копейках + * @var int Сумма НДС в копейках */ private $sum_final = 0; @@ -66,18 +66,19 @@ class Vat extends Entity case VatTypes::VAT0: return 0; case VatTypes::VAT10: - return $kopeks * 10 / 100; + //return $kopeks * 10 / 100; case VatTypes::VAT110: return $kopeks * 10 / 110; case VatTypes::VAT18: - return $kopeks * 18 / 100; + //return $kopeks * 18 / 100; case VatTypes::VAT118: return $kopeks * 18 / 118; case VatTypes::VAT20: - return $kopeks * 20 / 100; + //return $kopeks * 20 / 100; case VatTypes::VAT120: return $kopeks * 20 / 120; } + return 0; } /** diff --git a/src/AtolOnline/Entities/VatArray.php b/src/AtolOnline/Entities/VatArray.php index 3ad156c..391fe4a 100644 --- a/src/AtolOnline/Entities/VatArray.php +++ b/src/AtolOnline/Entities/VatArray.php @@ -62,7 +62,11 @@ class VatArray extends Entity public function add(Vat $vat) { if ($this->validateCount()) { - $this->vats[] = $vat; + if (isset($this->vats[$vat->getType()])) { + $this->vats[$vat->getType()]->addSum($vat->getSum()); + } else { + $this->vats[$vat->getType()] = $vat; + } } return $this; } @@ -101,7 +105,7 @@ class VatArray extends Entity { $max_items = SellSchema::get()->properties->receipt->properties->vats->maxItems; if ((!empty($vats) && count($vats) >= $max_items) || count($this->vats) >= $max_items) { - throw new AtolTooManyVatsException($max_items); + throw new AtolTooManyVatsException(count($vats), $max_items); } return true; } diff --git a/src/AtolOnline/Exceptions/AtolCashierTooLongException.php b/src/AtolOnline/Exceptions/AtolCashierTooLongException.php index 5917713..3f0ec20 100644 --- a/src/AtolOnline/Exceptions/AtolCashierTooLongException.php +++ b/src/AtolOnline/Exceptions/AtolCashierTooLongException.php @@ -9,26 +9,22 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке указать слишком длинное имя кассира * * @package AtolOnline\Exceptions */ -class AtolCashierTooLongException extends AtolException +class AtolCashierTooLongException extends AtolTooLongException { /** - * AtolCashierTooLongException constructor. - * - * @param $name - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($name, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком длинное имя кассира (макс. длина 64, фактически '.strlen($name).'): '.$name; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1021, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Cashier name is too long'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolCorrectionInfoException.php b/src/AtolOnline/Exceptions/AtolCorrectionInfoException.php index 594f336..bda765b 100644 --- a/src/AtolOnline/Exceptions/AtolCorrectionInfoException.php +++ b/src/AtolOnline/Exceptions/AtolCorrectionInfoException.php @@ -9,8 +9,6 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке зарегистрировать документ без данных коррекции * @@ -19,15 +17,7 @@ use Throwable; class AtolCorrectionInfoException extends AtolException { /** - * AtolNoCorrectionInfoException constructor. - * - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @var string Сообщение об ошибке */ - public function __construct($message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'В документе отсутствуют данные коррекции'; - parent::__construct($message, $code, $previous); - } + protected $message = 'Document must have correction info'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolEmailEmptyException.php b/src/AtolOnline/Exceptions/AtolEmailEmptyException.php index 17cd69d..8dcbc30 100644 --- a/src/AtolOnline/Exceptions/AtolEmailEmptyException.php +++ b/src/AtolOnline/Exceptions/AtolEmailEmptyException.php @@ -9,8 +9,6 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке указать пустой email * @@ -19,15 +17,15 @@ use Throwable; class AtolEmailEmptyException extends AtolException { /** - * AtolEmailEmptyException constructor. - * - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Email не может быть пустым'; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1008, + 1117, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Email cannot be empty'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolEmailTooLongException.php b/src/AtolOnline/Exceptions/AtolEmailTooLongException.php index 77f73c1..e3bfc2b 100644 --- a/src/AtolOnline/Exceptions/AtolEmailTooLongException.php +++ b/src/AtolOnline/Exceptions/AtolEmailTooLongException.php @@ -9,27 +9,23 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке указать слишком длинный email * * @package AtolOnline\Exceptions */ -class AtolEmailTooLongException extends AtolException +class AtolEmailTooLongException extends AtolTooLongException { /** - * AtolEmailTooLongException constructor. - * - * @param $email - * @param $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($email, $max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком длинный email (макс. длина '.$max.', фактически '.strlen($email).'): '.$email; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1008, + 1117, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Email is is too long'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolEmailValidateException.php b/src/AtolOnline/Exceptions/AtolEmailValidateException.php index a0d867f..ff1bcdb 100644 --- a/src/AtolOnline/Exceptions/AtolEmailValidateException.php +++ b/src/AtolOnline/Exceptions/AtolEmailValidateException.php @@ -18,6 +18,14 @@ use Throwable; */ class AtolEmailValidateException extends AtolException { + /** + * @inheritDoc + */ + protected $ffd_tags = [ + 1008, + 1117, + ]; + /** * AtolEmailValidateException constructor. * @@ -28,7 +36,6 @@ class AtolEmailValidateException extends AtolException */ public function __construct($email, $message = "", $code = 0, Throwable $previous = null) { - $message = $message ?: 'Некорректный email: '.$email; - parent::__construct($message, $code, $previous); + parent::__construct($message ?: 'Invalid email: '.$email, $code, $previous); } } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolException.php b/src/AtolOnline/Exceptions/AtolException.php index 0696f2b..ddcbe9b 100644 --- a/src/AtolOnline/Exceptions/AtolException.php +++ b/src/AtolOnline/Exceptions/AtolException.php @@ -10,6 +10,7 @@ namespace AtolOnline\Exceptions; use Exception; +use Throwable; /** * Исключение, возникающее при работе с АТОЛ Онлайн @@ -18,5 +19,33 @@ use Exception; */ class AtolException extends Exception { - + /** + * @var int[] Теги ФФД + */ + protected $ffd_tags = null; + + /** + * AtolException constructor. + * + * @param string $message + * @param int $code + * @param \Throwable|null $previous + */ + public function __construct($message = "", $code = 0, Throwable $previous = null) + { + if ($this->getFfdTags()) { + $message .= ' [FFD tags: '.implode(', ', $this->getFfdTags()).']'; + } + parent::__construct($message, $code, $previous); + } + + /** + * Возвращает теги ФФД, с которыми связано исключение + * + * @return array|null + */ + protected function getFfdTags(): ?array + { + return $this->ffd_tags; + } } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolInnWrongLengthException.php b/src/AtolOnline/Exceptions/AtolInnWrongLengthException.php index cc96bc8..6f63c76 100644 --- a/src/AtolOnline/Exceptions/AtolInnWrongLengthException.php +++ b/src/AtolOnline/Exceptions/AtolInnWrongLengthException.php @@ -18,6 +18,16 @@ use Throwable; */ class AtolInnWrongLengthException extends AtolException { + /** + * @inheritDoc + */ + protected $ffd_tags = [ + 1016, + 1018, + 1226, + 1228, + ]; + /** * AtolInnWrongLengthException constructor. * @@ -28,7 +38,7 @@ class AtolInnWrongLengthException extends AtolException */ public function __construct($inn, $message = "", $code = 0, Throwable $previous = null) { - $message = $message ?: 'Длина ИНН должна быть 10 или 12 цифр, фактически '.strlen($inn).': '.$inn; - parent::__construct($message, $code, $previous); + parent::__construct($message ?: 'INN length must be 10 or 12 digits only, but actual is '. + (function_exists('mb_strlen') ? mb_strlen($inn) : strlen($inn)).')', $code, $previous); } } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolInvalidJsonException.php b/src/AtolOnline/Exceptions/AtolInvalidJsonException.php new file mode 100644 index 0000000..4c53a5a --- /dev/null +++ b/src/AtolOnline/Exceptions/AtolInvalidJsonException.php @@ -0,0 +1,32 @@ +message.' (max length - '.$max.', actual length - '. + (function_exists('mb_strlen') ? mb_strlen($string) : strlen($string)).')', $code, $previous); + } +} \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolQuantityTooHighException.php b/src/AtolOnline/Exceptions/AtolTooManyException.php similarity index 72% rename from src/AtolOnline/Exceptions/AtolQuantityTooHighException.php rename to src/AtolOnline/Exceptions/AtolTooManyException.php index d4ed67d..427c96b 100644 --- a/src/AtolOnline/Exceptions/AtolQuantityTooHighException.php +++ b/src/AtolOnline/Exceptions/AtolTooManyException.php @@ -12,14 +12,19 @@ namespace AtolOnline\Exceptions; use Throwable; /** - * Исключение, возникающее при попытке указать слишком большое количество + * Исключение, возникающее при попытке указать слишком большое количество чего-либо * * @package AtolOnline\Exceptions */ -class AtolQuantityTooHighException extends AtolException +class AtolTooManyException extends AtolException { /** - * AtolQuantityTooHighException constructor. + * @var string Сообщение об ошибке + */ + protected $message = 'Quantity is too high'; + + /** + * AtolTooManyException constructor. * * @param $quantity * @param $max @@ -29,7 +34,7 @@ class AtolQuantityTooHighException extends AtolException */ public function __construct($quantity, $max, $message = "", $code = 0, Throwable $previous = null) { - $message = $message ?: 'Слишком большое количество (макс. '.$max.'): '.$quantity; + $message = $message ?: $this->message.' (max - '.$max.', actual - '.$quantity.')'; parent::__construct($message, $code, $previous); } } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolTooManyItemsException.php b/src/AtolOnline/Exceptions/AtolTooManyItemsException.php index 96478eb..ef0c8d1 100644 --- a/src/AtolOnline/Exceptions/AtolTooManyItemsException.php +++ b/src/AtolOnline/Exceptions/AtolTooManyItemsException.php @@ -9,26 +9,15 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке добавить слишком много предметов расчёта в массив * * @package AtolOnline\Exceptions */ -class AtolTooManyItemsException extends AtolException +class AtolTooManyItemsException extends AtolTooManyException { /** - * AtolTooManyItemsException constructor. - * - * @param int $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @var string Сообщение об ошибке */ - public function __construct($max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком много предметов расчёта (макс. '.$max.')'; - parent::__construct($message, $code, $previous); - } + protected $message = 'Too many items'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolTooManyPaymentsException.php b/src/AtolOnline/Exceptions/AtolTooManyPaymentsException.php index 53e652a..14f483d 100644 --- a/src/AtolOnline/Exceptions/AtolTooManyPaymentsException.php +++ b/src/AtolOnline/Exceptions/AtolTooManyPaymentsException.php @@ -9,26 +9,25 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** - * Исключение, возникающее при попытке добавить слишком много ставок НДС в массив + * Исключение, возникающее при попытке добавить слишком много платежей в массив * * @package AtolOnline\Exceptions */ -class AtolTooManyPaymentsException extends AtolException +class AtolTooManyPaymentsException extends AtolTooManyException { /** - * AtolTooManyPaymentsException constructor. - * - * @param int $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком много платежей (макс. '.$max.')'; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1031, + 1081, + 1215, + 1217, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Too many payments'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolTooManyVatsException.php b/src/AtolOnline/Exceptions/AtolTooManyVatsException.php index 960de42..cb35d57 100644 --- a/src/AtolOnline/Exceptions/AtolTooManyVatsException.php +++ b/src/AtolOnline/Exceptions/AtolTooManyVatsException.php @@ -9,26 +9,27 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке добавить слишком много ставок НДС в массив * * @package AtolOnline\Exceptions */ -class AtolTooManyVatsException extends AtolException +class AtolTooManyVatsException extends AtolTooManyException { /** - * AtolTooManyVatsException constructor. - * - * @param int $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком много ставок НДС (макс. '.$max.')'; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1102, + 1103, + 1104, + 1105, + 1106, + 1107, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Too many vats'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolUnitTooLongException.php b/src/AtolOnline/Exceptions/AtolUnitTooLongException.php index 422d3ba..f000170 100644 --- a/src/AtolOnline/Exceptions/AtolUnitTooLongException.php +++ b/src/AtolOnline/Exceptions/AtolUnitTooLongException.php @@ -9,27 +9,22 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** * Исключение, возникающее при попытке указать слишком длинный телефон * * @package AtolOnline\Exceptions */ -class AtolUnitTooLongException extends AtolException +class AtolUnitTooLongException extends AtolTooLongException { /** - * AtolUnitTooLongException constructor. - * - * @param $unit - * @param $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($unit, $max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком длинное название единицы измерения (макс. длина '.$max.', фактически '.strlen($unit).'): '.$unit; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1197, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'Measurement unit is too long'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolUserdataTooLongException.php b/src/AtolOnline/Exceptions/AtolUserdataTooLongException.php index adec4a5..46cf2b1 100644 --- a/src/AtolOnline/Exceptions/AtolUserdataTooLongException.php +++ b/src/AtolOnline/Exceptions/AtolUserdataTooLongException.php @@ -9,27 +9,22 @@ namespace AtolOnline\Exceptions; -use Throwable; - /** - * Исключение, возникающее при попытке указать слишком длинный телефон + * Исключение, возникающее при попытке указать слишком длинный дополнительный реквизит * * @package AtolOnline\Exceptions */ -class AtolUserdataTooLongException extends AtolException +class AtolUserdataTooLongException extends AtolTooLongException { /** - * AtolUserdataTooLongException constructor. - * - * @param $data - * @param $max - * @param string $message - * @param int $code - * @param Throwable|null $previous + * @inheritDoc */ - public function __construct($data, $max, $message = "", $code = 0, Throwable $previous = null) - { - $message = $message ?: 'Слишком длинный дополнительный реквизит (макс. длина '.$max.', фактически '.strlen($data).'): '.$data; - parent::__construct($message, $code, $previous); - } + protected $ffd_tags = [ + 1191, + ]; + + /** + * @var string Сообщение об ошибке + */ + protected $message = 'User data is too long'; } \ No newline at end of file diff --git a/src/AtolOnline/Exceptions/AtolWrongDocumentTypeException.php b/src/AtolOnline/Exceptions/AtolWrongDocumentTypeException.php index 0cdbbd3..c7144ed 100644 --- a/src/AtolOnline/Exceptions/AtolWrongDocumentTypeException.php +++ b/src/AtolOnline/Exceptions/AtolWrongDocumentTypeException.php @@ -28,7 +28,6 @@ class AtolWrongDocumentTypeException extends AtolException */ public function __construct($type, $message = "", $code = 0, Throwable $previous = null) { - $message = $message ?: 'Некорректный тип документа: ожидался \'receipt\' или \'correction\', указан \''.$type.'\''; - parent::__construct($message, $code, $previous); + parent::__construct($message ?: "Wrong document type: 'receipt' or 'correction' expected, but '$type' provided", $code, $previous); } } \ No newline at end of file diff --git a/tests/Feature/ItemTest.php b/tests/Feature/ItemTest.php index df0f52e..b3db8f6 100644 --- a/tests/Feature/ItemTest.php +++ b/tests/Feature/ItemTest.php @@ -13,10 +13,9 @@ use AtolOnline\{Constants\PaymentMethods, Entities\Item, Exceptions\AtolNameTooLongException, Exceptions\AtolPriceTooHighException, - Exceptions\AtolQuantityTooHighException, + Exceptions\AtolTooManyException, Exceptions\AtolUnitTooLongException, - Exceptions\AtolUserdataTooLongException -}; + Exceptions\AtolUserdataTooLongException}; /** * Class ItemTest @@ -28,7 +27,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolNameTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testConstructor() @@ -57,7 +56,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolNameTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException * @throws AtolOnline\Exceptions\AtolUserdataTooLongException */ @@ -88,7 +87,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolNameTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testSetVat() @@ -105,7 +104,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolNameTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testAtolNameTooLongException() @@ -119,14 +118,14 @@ class ItemTest extends BasicTestCase * Тестирует исключение о слишком высоком количестве * * @throws AtolOnline\Exceptions\AtolNameTooLongException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolPriceTooHighException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testAtolQuantityTooHighException() { $item = new Item(); - $this->expectException(AtolQuantityTooHighException::class); + $this->expectException(AtolTooManyException::class); $item->setQuantity(100000.1); } @@ -135,7 +134,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolPriceTooHighException * @throws AtolOnline\Exceptions\AtolNameTooLongException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testAtolPriceTooHighException() @@ -151,7 +150,7 @@ class ItemTest extends BasicTestCase * @throws AtolOnline\Exceptions\AtolUserdataTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException * @throws AtolOnline\Exceptions\AtolNameTooLongException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testAtolUserdataTooLongException() @@ -166,7 +165,7 @@ class ItemTest extends BasicTestCase * * @throws AtolOnline\Exceptions\AtolNameTooLongException * @throws AtolOnline\Exceptions\AtolPriceTooHighException - * @throws AtolOnline\Exceptions\AtolQuantityTooHighException + * @throws AtolOnline\Exceptions\AtolTooManyException * @throws AtolOnline\Exceptions\AtolUnitTooLongException */ public function testAtolUnitTooLongException()