From 359264db6442ee9a11e26aeab591e0cd338a1258 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 6 Dec 2021 19:21:42 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=81=D1=83?= =?UTF-8?q?=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20`AdditionalUserProps`=20?= =?UTF-8?q?=D1=81=20=D0=BF=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5=D0=BC?= =?UTF-8?q?=20=D0=B4=D0=BB=D1=8F=20=D0=B1=D1=83=D0=B4=D1=83=D1=89=D0=B5?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= =?UTF-8?q?=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83=D0=BC=D0=B5=D0=BD=D1=82?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Constants/Constraints.php | 24 +++- src/Constants/Ffd105Tags.php | 15 +++ src/Entities/AdditionalUserProps.php | 127 ++++++++++++++++++ .../EmptyAddUserPropNameException.php | 25 ++++ .../EmptyAddUserPropValueException.php | 25 ++++ .../TooLongAddUserPropNameException.php | 28 ++++ .../TooLongAddUserPropValueException.php | 28 ++++ src/TestEnvParams.php | 1 + .../Entities/AdditionalUserPropsTest.php | 104 ++++++++++++++ 9 files changed, 372 insertions(+), 5 deletions(-) create mode 100644 src/Entities/AdditionalUserProps.php create mode 100644 src/Exceptions/EmptyAddUserPropNameException.php create mode 100644 src/Exceptions/EmptyAddUserPropValueException.php create mode 100644 src/Exceptions/TooLongAddUserPropNameException.php create mode 100644 src/Exceptions/TooLongAddUserPropValueException.php create mode 100644 tests/AtolOnline/Tests/Entities/AdditionalUserPropsTest.php diff --git a/src/Constants/Constraints.php b/src/Constants/Constraints.php index 49dfec6..8c9dd34 100644 --- a/src/Constants/Constraints.php +++ b/src/Constants/Constraints.php @@ -128,6 +128,11 @@ final class Constraints */ const MAX_COUNT_DOC_VATS = 6; + /** + * Максимальная сумма одной оплаты + */ + const MAX_COUNT_PAYMENT_SUM = 99999.999; + /** * Максимальная длина имени кассира (1021) * @@ -142,16 +147,25 @@ final class Constraints */ const MAX_LENGTH_ITEM_CODE = 32; + /** + * Максимальная длина наименования дополнительного реквизита (1085) + * + * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 32 + */ + const MAX_LENGTH_ADD_USER_PROP_NAME = 64; + + /** + * Максимальная длина значения дополнительного реквизита (1086) + * + * @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 32 + */ + const MAX_LENGTH_ADD_USER_PROP_VALUE = 256; + /** * Формат даты документа коррекции */ const CORRECTION_DATE_FORMAT = 'd.m.Y'; - /** - * Максимальная сумма одной оплаты - */ - const MAX_COUNT_PAYMENT_SUM = 99999.999; - /** * Регулярное выражение для валидации строки ИНН * diff --git a/src/Constants/Ffd105Tags.php b/src/Constants/Ffd105Tags.php index 32a015a..ed6cc5f 100644 --- a/src/Constants/Ffd105Tags.php +++ b/src/Constants/Ffd105Tags.php @@ -226,4 +226,19 @@ final class Ffd105Tags * Сумма НДС чека по расч. ставке 20/120 */ const DOC_VAT_TYPE_VAT120 = 1106; + + /** + * Дополнительный реквизит пользователя + */ + const DOC_ADD_USER_PROP = 1084; + + /** + * Наименование дополнительного реквизита пользователя + */ + const DOC_ADD_USER_PROP_NAME = 1085; + + /** + * Значение дополнительного реквизита пользователя + */ + const DOC_ADD_USER_PROP_VALUE = 1086; } diff --git a/src/Entities/AdditionalUserProps.php b/src/Entities/AdditionalUserProps.php new file mode 100644 index 0000000..0d1739b --- /dev/null +++ b/src/Entities/AdditionalUserProps.php @@ -0,0 +1,127 @@ +setName($name)->setValue($value); + } + + /** + * Возвращает наименование реквизита + * + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * Устанавливает наименование реквизита + * + * @param string $name + * @return $this + * @throws TooLongAddUserPropNameException + * @throws EmptyAddUserPropNameException + */ + public function setName(string $name): self + { + $name = trim($name); + if (mb_strlen($name) > Constraints::MAX_LENGTH_ADD_USER_PROP_NAME) { + throw new TooLongAddUserPropNameException($name); + } + if (empty($name)) { + throw new EmptyAddUserPropNameException($name); + } + $this->name = $name; + return $this; + } + + /** + * Возвращает установленный телефон + * + * @return string|null + */ + public function getValue(): ?string + { + return $this->value; + } + + /** + * Устанавливает значение реквизита + * + * @param string $value + * @return $this + * @throws TooLongAddUserPropValueException + * @throws EmptyAddUserPropValueException + */ + public function setValue(string $value): self + { + $value = trim($value); + if (mb_strlen($value) > Constraints::MAX_LENGTH_CLIENT_NAME) { + throw new TooLongAddUserPropValueException($value); + } + if (empty($value)) { + throw new EmptyAddUserPropValueException($value); + } + $this->value = $value; + return $this; + } + + /** + * @inheritDoc + */ + #[Pure] + public function jsonSerialize(): array + { + return [ + 'name' => $this->getName(), + 'value' => $this->getValue(), + ]; + } +} diff --git a/src/Exceptions/EmptyAddUserPropNameException.php b/src/Exceptions/EmptyAddUserPropNameException.php new file mode 100644 index 0000000..567d18b --- /dev/null +++ b/src/Exceptions/EmptyAddUserPropNameException.php @@ -0,0 +1,25 @@ +assertAtolable( + new AdditionalUserProps('name', 'value'), + [ + 'name' => 'name', + 'value' => 'value', + ] + ); + } + + /** + * Тестирует выброс исключения при слишком длинном наименовании + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setName + * @covers \AtolOnline\Exceptions\TooLongAddUserPropNameException + * @throws EmptyAddUserPropNameException + * @throws EmptyAddUserPropValueException + * @throws TooLongAddUserPropValueException + */ + public function testTooLongAddCheckPropNameException(): void + { + $this->expectException(TooLongAddUserPropNameException::class); + new AdditionalUserProps(Helpers::randomStr(Constraints::MAX_LENGTH_ADD_USER_PROP_NAME + 1), 'value'); + } + + /** + * Тестирует выброс исключения при пустом наименовании + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setName + * @covers \AtolOnline\Exceptions\EmptyAddUserPropNameException + */ + public function testEmptyAddCheckPropNameException(): void + { + $this->expectException(EmptyAddUserPropNameException::class); + new AdditionalUserProps('', 'value'); + } + + /** + * Тестирует выброс исключения при слишком длинном значении + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setValue + * @covers \AtolOnline\Exceptions\TooLongAddUserPropValueException + * @throws EmptyAddUserPropNameException + * @throws EmptyAddUserPropValueException + * @throws TooLongAddUserPropValueException + * @throws TooLongAddUserPropNameException + */ + public function testTooLongAddCheckPropValueException(): void + { + $this->expectException(TooLongAddUserPropValueException::class); + new AdditionalUserProps('name', Helpers::randomStr(Constraints::MAX_LENGTH_ADD_USER_PROP_VALUE + 1)); + } + + /** + * Тестирует выброс исключения при пустом значении + * + * @covers \AtolOnline\Entities\AdditionalUserProps::setValue + * @covers \AtolOnline\Exceptions\EmptyAddUserPropValueException + */ + public function testEmptyAddCheckPropValueException(): void + { + $this->expectException(EmptyAddUserPropValueException::class); + new AdditionalUserProps('name', ''); + } +}