├── .gitignore ├── .php_cs ├── .scrutinizer.yml ├── .travis.yml ├── LICENSE ├── README.md ├── bootstrap.php ├── composer.json ├── phpunit.xml ├── src ├── Converter │ └── ObjectConverter.php ├── Exception │ ├── AtolErrorException.php │ ├── ParseException.php │ ├── TokenException.php │ ├── UnknownStatusException.php │ ├── ValidationException.php │ └── VatException.php ├── Serializer │ └── Handler │ │ ├── EnumHandler.php │ │ └── ExtendedDateHandler.php ├── V3 │ ├── AtolApi.php │ ├── DTO │ │ ├── General │ │ │ ├── Error.php │ │ │ ├── Error │ │ │ │ ├── ErrorCode.php │ │ │ │ └── ErrorCodeTrait.php │ │ │ ├── ErrorTrait.php │ │ │ └── TimestampTrait.php │ │ ├── GetTokenResponse.php │ │ ├── Report │ │ │ └── Response │ │ │ │ ├── Payload.php │ │ │ │ └── Status.php │ │ ├── ReportResponse.php │ │ ├── Sell │ │ │ ├── Request │ │ │ │ ├── Receipt.php │ │ │ │ ├── Receipt │ │ │ │ │ ├── Attributes.php │ │ │ │ │ ├── Attributes │ │ │ │ │ │ └── TaxSystem.php │ │ │ │ │ ├── Item.php │ │ │ │ │ ├── Item │ │ │ │ │ │ └── Tax.php │ │ │ │ │ ├── Payment.php │ │ │ │ │ └── Payment │ │ │ │ │ │ └── PaymentType.php │ │ │ │ └── Service.php │ │ │ └── Response │ │ │ │ └── Status.php │ │ ├── SellRequest.php │ │ └── SellResponse.php │ └── Validator │ │ ├── EmailOrPhone.php │ │ └── EmailOrPhoneValidator.php ├── V4 │ ├── AtolApi.php │ └── DTO │ │ ├── Correction │ │ ├── Correction.php │ │ ├── CorrectionInfo.php │ │ ├── CorrectionRequest.php │ │ ├── CorrectionResponse.php │ │ └── CorrectionType.php │ │ ├── GetToken │ │ ├── GetTokenRequest.php │ │ └── GetTokenResponse.php │ │ ├── Register │ │ ├── AgentInfo.php │ │ ├── AgentType.php │ │ ├── Client.php │ │ ├── Company.php │ │ ├── Item.php │ │ ├── MoneyTransferOperator.php │ │ ├── PayingAgent.php │ │ ├── Payment.php │ │ ├── PaymentMethod.php │ │ ├── PaymentObject.php │ │ ├── PaymentType.php │ │ ├── Receipt.php │ │ ├── ReceivePaymentsOperator.php │ │ ├── RegisterRequest.php │ │ ├── RegisterResponse.php │ │ ├── Service.php │ │ ├── Sno.php │ │ ├── Status.php │ │ ├── SupplierInfo.php │ │ ├── Vat.php │ │ └── VatType.php │ │ ├── Report │ │ ├── Payload.php │ │ ├── ReportResponse.php │ │ └── Status.php │ │ └── Shared │ │ ├── Error.php │ │ ├── ErrorTrait.php │ │ ├── ErrorType.php │ │ └── TimestampTrait.php └── V5 │ ├── AtolApi.php │ └── DTO │ ├── Correction │ ├── AdditionalUserProps.php │ ├── Correction.php │ ├── CorrectionInfo.php │ ├── CorrectionRequest.php │ ├── CorrectionResponse.php │ ├── CorrectionType.php │ ├── FederalId.php │ ├── OperatingCheckProps.php │ └── SectoralCheckProps.php │ ├── GetToken │ ├── GetTokenRequest.php │ └── GetTokenResponse.php │ ├── Register │ ├── AgentInfo.php │ ├── AgentType.php │ ├── Client.php │ ├── Company.php │ ├── Item.php │ ├── MarkCode.php │ ├── Measure.php │ ├── MoneyTransferOperator.php │ ├── PayingAgent.php │ ├── Payment.php │ ├── PaymentMethod.php │ ├── PaymentObject.php │ ├── PaymentType.php │ ├── Receipt.php │ ├── ReceivePaymentsOperator.php │ ├── RegisterRequest.php │ ├── RegisterResponse.php │ ├── Service.php │ ├── Sno.php │ ├── Status.php │ ├── SupplierInfo.php │ ├── Vat.php │ └── VatType.php │ ├── Report │ ├── Payload.php │ ├── ReportResponse.php │ └── Status.php │ └── Shared │ ├── Error.php │ ├── ErrorTrait.php │ ├── ErrorType.php │ └── TimestampTrait.php └── tests ├── Functional ├── V3 │ └── AtolApiTest.php ├── V4 │ └── AtolApiTest.php └── V5 │ └── AtolApiTest.php ├── Helper ├── AtolApiFactory.php └── ProtectedPropertiesTrait.php ├── Integrational ├── V4 │ └── AtolApiTest.php └── V5 │ └── AtolApiTest.php ├── TestCase ├── V4 │ └── AtolApiTestCase.php └── V5 │ └── AtolApiTestCase.php └── Unit ├── Converter └── ObjectConverterTest.php ├── Exception ├── AtolErrorExceptionTest.php ├── ParseExceptionTest.php ├── TokenExceptionTest.php ├── UnknownStatusExceptionTest.php ├── ValidationExceptionTest.php └── VatExceptionTest.php └── V3 ├── AtolApiTest.php ├── DTO ├── General │ ├── Error │ │ └── ErrorCodeTest.php │ └── ErrorTest.php ├── GetTokenResponseTest.php ├── Report │ └── Response │ │ └── PayloadTest.php ├── ReportResponseTest.php ├── Sell │ └── Request │ │ ├── Receipt │ │ ├── AttributesTest.php │ │ ├── ItemTest.php │ │ ├── PaymentTest.php │ │ └── TaxTest.php │ │ ├── ReceiptTest.php │ │ └── ServiceTest.php ├── SellRequestTest.php └── SellResponseTest.php └── Validator ├── EmailOrPhoneTest.php └── EmailOrPhoneValidatorTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea/ 2 | /build/ 3 | /_output/ 4 | /vendor/ 5 | /composer.lock 6 | /.php_cs.cache -------------------------------------------------------------------------------- /.php_cs: -------------------------------------------------------------------------------- 1 | exclude('vendor') 5 | ->exclude('build') 6 | ->exclude('bundle_tests/App/var') 7 | ->in(__DIR__); 8 | 9 | return PhpCsFixer\Config::create() 10 | ->setRules([ 11 | '@Symfony' => true, 12 | 'concat_space' => ['spacing' => 'one'], 13 | 'phpdoc_align' => false, 14 | 'phpdoc_to_comment' => false, 15 | 'header_comment' => false, 16 | ]) 17 | ->setFinder($finder); -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | checks: 2 | php: 3 | code_rating: true 4 | duplication: true 5 | 6 | build: 7 | tests: 8 | override: 9 | - 10 | command: vendor/bin/phpunit --coverage-clover=build/clover.xml 11 | coverage: 12 | file: build/clover.xml 13 | format: clover 14 | 15 | filter: 16 | excluded_paths: 17 | - "./tests" -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | ## php 7.1 doesn't supports by jms/serialize 4 | php: 5 | - 7.2 6 | - 7.3 7 | - 7.4 8 | 9 | env: 10 | matrix: 11 | - DEPENDENCIES="high" 12 | - DEPENDENCIES="low" 13 | global: 14 | - DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-ansi --no-progress --no-suggest" 15 | 16 | matrix: 17 | fast_finish: true 18 | 19 | before_install: 20 | - travis_retry composer self-update 21 | 22 | install: 23 | - if [[ "$DEPENDENCIES" = 'high' ]]; then COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi 24 | - if [[ "$DEPENDENCIES" = 'low' ]]; then COMPOSER_MEMORY_LIMIT=-1 travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi 25 | 26 | cache: 27 | directories: 28 | - $HOME/.composer/cache 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2018 Lamoda 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ATOL PHP Client 2 | ATOL API v3/v4/v5 client for PHP 3 | 4 | https://online.atol.ru/ 5 | 6 | [![Build Status](https://travis-ci.org/lamoda/atol-client.svg?branch=master)](https://travis-ci.org/lamoda/atol-client) 7 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lamoda/atol-client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lamoda/atol-client/?branch=master) 8 | [![Code Coverage](https://scrutinizer-ci.com/g/lamoda/atol-client/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lamoda/atol-client/?branch=master) 9 | [![Build Status](https://scrutinizer-ci.com/g/lamoda/atol-client/badges/build.png?b=master)](https://scrutinizer-ci.com/g/lamoda/atol-client/build-status/master) 10 | 11 | ## Installation 12 | 13 | Usage is as simple as 14 | 15 | 1. Install library 16 | ```bash 17 | composer require lamoda/atol-client 18 | ``` 19 | 20 | 2. Better to use this library with symfony: https://github.com/lamoda/atol-client-bundle 21 | 22 | 3. But you can configure it manually (you will probably need some factory: 23 | ```php 24 | build(); 84 | } 85 | 86 | private static function createValidator(): ValidatorInterface 87 | { 88 | return Validation::createValidatorBuilder() 89 | ->enableAnnotationMapping() 90 | ->getValidator(); 91 | } 92 | } 93 | ``` 94 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | tests/Unit 21 | 22 | 23 | tests/Functional 24 | 25 | 26 | tests/Integrational 27 | 28 | 29 | 30 | 31 | 32 | src 33 | 34 | ./vendor/ 35 | ./tests/ 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/Converter/ObjectConverter.php: -------------------------------------------------------------------------------- 1 | serializer = $serializer; 26 | $this->validator = $validator; 27 | } 28 | 29 | /** 30 | * @param string $class 31 | * @param string $json 32 | * 33 | * @throws ValidationException 34 | * @throws ParseException 35 | * 36 | * @return mixed 37 | */ 38 | public function getResponseObject(string $class, string $json) 39 | { 40 | $object = $this->deserialize($class, $json); 41 | $this->assertValid($object, ValidationException::RESPONSE); 42 | 43 | return $object; 44 | } 45 | 46 | /** 47 | * @param mixed $object 48 | * 49 | * @throws ValidationException 50 | * @throws ParseException 51 | * 52 | * @return string 53 | */ 54 | public function getRequestString($object): string 55 | { 56 | $this->assertValid($object, ValidationException::RESPONSE); 57 | 58 | return $this->serializeBodyObject($object); 59 | } 60 | 61 | /** 62 | * @param string $class 63 | * @param string $json 64 | * 65 | * @throws ParseException 66 | * 67 | * @return mixed 68 | */ 69 | private function deserialize(string $class, string $json) 70 | { 71 | try { 72 | return $this->serializer->deserialize($json, $class, 'atol_client'); 73 | } catch (\RuntimeException $exception) { 74 | throw ParseException::becauseOfRuntimeException($exception, ParseException::RESPONSE); 75 | } 76 | } 77 | 78 | /** 79 | * Assert that object is valid. 80 | * 81 | * @param mixed $object 82 | * @param int $code 83 | * 84 | * @throws ValidationException 85 | */ 86 | private function assertValid($object, int $code = 0) 87 | { 88 | $errors = $this->validator->validate($object); 89 | if (count($errors)) { 90 | throw ValidationException::becauseOfValidationErrors($errors, $code); 91 | } 92 | } 93 | 94 | /** 95 | * @param mixed $object 96 | * 97 | * @throws ParseException 98 | * 99 | * @return string 100 | */ 101 | private function serializeBodyObject($object): string 102 | { 103 | try { 104 | return $this->serializer->serialize($object, 'atol_client', $this->getSerializeBodyObjectContext()); 105 | } catch (\RuntimeException $exception) { 106 | throw ParseException::becauseOfRuntimeException($exception, ParseException::REQUEST); 107 | } 108 | } 109 | 110 | /** 111 | * @return Context 112 | */ 113 | private function getSerializeBodyObjectContext(): Context 114 | { 115 | return SerializationContext::create()->setGroups(['Default', 'post']); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Exception/AtolErrorException.php: -------------------------------------------------------------------------------- 1 | type = $type; 25 | parent::__construct($message, $code, $previous); 26 | } 27 | 28 | public static function becauseOfAtolError(Error $error) 29 | { 30 | return new static( 31 | $error->getText(), 32 | $error->getCode()->getNumber(), 33 | $error->getType() 34 | ); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | public function getType(): string 41 | { 42 | return $this->type; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Exception/ParseException.php: -------------------------------------------------------------------------------- 1 | getMessage(), $exception->getCode(), $exception); 16 | } 17 | 18 | public static function becauseOfAtolError(Error $error) 19 | { 20 | return new static($error->getText(), $error->getCode()->getNumber()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Exception/UnknownStatusException.php: -------------------------------------------------------------------------------- 1 | getMessage(); 29 | } 30 | 31 | return implode("\n", $reasons); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Exception/VatException.php: -------------------------------------------------------------------------------- 1 | 'Enum', 30 | 'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, 31 | 'format' => $format, 32 | 'method' => 'deserialize', 33 | ]; 34 | 35 | $methods[] = [ 36 | 'type' => 'Enum', 37 | 'direction' => GraphNavigator::DIRECTION_SERIALIZATION, 38 | 'format' => $format, 39 | 'method' => 'serialize', 40 | ]; 41 | } 42 | 43 | return $methods; 44 | } 45 | 46 | /** 47 | * @param VisitorInterface $visitor 48 | * @param mixed $data 49 | * @param array $type 50 | * 51 | * @throws \Paillechat\Enum\Exception\EnumException 52 | * 53 | * @return Enum 54 | */ 55 | public function deserialize(VisitorInterface $visitor, $data, array $type) 56 | { 57 | if ($data === null) { 58 | return null; 59 | } 60 | 61 | // Return enum if exists: 62 | $class = $type['params'][0] ?? null; 63 | if (class_exists($class) && isset(class_parents($class)[Enum::class])) { 64 | return new $class($data); 65 | } 66 | 67 | throw new \LogicException('Enum class does not exist.'); 68 | } 69 | 70 | /** 71 | * @param VisitorInterface $visitor 72 | * @param Enum $enum 73 | * @param array $type 74 | * @param Context $context 75 | * 76 | * @throws \LogicException 77 | * 78 | * @return mixed 79 | */ 80 | public function serialize(VisitorInterface $visitor, Enum $enum, array $type, Context $context) 81 | { 82 | $valueType = $type['params'][1] ?? 'string'; 83 | switch ($valueType) { 84 | case 'string': 85 | return $visitor->visitString($enum->getValue(), $type, $context); 86 | case 'integer': 87 | return $visitor->visitInteger($enum->getValue(), $type, $context); 88 | default: 89 | throw new \LogicException('Unknown value type '); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Serializer/Handler/ExtendedDateHandler.php: -------------------------------------------------------------------------------- 1 | dateHandler = new DateHandler(); 32 | } 33 | 34 | /** 35 | * {@inheritdoc} 36 | */ 37 | public static function getSubscribingMethods() 38 | { 39 | $methods = DateHandler::getSubscribingMethods(); 40 | 41 | foreach (self::$additionalFormats as $format) { 42 | $methods[] = [ 43 | 'type' => 'DateTime', 44 | 'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION, 45 | 'format' => $format, 46 | 'method' => 'deserializeDateTimeFromJson', 47 | ]; 48 | 49 | foreach (self::$types as $type) { 50 | $methods[] = [ 51 | 'type' => $type, 52 | 'format' => $format, 53 | 'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION, 54 | 'method' => 'serialize' . $type, 55 | ]; 56 | } 57 | } 58 | 59 | return $methods; 60 | } 61 | 62 | public function serializeDateTime(SerializationVisitorInterface $visitor, \DateTime $date, array $type, SerializationContext $context) 63 | { 64 | return $this->dateHandler->serializeDateTime($visitor, $date, $type, $context); 65 | } 66 | 67 | public function serializeDateTimeImmutable( 68 | SerializationVisitorInterface $visitor, 69 | \DateTimeImmutable $date, 70 | array $type, 71 | SerializationContext $context 72 | ) { 73 | return $this->dateHandler->serializeDateTimeImmutable($visitor, $date, $type, $context); 74 | } 75 | 76 | public function serializeDateInterval(SerializationVisitorInterface $visitor, \DateInterval $date, array $type, SerializationContext $context) 77 | { 78 | return $this->dateHandler->serializeDateInterval($visitor, $date, $type, $context); 79 | } 80 | 81 | public function deserializeDateTimeFromJson(DeserializationVisitorInterface $visitor, $data, array $type): ?\DateTimeInterface 82 | { 83 | return $this->dateHandler->deserializeDateTimeFromJson($visitor, $data, $type); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/V3/DTO/General/Error.php: -------------------------------------------------------------------------------- 1 | text; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getType(): ?string 42 | { 43 | return $this->type; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/V3/DTO/General/Error/ErrorCode.php: -------------------------------------------------------------------------------- 1 | number = $number; 48 | } 49 | 50 | public function getNumber(): int 51 | { 52 | return $this->number; 53 | } 54 | 55 | /** 56 | * @return bool 57 | */ 58 | public function isTokenSuccess(): bool 59 | { 60 | return in_array($this->getNumber(), [ 61 | self::NEW_TOKEN, 62 | self::OLD_TOKEN, 63 | ]); 64 | } 65 | 66 | /** 67 | * @return bool 68 | */ 69 | public function isTokenError(): bool 70 | { 71 | return in_array($this->getNumber(), [ 72 | self::INCOMING_MISSING_TOKEN, 73 | self::INCOMING_NOT_EXIST_TOKEN, 74 | self::INCOMING_EXPIRED_TOKEN, 75 | self::STATE_MISSING_TOKEN, 76 | self::STATE_NOT_EXIST_TOKEN, 77 | self::STATE_EXPIRED_TOKEN, 78 | ]); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/V3/DTO/General/Error/ErrorCodeTrait.php: -------------------------------------------------------------------------------- 1 | code); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/V3/DTO/General/ErrorTrait.php: -------------------------------------------------------------------------------- 1 | error; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V3/DTO/General/TimestampTrait.php: -------------------------------------------------------------------------------- 1 | ") 15 | * 16 | * @var \DateTime 17 | */ 18 | private $timestamp; 19 | 20 | /** 21 | * @return \DateTime 22 | */ 23 | public function getTimestamp(): \DateTime 24 | { 25 | return $this->timestamp; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V3/DTO/GetTokenResponse.php: -------------------------------------------------------------------------------- 1 | text; 37 | } 38 | 39 | /** 40 | * @return string 41 | */ 42 | public function getToken(): string 43 | { 44 | return $this->token; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/V3/DTO/Report/Response/Payload.php: -------------------------------------------------------------------------------- 1 | ") 37 | * 38 | * @var \DateTimeInterface 39 | */ 40 | private $receiptDatetime; 41 | 42 | /** 43 | * @Serializer\Type("integer") 44 | * 45 | * @var int 46 | */ 47 | private $fiscalReceiptNumber; 48 | 49 | /** 50 | * @Serializer\Type("integer") 51 | * 52 | * @var int 53 | */ 54 | private $fiscalDocumentNumber; 55 | 56 | /** 57 | * @Serializer\Type("string") 58 | * 59 | * @var string 60 | */ 61 | private $ecrRegistrationNumber; 62 | 63 | /** 64 | * @Serializer\Type("integer") 65 | * 66 | * @var int 67 | */ 68 | private $fiscalDocumentAttribute; 69 | 70 | /** 71 | * @return int 72 | */ 73 | public function getTotal(): int 74 | { 75 | return $this->total; 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getFnNumber(): string 82 | { 83 | return $this->fnNumber; 84 | } 85 | 86 | /** 87 | * @return int 88 | */ 89 | public function getShiftNumber(): int 90 | { 91 | return $this->shiftNumber; 92 | } 93 | 94 | /** 95 | * @return \DateTimeInterface 96 | */ 97 | public function getReceiptDatetime(): \DateTimeInterface 98 | { 99 | return $this->receiptDatetime; 100 | } 101 | 102 | /** 103 | * @return int 104 | */ 105 | public function getFiscalReceiptNumber(): int 106 | { 107 | return $this->fiscalReceiptNumber; 108 | } 109 | 110 | /** 111 | * @return int 112 | */ 113 | public function getFiscalDocumentNumber(): int 114 | { 115 | return $this->fiscalDocumentNumber; 116 | } 117 | 118 | /** 119 | * @return string 120 | */ 121 | public function getEcrRegistrationNumber(): string 122 | { 123 | return $this->ecrRegistrationNumber; 124 | } 125 | 126 | /** 127 | * @return int 128 | */ 129 | public function getFiscalDocumentAttribute(): int 130 | { 131 | return $this->fiscalDocumentAttribute; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /src/V3/DTO/Report/Response/Status.php: -------------------------------------------------------------------------------- 1 | ") 28 | * 29 | * @var Status 30 | */ 31 | private $status; 32 | 33 | /** 34 | * @Serializer\Type("Lamoda\AtolClient\V3\DTO\Report\Response\Payload") 35 | * 36 | * @var Payload 37 | */ 38 | private $payload; 39 | 40 | /** 41 | * @Serializer\Type("string") 42 | * 43 | * @var string 44 | */ 45 | private $callbackUrl; 46 | 47 | /** 48 | * @return string 49 | */ 50 | public function getUuid(): string 51 | { 52 | return $this->uuid; 53 | } 54 | 55 | /** 56 | * @return Status 57 | */ 58 | public function getStatus(): Status 59 | { 60 | return $this->status; 61 | } 62 | 63 | /** 64 | * @return Payload 65 | */ 66 | public function getPayload(): Payload 67 | { 68 | return $this->payload; 69 | } 70 | 71 | /** 72 | * @return string 73 | */ 74 | public function getCallbackUrl(): string 75 | { 76 | return $this->callbackUrl; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt.php: -------------------------------------------------------------------------------- 1 | ") 20 | * 21 | * @var Item[] 22 | */ 23 | private $items; 24 | 25 | /** 26 | * @Serializer\Type("float") 27 | * 28 | * @var float 29 | */ 30 | private $total; 31 | 32 | /** 33 | * @Serializer\Type("array") 34 | * 35 | * @var Payment[] 36 | */ 37 | private $payments; 38 | 39 | /** 40 | * @Serializer\Type("Lamoda\AtolClient\V3\DTO\Sell\Request\Receipt\Attributes") 41 | * @Assert\Valid() 42 | * 43 | * @var Attributes 44 | */ 45 | private $attributes; 46 | 47 | /** 48 | * @param Item[] $items 49 | * @param float $total 50 | * @param Payment[] $payments 51 | * @param Attributes $attributes 52 | */ 53 | public function __construct( 54 | array $items, 55 | float $total, 56 | array $payments, 57 | Attributes $attributes 58 | ) { 59 | $this->items = $items; 60 | $this->total = $total; 61 | $this->payments = $payments; 62 | $this->attributes = $attributes; 63 | } 64 | 65 | /** 66 | * @return Item[] 67 | */ 68 | public function getItems(): array 69 | { 70 | return $this->items; 71 | } 72 | 73 | /** 74 | * @return float 75 | */ 76 | public function getTotal(): float 77 | { 78 | return $this->total; 79 | } 80 | 81 | /** 82 | * @return Payment[] 83 | */ 84 | public function getPayments(): array 85 | { 86 | return $this->payments; 87 | } 88 | 89 | /** 90 | * @return Attributes 91 | */ 92 | public function getAttributes(): Attributes 93 | { 94 | return $this->attributes; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt/Attributes.php: -------------------------------------------------------------------------------- 1 | ") 34 | * 35 | * @var TaxSystem 36 | */ 37 | private $sno; 38 | 39 | /** 40 | * Attributes constructor. 41 | * 42 | * @param string $email 43 | * @param string $phone 44 | * @param TaxSystem $sno 45 | */ 46 | public function __construct(string $email = null, string $phone = null, TaxSystem $sno = null) 47 | { 48 | $this->email = $email; 49 | $this->phone = $phone; 50 | $this->sno = $sno; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getEmail(): ?string 57 | { 58 | return $this->email; 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getPhone(): ?string 65 | { 66 | return $this->phone; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt/Attributes/TaxSystem.php: -------------------------------------------------------------------------------- 1 | ") 45 | * 46 | * @var Tax 47 | */ 48 | private $tax; 49 | 50 | /** 51 | * @Serializer\Type("float") 52 | * 53 | * @var float 54 | */ 55 | private $taxsum; 56 | 57 | /** 58 | * ReceiptItem constructor. 59 | * 60 | * @param string $name 61 | * @param float $price 62 | * @param float $quantity 63 | * @param float $sum 64 | * @param Tax $tax 65 | * @param float $taxsum 66 | */ 67 | public function __construct( 68 | string $name, 69 | float $price, 70 | float $quantity, 71 | float $sum, 72 | Tax $tax, 73 | float $taxsum 74 | ) { 75 | $this->name = $name; 76 | $this->price = $price; 77 | $this->quantity = $quantity; 78 | $this->sum = $sum; 79 | $this->tax = $tax; 80 | $this->taxsum = $taxsum; 81 | } 82 | 83 | /** 84 | * @return string 85 | */ 86 | public function getName(): string 87 | { 88 | return $this->name; 89 | } 90 | 91 | /** 92 | * @return float 93 | */ 94 | public function getPrice(): float 95 | { 96 | return $this->price; 97 | } 98 | 99 | /** 100 | * @return float 101 | */ 102 | public function getQuantity(): float 103 | { 104 | return $this->quantity; 105 | } 106 | 107 | /** 108 | * @return float 109 | */ 110 | public function getSum(): float 111 | { 112 | return $this->sum; 113 | } 114 | 115 | /** 116 | * @return Tax 117 | */ 118 | public function getTax(): Tax 119 | { 120 | return $this->tax; 121 | } 122 | 123 | /** 124 | * @return float 125 | */ 126 | public function getTaxsum(): float 127 | { 128 | return $this->taxsum; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt/Item/Tax.php: -------------------------------------------------------------------------------- 1 | self::VAT0, 56 | 10 => self::VAT110, 57 | 18 => self::VAT118, 58 | ]; 59 | 60 | if (null === $vat) { 61 | return new self(self::NONE); 62 | } 63 | 64 | if (!isset($mapping[$vat])) { 65 | throw VatException::becauseUnknownVatValue($vat); 66 | } 67 | 68 | return new self($mapping[$vat]); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt/Payment.php: -------------------------------------------------------------------------------- 1 | ") 24 | * 25 | * @var PaymentType 26 | */ 27 | private $type; 28 | 29 | /** 30 | * Payment constructor. 31 | * 32 | * @param float $sum 33 | * @param PaymentType $type 34 | */ 35 | public function __construct(float $sum, PaymentType $type) 36 | { 37 | $this->sum = $sum; 38 | $this->type = $type; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Request/Receipt/Payment/PaymentType.php: -------------------------------------------------------------------------------- 1 | inn = $inn; 45 | $this->callbackUrl = $callbackUrl; 46 | $this->paymentAddress = $paymentAddress; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/V3/DTO/Sell/Response/Status.php: -------------------------------------------------------------------------------- 1 | externalId = $externalId; 72 | $this->service = $service; 73 | $this->receipt = $receipt; 74 | $this->token = $token; 75 | $this->timestamp = $timestamp ?: new \DateTime(); 76 | } 77 | 78 | /** 79 | * @return string 80 | */ 81 | public function getExternalId(): string 82 | { 83 | return $this->externalId; 84 | } 85 | 86 | /** 87 | * @return Service 88 | */ 89 | public function getService(): Service 90 | { 91 | return $this->service; 92 | } 93 | 94 | /** 95 | * @return Receipt 96 | */ 97 | public function getReceipt(): Receipt 98 | { 99 | return $this->receipt; 100 | } 101 | 102 | /** 103 | * @return string 104 | */ 105 | public function getToken(): string 106 | { 107 | return $this->token; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/V3/DTO/SellResponse.php: -------------------------------------------------------------------------------- 1 | ") 30 | * @Assert\NotBlank() 31 | * 32 | * @var Status 33 | */ 34 | private $status; 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function getUuid(): ?string 40 | { 41 | return $this->uuid; 42 | } 43 | 44 | /** 45 | * @return Status 46 | */ 47 | public function getStatus(): Status 48 | { 49 | return $this->status; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/V3/Validator/EmailOrPhone.php: -------------------------------------------------------------------------------- 1 | getEmail() || $attributes->getPhone()) { 20 | return; 21 | } 22 | 23 | $this->context 24 | ->buildViolation($constraint->message) 25 | ->atPath('phone / email') 26 | ->addViolation(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/V4/AtolApi.php: -------------------------------------------------------------------------------- 1 | converter = $converter; 51 | $this->client = $client; 52 | $this->clientOptions = $clientOptions; 53 | $this->baseUri = rtrim($baseUri, '/'); 54 | } 55 | 56 | public function getToken(GetTokenRequest $request): GetTokenResponse 57 | { 58 | $response = $this->request('POST', 'getToken', [], $request); 59 | 60 | return $this->converter->getResponseObject(GetTokenResponse::class, $response); 61 | } 62 | 63 | public function sell(string $groupCode, string $token, RegisterRequest $request): RegisterResponse 64 | { 65 | return $this->register(self::OPERATION_SELL, $groupCode, $token, $request); 66 | } 67 | 68 | public function sellRefund(string $groupCode, string $token, RegisterRequest $request): RegisterResponse 69 | { 70 | return $this->register(self::OPERATION_SELL_REFUND, $groupCode, $token, $request); 71 | } 72 | 73 | public function sellCorrection(string $groupCode, string $token, CorrectionRequest $request): CorrectionResponse 74 | { 75 | return $this->correction(self::OPERATION_SELL_CORRECTION, $groupCode, $token, $request); 76 | } 77 | 78 | public function report(string $groupCode, string $token, string $uuid): ReportResponse 79 | { 80 | $response = $this->request( 81 | 'GET', 82 | "$groupCode/report/$uuid", 83 | [], 84 | null, 85 | [ 86 | 'Token' => $token, 87 | ] 88 | ); 89 | 90 | return $this->converter->getResponseObject(ReportResponse::class, $response); 91 | } 92 | 93 | private function correction( 94 | string $operation, 95 | string $groupCode, 96 | string $token, 97 | CorrectionRequest $request 98 | ): CorrectionResponse { 99 | $response = $this->request( 100 | 'POST', 101 | "$groupCode/$operation", 102 | [], 103 | $request, 104 | [ 105 | 'Token' => $token, 106 | ] 107 | ); 108 | 109 | return $this->converter->getResponseObject(CorrectionResponse::class, $response); 110 | } 111 | 112 | private function register( 113 | string $operation, 114 | string $groupCode, 115 | string $token, 116 | RegisterRequest $request 117 | ): RegisterResponse { 118 | $response = $this->request( 119 | 'POST', 120 | "$groupCode/$operation", 121 | [], 122 | $request, 123 | [ 124 | 'Token' => $token, 125 | ] 126 | ); 127 | 128 | return $this->converter->getResponseObject(RegisterResponse::class, $response); 129 | } 130 | 131 | private function request(string $method, string $path, array $query = [], $body = null, array $headers = []): string 132 | { 133 | // Prepare request: 134 | $body = $this->parseBody($body); 135 | $path = trim($path, '/'); 136 | $uri = "{$this->baseUri}/v4/$path/"; 137 | 138 | $headers = array_merge($headers, [ 139 | 'Content-Type' => 'application/json', 140 | ]); 141 | 142 | $options = array_merge($this->clientOptions, [ 143 | RequestOptions::HEADERS => $headers, 144 | RequestOptions::QUERY => $query, 145 | RequestOptions::BODY => $body, 146 | // configuration 147 | RequestOptions::HTTP_ERRORS => false, 148 | ]); 149 | 150 | $response = $this->client->request( 151 | $method, 152 | $uri, 153 | $options 154 | ); 155 | 156 | return (string) $response->getBody(); 157 | } 158 | 159 | private function parseBody($body = null): ?string 160 | { 161 | if ($body === null || \is_string($body)) { 162 | return $body; 163 | } 164 | 165 | return $this->converter->getRequestString($body); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /src/V4/DTO/Correction/Correction.php: -------------------------------------------------------------------------------- 1 | ") 33 | */ 34 | private $payments; 35 | 36 | /** 37 | * @var Vat[] 38 | * 39 | * @Serializer\Type("array") 40 | */ 41 | private $vats; 42 | 43 | /** 44 | * @var string|null 45 | * 46 | * @Serializer\Type("string") 47 | */ 48 | private $cashier; 49 | 50 | public function __construct(Company $company, CorrectionInfo $correctionInfo, array $payments, array $vats) 51 | { 52 | $this->company = $company; 53 | $this->correctionInfo = $correctionInfo; 54 | $this->payments = $payments; 55 | $this->vats = $vats; 56 | } 57 | 58 | public function getCorrectionInfo(): CorrectionInfo 59 | { 60 | return $this->correctionInfo; 61 | } 62 | 63 | public function setCorrectionInfo(CorrectionInfo $correctionInfo): self 64 | { 65 | $this->correctionInfo = $correctionInfo; 66 | 67 | return $this; 68 | } 69 | 70 | public function getCompany(): Company 71 | { 72 | return $this->company; 73 | } 74 | 75 | public function setCompany(Company $company): self 76 | { 77 | $this->company = $company; 78 | 79 | return $this; 80 | } 81 | 82 | /** 83 | * @return Payment[] 84 | */ 85 | public function getPayments(): array 86 | { 87 | return $this->payments; 88 | } 89 | 90 | /** 91 | * @param Payment[] $payments 92 | * 93 | * @return Correction 94 | */ 95 | public function setPayments(array $payments): self 96 | { 97 | $this->payments = $payments; 98 | 99 | return $this; 100 | } 101 | 102 | /** 103 | * @return Vat[] 104 | */ 105 | public function getVats(): array 106 | { 107 | return $this->vats; 108 | } 109 | 110 | /** 111 | * @param Vat[] $vats 112 | * 113 | * @return Correction 114 | */ 115 | public function setVats(array $vats): self 116 | { 117 | $this->vats = $vats; 118 | 119 | return $this; 120 | } 121 | 122 | public function getCashier(): ?string 123 | { 124 | return $this->cashier; 125 | } 126 | 127 | /** 128 | * @param string $cashier 129 | * 130 | * @return Correction 131 | */ 132 | public function setCashier(string $cashier): self 133 | { 134 | $this->cashier = $cashier; 135 | 136 | return $this; 137 | } 138 | 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/V4/DTO/Correction/CorrectionInfo.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var \DateTime 20 | * 21 | * @Serializer\Type("DateTime<'d.m.Y'>") 22 | * @Serializer\SerializedName("base_date") 23 | */ 24 | private $baseDate; 25 | 26 | /** 27 | * @var string 28 | * 29 | * @Serializer\Type("string") 30 | * @Serializer\SerializedName("base_number") 31 | */ 32 | private $baseNumber; 33 | 34 | public function __construct(CorrectionType $type, \DateTime $baseDate, string $baseNumber) 35 | { 36 | $this->type = $type; 37 | $this->baseDate = $baseDate; 38 | $this->baseNumber = $baseNumber; 39 | } 40 | 41 | public function getType(): CorrectionType 42 | { 43 | return $this->type; 44 | } 45 | 46 | public function setType(CorrectionType $type): self 47 | { 48 | $this->type = $type; 49 | 50 | return $this; 51 | } 52 | 53 | public function getBaseDate(): \DateTime 54 | { 55 | return $this->baseDate; 56 | } 57 | 58 | public function setBaseDate(\DateTime $baseDate): self 59 | { 60 | $this->baseDate = $baseDate; 61 | 62 | return $this; 63 | } 64 | 65 | public function getBaseNumber(): string 66 | { 67 | return $this->baseNumber; 68 | } 69 | 70 | public function setBaseNumber(string $baseNumber): self 71 | { 72 | $this->baseNumber = $baseNumber; 73 | 74 | return $this; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/V4/DTO/Correction/CorrectionRequest.php: -------------------------------------------------------------------------------- 1 | externalId = $externalId; 40 | $this->correction = $correction; 41 | $this->timestamp = $timestamp; 42 | } 43 | 44 | public function setTimestamp(\DateTime $timestamp): self 45 | { 46 | $this->timestamp = $timestamp; 47 | 48 | return $this; 49 | } 50 | 51 | public function getExternalId(): string 52 | { 53 | return $this->externalId; 54 | } 55 | 56 | public function setExternalId(string $externalId): void 57 | { 58 | $this->externalId = $externalId; 59 | } 60 | 61 | public function getService(): ?Service 62 | { 63 | return $this->service; 64 | } 65 | 66 | public function setService(?Service $service): void 67 | { 68 | $this->service = $service; 69 | } 70 | 71 | public function getCorrection(): Correction 72 | { 73 | return $this->correction; 74 | } 75 | 76 | public function setCorrection(Correction $correction): self 77 | { 78 | $this->correction = $correction; 79 | 80 | return $this; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/V4/DTO/Correction/CorrectionResponse.php: -------------------------------------------------------------------------------- 1 | ") 28 | */ 29 | private $status; 30 | 31 | public function getUuid(): ?string 32 | { 33 | return $this->uuid; 34 | } 35 | 36 | public function getStatus(): ?Status 37 | { 38 | return $this->status; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V4/DTO/Correction/CorrectionType.php: -------------------------------------------------------------------------------- 1 | login = $login; 27 | $this->pass = $pass; 28 | } 29 | 30 | public function getLogin(): string 31 | { 32 | return $this->login; 33 | } 34 | 35 | public function setLogin(string $login): self 36 | { 37 | $this->login = $login; 38 | 39 | return $this; 40 | } 41 | 42 | public function getPass(): string 43 | { 44 | return $this->pass; 45 | } 46 | 47 | public function setPass(string $pass): self 48 | { 49 | $this->pass = $pass; 50 | 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/V4/DTO/GetToken/GetTokenResponse.php: -------------------------------------------------------------------------------- 1 | token; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/AgentInfo.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var PayingAgent|null 20 | * 21 | * @Serializer\Type("Lamoda\AtolClient\V4\DTO\Register\PayingAgent") 22 | */ 23 | private $payingAgent; 24 | 25 | /** 26 | * @var ReceivePaymentsOperator|null 27 | * 28 | * @Serializer\Type("Lamoda\AtolClient\V4\DTO\Register\ReceivePaymentsOperator") 29 | */ 30 | private $receivePaymentsOperator; 31 | 32 | /** 33 | * @var MoneyTransferOperator|null 34 | * 35 | * @Serializer\Type("Lamoda\AtolClient\V4\DTO\Register\MoneyTransferOperator") 36 | */ 37 | private $moneyTransferOperator; 38 | 39 | public function __construct(AgentType $type) 40 | { 41 | $this->type = $type; 42 | } 43 | 44 | public function getType(): AgentType 45 | { 46 | return $this->type; 47 | } 48 | 49 | public function setType(AgentType $type): self 50 | { 51 | $this->type = $type; 52 | 53 | return $this; 54 | } 55 | 56 | public function getPayingAgent(): ?PayingAgent 57 | { 58 | return $this->payingAgent; 59 | } 60 | 61 | public function setPayingAgent(?PayingAgent $payingAgent): self 62 | { 63 | $this->payingAgent = $payingAgent; 64 | 65 | return $this; 66 | } 67 | 68 | public function getReceivePaymentsOperator(): ?ReceivePaymentsOperator 69 | { 70 | return $this->receivePaymentsOperator; 71 | } 72 | 73 | public function setReceivePaymentsOperator(?ReceivePaymentsOperator $receivePaymentsOperator): self 74 | { 75 | $this->receivePaymentsOperator = $receivePaymentsOperator; 76 | 77 | return $this; 78 | } 79 | 80 | public function getMoneyTransferOperator(): ?MoneyTransferOperator 81 | { 82 | return $this->moneyTransferOperator; 83 | } 84 | 85 | public function setMoneyTransferOperator(?MoneyTransferOperator $moneyTransferOperator): self 86 | { 87 | $this->moneyTransferOperator = $moneyTransferOperator; 88 | 89 | return $this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/AgentType.php: -------------------------------------------------------------------------------- 1 | email = $email; 28 | $this->phone = $phone; 29 | 30 | $this->assertValidity(); 31 | } 32 | 33 | public function getEmail(): ?string 34 | { 35 | return $this->email; 36 | } 37 | 38 | public function setEmail(?string $email): self 39 | { 40 | $this->email = $email; 41 | $this->assertValidity(); 42 | 43 | return $this; 44 | } 45 | 46 | public function getPhone(): ?string 47 | { 48 | return $this->phone; 49 | } 50 | 51 | public function setPhone(?string $phone): self 52 | { 53 | $this->phone = $phone; 54 | $this->assertValidity(); 55 | 56 | return $this; 57 | } 58 | 59 | private function assertValidity(): void 60 | { 61 | /** @noinspection IsEmptyFunctionUsageInspection */ 62 | if (empty($this->email) && empty($this->phone)) { 63 | throw new \InvalidArgumentException('Email and phone can not be empty at the same time'); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/Company.php: -------------------------------------------------------------------------------- 1 | ") 21 | */ 22 | private $sno; 23 | /** 24 | * @var string 25 | * 26 | * @Serializer\Type("string") 27 | */ 28 | private $inn; 29 | /** 30 | * @var string 31 | * 32 | * @Serializer\Type("string") 33 | * @Serializer\SerializedName("payment_address") 34 | */ 35 | private $paymentAddress; 36 | 37 | public function __construct(string $email, string $inn, string $paymentAddress) 38 | { 39 | $this->email = $email; 40 | $this->inn = $inn; 41 | $this->paymentAddress = $paymentAddress; 42 | } 43 | 44 | public function getEmail(): string 45 | { 46 | return $this->email; 47 | } 48 | 49 | public function setEmail(string $email): self 50 | { 51 | $this->email = $email; 52 | 53 | return $this; 54 | } 55 | 56 | public function getSno(): ?Sno 57 | { 58 | return $this->sno; 59 | } 60 | 61 | public function setSno(?Sno $sno): self 62 | { 63 | $this->sno = $sno; 64 | 65 | return $this; 66 | } 67 | 68 | public function getInn(): string 69 | { 70 | return $this->inn; 71 | } 72 | 73 | public function setInn(string $inn): self 74 | { 75 | $this->inn = $inn; 76 | 77 | return $this; 78 | } 79 | 80 | public function getPaymentAddress(): string 81 | { 82 | return $this->paymentAddress; 83 | } 84 | 85 | public function setPaymentAddress(string $paymentAddress): self 86 | { 87 | $this->paymentAddress = $paymentAddress; 88 | 89 | return $this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/MoneyTransferOperator.php: -------------------------------------------------------------------------------- 1 | phones; 39 | } 40 | 41 | public function setPhones(array $phones): self 42 | { 43 | $this->phones = $phones; 44 | 45 | return $this; 46 | } 47 | 48 | public function getName(): string 49 | { 50 | return $this->name; 51 | } 52 | 53 | public function setName(string $name): self 54 | { 55 | $this->name = $name; 56 | 57 | return $this; 58 | } 59 | 60 | public function getAddress(): string 61 | { 62 | return $this->address; 63 | } 64 | 65 | public function setAddress(string $address): self 66 | { 67 | $this->address = $address; 68 | 69 | return $this; 70 | } 71 | 72 | public function getInn(): string 73 | { 74 | return $this->inn; 75 | } 76 | 77 | public function setInn(string $inn): self 78 | { 79 | $this->inn = $inn; 80 | 81 | return $this; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/PayingAgent.php: -------------------------------------------------------------------------------- 1 | operation = $operation; 28 | $this->phones = $phones; 29 | } 30 | 31 | public function getOperation(): string 32 | { 33 | return $this->operation; 34 | } 35 | 36 | public function setOperation(string $operation): self 37 | { 38 | $this->operation = $operation; 39 | 40 | return $this; 41 | } 42 | 43 | public function getPhones(): array 44 | { 45 | return $this->phones; 46 | } 47 | 48 | public function setPhones(array $phones): self 49 | { 50 | $this->phones = $phones; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/Payment.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var float 20 | * 21 | * @Serializer\Type("float") 22 | */ 23 | private $sum; 24 | 25 | public function __construct(PaymentType $type, float $sum) 26 | { 27 | $this->type = $type; 28 | $this->sum = $sum; 29 | } 30 | 31 | public function getType(): PaymentType 32 | { 33 | return $this->type; 34 | } 35 | 36 | public function setType(PaymentType $type): self 37 | { 38 | $this->type = $type; 39 | 40 | return $this; 41 | } 42 | 43 | public function getSum(): float 44 | { 45 | return $this->sum; 46 | } 47 | 48 | public function setSum(float $sum): self 49 | { 50 | $this->sum = $sum; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/PaymentMethod.php: -------------------------------------------------------------------------------- 1 | ") 29 | */ 30 | private $items; 31 | 32 | /** 33 | * @var Payment[] 34 | * 35 | * @Serializer\Type("array") 36 | */ 37 | private $payments; 38 | 39 | /** 40 | * @var Vat[]|null 41 | * 42 | * @Serializer\Type("array") 43 | */ 44 | private $vats; 45 | 46 | /** 47 | * @var float 48 | * 49 | * @Serializer\Type("float") 50 | */ 51 | private $total; 52 | 53 | /** 54 | * @param Client $client 55 | * @param Company $company 56 | * @param Item[] $items 57 | * @param Payment[] $payments 58 | * @param float $total 59 | */ 60 | public function __construct(Client $client, Company $company, array $items, array $payments, float $total) 61 | { 62 | $this->client = $client; 63 | $this->company = $company; 64 | $this->items = $items; 65 | $this->payments = $payments; 66 | $this->total = $total; 67 | } 68 | 69 | public function getClient(): Client 70 | { 71 | return $this->client; 72 | } 73 | 74 | public function setClient(Client $client): self 75 | { 76 | $this->client = $client; 77 | 78 | return $this; 79 | } 80 | 81 | public function getCompany(): Company 82 | { 83 | return $this->company; 84 | } 85 | 86 | public function setCompany(Company $company): self 87 | { 88 | $this->company = $company; 89 | 90 | return $this; 91 | } 92 | 93 | /** 94 | * @return Item[] 95 | */ 96 | public function getItems(): array 97 | { 98 | return $this->items; 99 | } 100 | 101 | /** 102 | * @param Item[] $items 103 | * 104 | * @return Receipt 105 | */ 106 | public function setItems(array $items): self 107 | { 108 | $this->items = $items; 109 | 110 | return $this; 111 | } 112 | 113 | /** 114 | * @return Payment[] 115 | */ 116 | public function getPayments(): array 117 | { 118 | return $this->payments; 119 | } 120 | 121 | /** 122 | * @param Payment[] $payments 123 | * 124 | * @return Receipt 125 | */ 126 | public function setPayments(array $payments): self 127 | { 128 | $this->payments = $payments; 129 | 130 | return $this; 131 | } 132 | 133 | /** 134 | * @return Vat[]|null 135 | */ 136 | public function getVats(): ?array 137 | { 138 | return $this->vats; 139 | } 140 | 141 | /** 142 | * @param Vat[]|null $vats 143 | * 144 | * @return Receipt 145 | */ 146 | public function setVats(?array $vats): self 147 | { 148 | $this->vats = $vats; 149 | 150 | return $this; 151 | } 152 | 153 | public function getTotal(): float 154 | { 155 | return $this->total; 156 | } 157 | 158 | public function setTotal(float $total): self 159 | { 160 | $this->total = $total; 161 | 162 | return $this; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/ReceivePaymentsOperator.php: -------------------------------------------------------------------------------- 1 | phones = $phones; 21 | } 22 | 23 | public function getPhones(): array 24 | { 25 | return $this->phones; 26 | } 27 | 28 | public function setPhones(array $phones): self 29 | { 30 | $this->phones = $phones; 31 | 32 | return $this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/RegisterRequest.php: -------------------------------------------------------------------------------- 1 | externalId = $externalId; 39 | $this->receipt = $receipt; 40 | $this->timestamp = $timestamp; 41 | } 42 | 43 | public function setTimestamp(\DateTime $timestamp): self 44 | { 45 | $this->timestamp = $timestamp; 46 | 47 | return $this; 48 | } 49 | 50 | public function getExternalId(): string 51 | { 52 | return $this->externalId; 53 | } 54 | 55 | public function setExternalId(string $externalId): void 56 | { 57 | $this->externalId = $externalId; 58 | } 59 | 60 | public function getService(): ?Service 61 | { 62 | return $this->service; 63 | } 64 | 65 | public function setService(?Service $service): void 66 | { 67 | $this->service = $service; 68 | } 69 | 70 | public function getReceipt(): Receipt 71 | { 72 | return $this->receipt; 73 | } 74 | 75 | public function setReceipt(Receipt $receipt): void 76 | { 77 | $this->receipt = $receipt; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/RegisterResponse.php: -------------------------------------------------------------------------------- 1 | ") 27 | */ 28 | private $status; 29 | 30 | public function getUuid(): ?string 31 | { 32 | return $this->uuid; 33 | } 34 | 35 | public function getStatus(): ?Status 36 | { 37 | return $this->status; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/Service.php: -------------------------------------------------------------------------------- 1 | callbackUrl = $callbackUrl; 22 | } 23 | 24 | public function getCallbackUrl(): string 25 | { 26 | return $this->callbackUrl; 27 | } 28 | 29 | public function setCallbackUrl(string $callbackUrl): self 30 | { 31 | $this->callbackUrl = $callbackUrl; 32 | 33 | return $this; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/Sno.php: -------------------------------------------------------------------------------- 1 | phones = $phones; 33 | $this->name = $name; 34 | $this->inn = $inn; 35 | } 36 | 37 | public function getPhones(): array 38 | { 39 | return $this->phones; 40 | } 41 | 42 | public function setPhones(array $phones): self 43 | { 44 | $this->phones = $phones; 45 | 46 | return $this; 47 | } 48 | 49 | public function getName(): string 50 | { 51 | return $this->name; 52 | } 53 | 54 | public function setName(string $name): self 55 | { 56 | $this->name = $name; 57 | 58 | return $this; 59 | } 60 | 61 | public function getInn(): string 62 | { 63 | return $this->inn; 64 | } 65 | 66 | public function setInn(string $inn): self 67 | { 68 | $this->inn = $inn; 69 | 70 | return $this; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/Vat.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var float 20 | * 21 | * @Serializer\Type("float") 22 | */ 23 | private $sum; 24 | 25 | public function __construct(VatType $type, float $sum) 26 | { 27 | $this->type = $type; 28 | $this->sum = $sum; 29 | } 30 | 31 | public function getType(): VatType 32 | { 33 | return $this->type; 34 | } 35 | 36 | public function setType(VatType $type): self 37 | { 38 | $this->type = $type; 39 | 40 | return $this; 41 | } 42 | 43 | public function getSum(): float 44 | { 45 | return $this->sum; 46 | } 47 | 48 | public function setSum(float $sum): self 49 | { 50 | $this->sum = $sum; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V4/DTO/Register/VatType.php: -------------------------------------------------------------------------------- 1 | ") 27 | */ 28 | private $receiptDatetime; 29 | 30 | /** 31 | * @var float 32 | * 33 | * @Serializer\Type("float") 34 | */ 35 | private $total; 36 | 37 | /** 38 | * @var string 39 | * 40 | * @Serializer\Type("string") 41 | */ 42 | private $fnNumber; 43 | 44 | /** 45 | * @var string 46 | * 47 | * @Serializer\Type("string") 48 | */ 49 | private $ecrRegistrationNumber; 50 | 51 | /** 52 | * @var int 53 | * 54 | * @Serializer\Type("integer") 55 | */ 56 | private $fiscalDocumentNumber; 57 | 58 | /** 59 | * @var int 60 | * 61 | * @Serializer\Type("integer") 62 | */ 63 | private $fiscalDocumentAttribute; 64 | 65 | /** 66 | * @var string 67 | * 68 | * @Serializer\Type("string") 69 | */ 70 | private $fnsSite; 71 | 72 | public function getTotal(): float 73 | { 74 | return $this->total; 75 | } 76 | 77 | public function getFnNumber(): string 78 | { 79 | return $this->fnNumber; 80 | } 81 | 82 | public function getShiftNumber(): int 83 | { 84 | return $this->shiftNumber; 85 | } 86 | 87 | public function getReceiptDatetime(): \DateTimeInterface 88 | { 89 | return $this->receiptDatetime; 90 | } 91 | 92 | public function getFiscalReceiptNumber(): int 93 | { 94 | return $this->fiscalReceiptNumber; 95 | } 96 | 97 | public function getFiscalDocumentNumber(): int 98 | { 99 | return $this->fiscalDocumentNumber; 100 | } 101 | 102 | public function getEcrRegistrationNumber(): string 103 | { 104 | return $this->ecrRegistrationNumber; 105 | } 106 | 107 | public function getFiscalDocumentAttribute(): int 108 | { 109 | return $this->fiscalDocumentAttribute; 110 | } 111 | 112 | public function getFnsSite(): string 113 | { 114 | return $this->fnsSite; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/V4/DTO/Report/ReportResponse.php: -------------------------------------------------------------------------------- 1 | ") 55 | */ 56 | private $status; 57 | 58 | /** 59 | * @var Payload|null 60 | * 61 | * @Serializer\Type("Lamoda\AtolClient\V4\DTO\Report\Payload") 62 | */ 63 | private $payload; 64 | 65 | public function getUuid(): ?string 66 | { 67 | return $this->uuid; 68 | } 69 | 70 | public function getGroupCode(): ?string 71 | { 72 | return $this->groupCode; 73 | } 74 | 75 | public function getDaemonCode(): ?string 76 | { 77 | return $this->daemonCode; 78 | } 79 | 80 | public function getDeviceCode(): ?string 81 | { 82 | return $this->deviceCode; 83 | } 84 | 85 | public function getCallbackUrl(): ?string 86 | { 87 | return $this->callbackUrl; 88 | } 89 | 90 | public function getStatus(): ?Status 91 | { 92 | return $this->status; 93 | } 94 | 95 | public function getPayload(): ?Payload 96 | { 97 | return $this->payload; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/V4/DTO/Report/Status.php: -------------------------------------------------------------------------------- 1 | ") 35 | */ 36 | private $type; 37 | 38 | public function getErrorId(): string 39 | { 40 | return $this->errorId; 41 | } 42 | 43 | public function getCode(): int 44 | { 45 | return $this->code; 46 | } 47 | 48 | public function getText(): string 49 | { 50 | return $this->text; 51 | } 52 | 53 | public function getType(): ErrorType 54 | { 55 | return $this->type; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/V4/DTO/Shared/ErrorTrait.php: -------------------------------------------------------------------------------- 1 | error; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/V4/DTO/Shared/ErrorType.php: -------------------------------------------------------------------------------- 1 | ") 15 | * 16 | * @var \DateTime 17 | */ 18 | private $timestamp; 19 | 20 | /** 21 | * @return \DateTime 22 | */ 23 | public function getTimestamp(): \DateTime 24 | { 25 | return $this->timestamp; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V5/AtolApi.php: -------------------------------------------------------------------------------- 1 | converter = $converter; 52 | $this->client = $client; 53 | $this->clientOptions = $clientOptions; 54 | $this->baseUri = rtrim($baseUri, '/'); 55 | } 56 | 57 | public function getToken(GetTokenRequest $request): GetTokenResponse 58 | { 59 | $response = $this->request('POST', 'getToken', [], $request); 60 | 61 | return $this->converter->getResponseObject(GetTokenResponse::class, $response); 62 | } 63 | 64 | public function sell(string $groupCode, string $token, RegisterRequest $request): RegisterResponse 65 | { 66 | return $this->register(self::OPERATION_SELL, $groupCode, $token, $request); 67 | } 68 | 69 | public function sellRefund(string $groupCode, string $token, RegisterRequest $request): RegisterResponse 70 | { 71 | return $this->register(self::OPERATION_SELL_REFUND, $groupCode, $token, $request); 72 | } 73 | 74 | public function sellCorrection(string $groupCode, string $token, CorrectionRequest $request): CorrectionResponse 75 | { 76 | return $this->correction(self::OPERATION_SELL_CORRECTION, $groupCode, $token, $request); 77 | } 78 | 79 | public function sellRefundCorrection(string $groupCode, string $token, CorrectionRequest $request): CorrectionResponse 80 | { 81 | return $this->correction(self::OPERATION_SELL_REFUND_CORRECTION, $groupCode, $token, $request); 82 | } 83 | 84 | public function report(string $groupCode, string $token, string $uuid): ReportResponse 85 | { 86 | $response = $this->request( 87 | 'GET', 88 | "$groupCode/report/$uuid", 89 | [], 90 | null, 91 | [ 92 | 'Token' => $token, 93 | ] 94 | ); 95 | 96 | return $this->converter->getResponseObject(ReportResponse::class, $response); 97 | } 98 | 99 | private function correction( 100 | string $operation, 101 | string $groupCode, 102 | string $token, 103 | CorrectionRequest $request 104 | ): CorrectionResponse { 105 | $response = $this->request( 106 | 'POST', 107 | "$groupCode/$operation", 108 | [], 109 | $request, 110 | [ 111 | 'Token' => $token, 112 | ] 113 | ); 114 | 115 | return $this->converter->getResponseObject(CorrectionResponse::class, $response); 116 | } 117 | 118 | private function register( 119 | string $operation, 120 | string $groupCode, 121 | string $token, 122 | RegisterRequest $request 123 | ): RegisterResponse { 124 | $response = $this->request( 125 | 'POST', 126 | "$groupCode/$operation", 127 | [], 128 | $request, 129 | [ 130 | 'Token' => $token, 131 | ] 132 | ); 133 | 134 | return $this->converter->getResponseObject(RegisterResponse::class, $response); 135 | } 136 | 137 | private function request(string $method, string $path, array $query = [], $body = null, array $headers = []): string 138 | { 139 | // Prepare request: 140 | $body = $this->parseBody($body); 141 | $path = trim($path, '/'); 142 | $uri = "{$this->baseUri}/v5/$path/"; 143 | 144 | $headers = array_merge($headers, [ 145 | 'Content-Type' => 'application/json', 146 | ]); 147 | 148 | $options = array_merge($this->clientOptions, [ 149 | RequestOptions::HEADERS => $headers, 150 | RequestOptions::QUERY => $query, 151 | RequestOptions::BODY => $body, 152 | // configuration 153 | RequestOptions::HTTP_ERRORS => false, 154 | ]); 155 | 156 | $response = $this->client->request( 157 | $method, 158 | $uri, 159 | $options 160 | ); 161 | 162 | return (string) $response->getBody(); 163 | } 164 | 165 | private function parseBody($body = null): ?string 166 | { 167 | if ($body === null || \is_string($body)) { 168 | return $body; 169 | } 170 | 171 | return $this->converter->getRequestString($body); 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/AdditionalUserProps.php: -------------------------------------------------------------------------------- 1 | name = $name; 26 | $this->value = $value; 27 | } 28 | 29 | public function getName(): string 30 | { 31 | return $this->name; 32 | } 33 | 34 | public function setName(string $name): self 35 | { 36 | $this->name = $name; 37 | 38 | return $this; 39 | } 40 | 41 | public function getValue(): string 42 | { 43 | return $this->value; 44 | } 45 | 46 | public function setValue(string $value): self 47 | { 48 | $this->value = $value; 49 | 50 | return $this; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/CorrectionInfo.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var \DateTime|null 20 | * 21 | * @Serializer\Type("DateTime<'d.m.Y'>") 22 | * @Serializer\SerializedName("base_date") 23 | */ 24 | private $baseDate; 25 | 26 | /** 27 | * @var string|null 28 | * 29 | * @Serializer\Type("string") 30 | * @Serializer\SerializedName("base_number") 31 | */ 32 | private $baseNumber; 33 | 34 | public function __construct(CorrectionType $type) 35 | { 36 | $this->type = $type; 37 | } 38 | 39 | public function getType(): CorrectionType 40 | { 41 | return $this->type; 42 | } 43 | 44 | public function setType(CorrectionType $type): self 45 | { 46 | $this->type = $type; 47 | 48 | return $this; 49 | } 50 | 51 | public function getBaseDate(): \DateTime 52 | { 53 | return $this->baseDate; 54 | } 55 | 56 | public function setBaseDate(\DateTime $baseDate): self 57 | { 58 | $this->baseDate = $baseDate; 59 | 60 | return $this; 61 | } 62 | 63 | public function getBaseNumber(): string 64 | { 65 | return $this->baseNumber; 66 | } 67 | 68 | public function setBaseNumber(string $baseNumber): self 69 | { 70 | $this->baseNumber = $baseNumber; 71 | 72 | return $this; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/CorrectionRequest.php: -------------------------------------------------------------------------------- 1 | externalId = $externalId; 40 | $this->correction = $correction; 41 | $this->timestamp = $timestamp; 42 | } 43 | 44 | public function setTimestamp(\DateTime $timestamp): self 45 | { 46 | $this->timestamp = $timestamp; 47 | 48 | return $this; 49 | } 50 | 51 | public function getExternalId(): string 52 | { 53 | return $this->externalId; 54 | } 55 | 56 | public function setExternalId(string $externalId): void 57 | { 58 | $this->externalId = $externalId; 59 | } 60 | 61 | public function getService(): ?Service 62 | { 63 | return $this->service; 64 | } 65 | 66 | public function setService(?Service $service): void 67 | { 68 | $this->service = $service; 69 | } 70 | 71 | public function getCorrection(): Correction 72 | { 73 | return $this->correction; 74 | } 75 | 76 | public function setCorrection(Correction $correction): self 77 | { 78 | $this->correction = $correction; 79 | 80 | return $this; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/CorrectionResponse.php: -------------------------------------------------------------------------------- 1 | ") 28 | */ 29 | private $status; 30 | 31 | public function getUuid(): ?string 32 | { 33 | return $this->uuid; 34 | } 35 | 36 | public function getStatus(): ?Status 37 | { 38 | return $this->status; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/CorrectionType.php: -------------------------------------------------------------------------------- 1 | ") 27 | */ 28 | private $timestamp; 29 | 30 | public function __construct(string $name, string $value, \DateTime $timestamp) 31 | { 32 | $this->name = $name; 33 | $this->value = $value; 34 | $this->timestamp = $timestamp; 35 | } 36 | 37 | public function getTimestamp(): \DateTime 38 | { 39 | return $this->timestamp; 40 | } 41 | 42 | public function setTimestamp($timestamp): self 43 | { 44 | $this->timestamp = $timestamp; 45 | 46 | return $this; 47 | } 48 | 49 | public function getName(): string 50 | { 51 | return $this->name; 52 | } 53 | 54 | public function setName(string $name): self 55 | { 56 | $this->name = $name; 57 | 58 | return $this; 59 | } 60 | 61 | public function getValue(): string 62 | { 63 | return $this->value; 64 | } 65 | 66 | public function setValue(string $value): self 67 | { 68 | $this->value = $value; 69 | 70 | return $this; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/V5/DTO/Correction/SectoralCheckProps.php: -------------------------------------------------------------------------------- 1 | ) 13 | */ 14 | private $federalId; 15 | 16 | /** 17 | * @var \DateTime 18 | * 19 | * @Serializer\Type("DateTime<'d.m.Y'>") 20 | */ 21 | private $date; 22 | 23 | /** 24 | * @var string 25 | * 26 | * @Serializer\Type("string") 27 | */ 28 | private $number; 29 | 30 | /** 31 | * @var string 32 | * 33 | * @Serializer\Type("string") 34 | */ 35 | private $value; 36 | 37 | public function __construct(string $federalId, \DateTime $date, string $number, string $value) 38 | { 39 | $this->federalId = $federalId; 40 | $this->date = $date; 41 | $this->number = $number; 42 | $this->value = $value; 43 | } 44 | 45 | 46 | public function getFederalId(): FederalId 47 | { 48 | return $this->federalId; 49 | } 50 | 51 | public function setFederalId(FederalId $federalId): self 52 | { 53 | $this->federalId = $federalId; 54 | 55 | return $this; 56 | } 57 | 58 | public function getDate(): \DateTime 59 | { 60 | return $this->date; 61 | } 62 | 63 | public function setDate(\DateTime $date): self 64 | { 65 | $this->date = $date; 66 | 67 | return $this; 68 | } 69 | 70 | public function getNumber(): string 71 | { 72 | return $this->number; 73 | } 74 | 75 | public function setNumber(string $number): self 76 | { 77 | $this->number = $number; 78 | 79 | return $this; 80 | } 81 | 82 | public function getValue(): string 83 | { 84 | return $this->value; 85 | } 86 | 87 | public function setValue(string $value): self 88 | { 89 | $this->value = $value; 90 | 91 | return $this; 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/V5/DTO/GetToken/GetTokenRequest.php: -------------------------------------------------------------------------------- 1 | login = $login; 27 | $this->pass = $pass; 28 | } 29 | 30 | public function getLogin(): string 31 | { 32 | return $this->login; 33 | } 34 | 35 | public function setLogin(string $login): self 36 | { 37 | $this->login = $login; 38 | 39 | return $this; 40 | } 41 | 42 | public function getPass(): string 43 | { 44 | return $this->pass; 45 | } 46 | 47 | public function setPass(string $pass): self 48 | { 49 | $this->pass = $pass; 50 | 51 | return $this; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/V5/DTO/GetToken/GetTokenResponse.php: -------------------------------------------------------------------------------- 1 | token; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/AgentInfo.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var PayingAgent|null 20 | * 21 | * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Register\PayingAgent") 22 | */ 23 | private $payingAgent; 24 | 25 | /** 26 | * @var ReceivePaymentsOperator|null 27 | * 28 | * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Register\ReceivePaymentsOperator") 29 | */ 30 | private $receivePaymentsOperator; 31 | 32 | /** 33 | * @var MoneyTransferOperator|null 34 | * 35 | * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Register\MoneyTransferOperator") 36 | */ 37 | private $moneyTransferOperator; 38 | 39 | public function __construct(AgentType $type) 40 | { 41 | $this->type = $type; 42 | } 43 | 44 | public function getType(): AgentType 45 | { 46 | return $this->type; 47 | } 48 | 49 | public function setType(AgentType $type): self 50 | { 51 | $this->type = $type; 52 | 53 | return $this; 54 | } 55 | 56 | public function getPayingAgent(): ?PayingAgent 57 | { 58 | return $this->payingAgent; 59 | } 60 | 61 | public function setPayingAgent(?PayingAgent $payingAgent): self 62 | { 63 | $this->payingAgent = $payingAgent; 64 | 65 | return $this; 66 | } 67 | 68 | public function getReceivePaymentsOperator(): ?ReceivePaymentsOperator 69 | { 70 | return $this->receivePaymentsOperator; 71 | } 72 | 73 | public function setReceivePaymentsOperator(?ReceivePaymentsOperator $receivePaymentsOperator): self 74 | { 75 | $this->receivePaymentsOperator = $receivePaymentsOperator; 76 | 77 | return $this; 78 | } 79 | 80 | public function getMoneyTransferOperator(): ?MoneyTransferOperator 81 | { 82 | return $this->moneyTransferOperator; 83 | } 84 | 85 | public function setMoneyTransferOperator(?MoneyTransferOperator $moneyTransferOperator): self 86 | { 87 | $this->moneyTransferOperator = $moneyTransferOperator; 88 | 89 | return $this; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/AgentType.php: -------------------------------------------------------------------------------- 1 | email = $email; 28 | $this->phone = $phone; 29 | 30 | $this->assertValidity(); 31 | } 32 | 33 | public function getEmail(): ?string 34 | { 35 | return $this->email; 36 | } 37 | 38 | public function setEmail(?string $email): self 39 | { 40 | $this->email = $email; 41 | $this->assertValidity(); 42 | 43 | return $this; 44 | } 45 | 46 | public function getPhone(): ?string 47 | { 48 | return $this->phone; 49 | } 50 | 51 | public function setPhone(?string $phone): self 52 | { 53 | $this->phone = $phone; 54 | $this->assertValidity(); 55 | 56 | return $this; 57 | } 58 | 59 | private function assertValidity(): void 60 | { 61 | /** @noinspection IsEmptyFunctionUsageInspection */ 62 | if ($this->isEmpty($this->email) && $this->isEmpty($this->phone)) { 63 | throw new \InvalidArgumentException('Email and phone can not be empty at the same time'); 64 | } 65 | 66 | $pattern = '/^\+?[0-9]{1,18}$/'; 67 | if (!$this->isEmpty($this->phone) && !preg_match($pattern, $this->phone)) { 68 | throw new \InvalidArgumentException('Phone is not valid. Phone: ' . $this->phone); 69 | } 70 | } 71 | 72 | private function isEmpty($phoneOrEmail): bool 73 | { 74 | return empty($phoneOrEmail) || 'none' === $phoneOrEmail; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Company.php: -------------------------------------------------------------------------------- 1 | ") 21 | */ 22 | private $sno; 23 | /** 24 | * @var string 25 | * 26 | * @Serializer\Type("string") 27 | */ 28 | private $inn; 29 | /** 30 | * @var string 31 | * 32 | * @Serializer\Type("string") 33 | * @Serializer\SerializedName("payment_address") 34 | */ 35 | private $paymentAddress; 36 | 37 | public function __construct(string $email, string $inn, string $paymentAddress, Sno $sno) 38 | { 39 | $this->email = $email; 40 | $this->inn = $inn; 41 | $this->paymentAddress = $paymentAddress; 42 | $this->sno = $sno; 43 | } 44 | 45 | public function getEmail(): string 46 | { 47 | return $this->email; 48 | } 49 | 50 | public function setEmail(string $email): self 51 | { 52 | $this->email = $email; 53 | 54 | return $this; 55 | } 56 | 57 | public function getSno(): ?Sno 58 | { 59 | return $this->sno; 60 | } 61 | 62 | public function setSno(Sno $sno): self 63 | { 64 | $this->sno = $sno; 65 | 66 | return $this; 67 | } 68 | 69 | public function getInn(): string 70 | { 71 | return $this->inn; 72 | } 73 | 74 | public function setInn(string $inn): self 75 | { 76 | $this->inn = $inn; 77 | 78 | return $this; 79 | } 80 | 81 | public function getPaymentAddress(): string 82 | { 83 | return $this->paymentAddress; 84 | } 85 | 86 | public function setPaymentAddress(string $paymentAddress): self 87 | { 88 | $this->paymentAddress = $paymentAddress; 89 | 90 | return $this; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/MarkCode.php: -------------------------------------------------------------------------------- 1 | format = $format; 106 | $this->$format = $value; 107 | 108 | $this->assertValidity(); 109 | } 110 | 111 | private function isValidFormat(string $format): bool 112 | { 113 | return in_array($format, self::VALID_FORMATS); 114 | } 115 | 116 | public function getValue(): string 117 | { 118 | return $this->{$this->format}; 119 | } 120 | 121 | /** 122 | * @return string|null 123 | */ 124 | public function getUnknown(): ?string 125 | { 126 | return $this->unknown; 127 | } 128 | 129 | /** 130 | * @return string|null 131 | */ 132 | public function getEan8(): ?string 133 | { 134 | return $this->ean8; 135 | } 136 | 137 | /** 138 | * @return string|null 139 | */ 140 | public function getEan13(): ?string 141 | { 142 | return $this->ean13; 143 | } 144 | 145 | /** 146 | * @return string|null 147 | */ 148 | public function getItf14(): ?string 149 | { 150 | return $this->itf14; 151 | } 152 | 153 | /** 154 | * @return string|null 155 | */ 156 | public function getGs1m(): ?string 157 | { 158 | return $this->gs1m; 159 | } 160 | 161 | /** 162 | * @return string|null 163 | */ 164 | public function getShort(): ?string 165 | { 166 | return $this->short; 167 | } 168 | 169 | /** 170 | * @return string|null 171 | */ 172 | public function getFur(): ?string 173 | { 174 | return $this->fur; 175 | } 176 | 177 | /** 178 | * @return string|null 179 | */ 180 | public function getEgais20(): ?string 181 | { 182 | return $this->egais20; 183 | } 184 | 185 | /** 186 | * @return string|null 187 | */ 188 | public function getEgais30(): ?string 189 | { 190 | return $this->egais30; 191 | } 192 | 193 | /** 194 | * @throws \InvalidArgumentException 195 | */ 196 | private function assertValidity(): void 197 | { 198 | if (!$this->isValidFormat($this->format) || !property_exists($this, $this->format)) { 199 | throw new \InvalidArgumentException('Format of mark code is not valid. Format: ' 200 | . $this->format . '. Valid formats: ' . implode(self::VALID_FORMATS, ', ')); 201 | } 202 | 203 | if (in_array($this->format, [self::EAN8, self::EAN13, self::ITF14]) && !is_numeric($this->getValue())) { 204 | throw new \InvalidArgumentException('Value for format ' . $this->format . ' mast be numeric. Value: ' . $this->getValue()); 205 | } 206 | } 207 | 208 | } 209 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Measure.php: -------------------------------------------------------------------------------- 1 | phones; 39 | } 40 | 41 | public function setPhones(array $phones): self 42 | { 43 | $this->phones = $phones; 44 | 45 | return $this; 46 | } 47 | 48 | public function getName(): string 49 | { 50 | return $this->name; 51 | } 52 | 53 | public function setName(string $name): self 54 | { 55 | $this->name = $name; 56 | 57 | return $this; 58 | } 59 | 60 | public function getAddress(): string 61 | { 62 | return $this->address; 63 | } 64 | 65 | public function setAddress(string $address): self 66 | { 67 | $this->address = $address; 68 | 69 | return $this; 70 | } 71 | 72 | public function getInn(): string 73 | { 74 | return $this->inn; 75 | } 76 | 77 | public function setInn(string $inn): self 78 | { 79 | $this->inn = $inn; 80 | 81 | return $this; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/PayingAgent.php: -------------------------------------------------------------------------------- 1 | operation = $operation; 28 | $this->phones = $phones; 29 | } 30 | 31 | public function getOperation(): string 32 | { 33 | return $this->operation; 34 | } 35 | 36 | public function setOperation(string $operation): self 37 | { 38 | $this->operation = $operation; 39 | 40 | return $this; 41 | } 42 | 43 | public function getPhones(): array 44 | { 45 | return $this->phones; 46 | } 47 | 48 | public function setPhones(array $phones): self 49 | { 50 | $this->phones = $phones; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Payment.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var float 20 | * 21 | * @Serializer\Type("float") 22 | */ 23 | private $sum; 24 | 25 | public function __construct(PaymentType $type, float $sum) 26 | { 27 | $this->type = $type; 28 | $this->sum = $sum; 29 | } 30 | 31 | public function getType(): PaymentType 32 | { 33 | return $this->type; 34 | } 35 | 36 | public function setType(PaymentType $type): self 37 | { 38 | $this->type = $type; 39 | 40 | return $this; 41 | } 42 | 43 | public function getSum(): float 44 | { 45 | return $this->sum; 46 | } 47 | 48 | public function setSum(float $sum): self 49 | { 50 | $this->sum = $sum; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/PaymentMethod.php: -------------------------------------------------------------------------------- 1 | ") 29 | */ 30 | private $items; 31 | 32 | /** 33 | * @var Payment[] 34 | * 35 | * @Serializer\Type("array") 36 | */ 37 | private $payments; 38 | 39 | /** 40 | * @var Vat[]|null 41 | * 42 | * @Serializer\Type("array") 43 | */ 44 | private $vats; 45 | 46 | /** 47 | * @var float 48 | * 49 | * @Serializer\Type("float") 50 | */ 51 | private $total; 52 | 53 | /** 54 | * @param Client $client 55 | * @param Company $company 56 | * @param Item[] $items 57 | * @param Payment[] $payments 58 | * @param float $total 59 | */ 60 | public function __construct(Client $client, Company $company, array $items, array $payments, float $total) 61 | { 62 | $this->client = $client; 63 | $this->company = $company; 64 | $this->items = $items; 65 | $this->payments = $payments; 66 | $this->total = $total; 67 | } 68 | 69 | public function getClient(): Client 70 | { 71 | return $this->client; 72 | } 73 | 74 | public function setClient(Client $client): self 75 | { 76 | $this->client = $client; 77 | 78 | return $this; 79 | } 80 | 81 | public function getCompany(): Company 82 | { 83 | return $this->company; 84 | } 85 | 86 | public function setCompany(Company $company): self 87 | { 88 | $this->company = $company; 89 | 90 | return $this; 91 | } 92 | 93 | /** 94 | * @return Item[] 95 | */ 96 | public function getItems(): array 97 | { 98 | return $this->items; 99 | } 100 | 101 | /** 102 | * @param Item[] $items 103 | * 104 | * @return Receipt 105 | */ 106 | public function setItems(array $items): self 107 | { 108 | $this->items = $items; 109 | 110 | return $this; 111 | } 112 | 113 | /** 114 | * @return Payment[] 115 | */ 116 | public function getPayments(): array 117 | { 118 | return $this->payments; 119 | } 120 | 121 | /** 122 | * @param Payment[] $payments 123 | * 124 | * @return Receipt 125 | */ 126 | public function setPayments(array $payments): self 127 | { 128 | $this->payments = $payments; 129 | 130 | return $this; 131 | } 132 | 133 | /** 134 | * @return Vat[]|null 135 | */ 136 | public function getVats(): ?array 137 | { 138 | return $this->vats; 139 | } 140 | 141 | /** 142 | * @param Vat[]|null $vats 143 | * 144 | * @return Receipt 145 | */ 146 | public function setVats(?array $vats): self 147 | { 148 | $this->vats = $vats; 149 | 150 | return $this; 151 | } 152 | 153 | public function getTotal(): float 154 | { 155 | return $this->total; 156 | } 157 | 158 | public function setTotal(float $total): self 159 | { 160 | $this->total = $total; 161 | 162 | return $this; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/ReceivePaymentsOperator.php: -------------------------------------------------------------------------------- 1 | phones = $phones; 21 | } 22 | 23 | public function getPhones(): array 24 | { 25 | return $this->phones; 26 | } 27 | 28 | public function setPhones(array $phones): self 29 | { 30 | $this->phones = $phones; 31 | 32 | return $this; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/RegisterRequest.php: -------------------------------------------------------------------------------- 1 | externalId = $externalId; 39 | $this->receipt = $receipt; 40 | $this->timestamp = $timestamp; 41 | } 42 | 43 | public function setTimestamp(\DateTime $timestamp): self 44 | { 45 | $this->timestamp = $timestamp; 46 | 47 | return $this; 48 | } 49 | 50 | public function getExternalId(): string 51 | { 52 | return $this->externalId; 53 | } 54 | 55 | public function setExternalId(string $externalId): void 56 | { 57 | $this->externalId = $externalId; 58 | } 59 | 60 | public function getService(): ?Service 61 | { 62 | return $this->service; 63 | } 64 | 65 | public function setService(?Service $service): void 66 | { 67 | $this->service = $service; 68 | } 69 | 70 | public function getReceipt(): Receipt 71 | { 72 | return $this->receipt; 73 | } 74 | 75 | public function setReceipt(Receipt $receipt): void 76 | { 77 | $this->receipt = $receipt; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/RegisterResponse.php: -------------------------------------------------------------------------------- 1 | ") 27 | */ 28 | private $status; 29 | 30 | public function getUuid(): ?string 31 | { 32 | return $this->uuid; 33 | } 34 | 35 | public function getStatus(): ?Status 36 | { 37 | return $this->status; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Service.php: -------------------------------------------------------------------------------- 1 | callbackUrl = $callbackUrl; 22 | } 23 | 24 | public function getCallbackUrl(): string 25 | { 26 | return $this->callbackUrl; 27 | } 28 | 29 | public function setCallbackUrl(string $callbackUrl): self 30 | { 31 | $this->callbackUrl = $callbackUrl; 32 | 33 | return $this; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Sno.php: -------------------------------------------------------------------------------- 1 | phones = $phones; 33 | $this->name = $name; 34 | $this->inn = $inn; 35 | } 36 | 37 | public function getPhones(): array 38 | { 39 | return $this->phones; 40 | } 41 | 42 | public function setPhones(array $phones): self 43 | { 44 | $this->phones = $phones; 45 | 46 | return $this; 47 | } 48 | 49 | public function getName(): string 50 | { 51 | return $this->name; 52 | } 53 | 54 | public function setName(string $name): self 55 | { 56 | $this->name = $name; 57 | 58 | return $this; 59 | } 60 | 61 | public function getInn(): string 62 | { 63 | return $this->inn; 64 | } 65 | 66 | public function setInn(string $inn): self 67 | { 68 | $this->inn = $inn; 69 | 70 | return $this; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/Vat.php: -------------------------------------------------------------------------------- 1 | ") 15 | */ 16 | private $type; 17 | 18 | /** 19 | * @var float 20 | * 21 | * @Serializer\Type("float") 22 | */ 23 | private $sum; 24 | 25 | public function __construct(VatType $type, float $sum) 26 | { 27 | $this->type = $type; 28 | $this->sum = $sum; 29 | } 30 | 31 | public function getType(): VatType 32 | { 33 | return $this->type; 34 | } 35 | 36 | public function setType(VatType $type): self 37 | { 38 | $this->type = $type; 39 | 40 | return $this; 41 | } 42 | 43 | public function getSum(): float 44 | { 45 | return $this->sum; 46 | } 47 | 48 | public function setSum(float $sum): self 49 | { 50 | $this->sum = $sum; 51 | 52 | return $this; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/V5/DTO/Register/VatType.php: -------------------------------------------------------------------------------- 1 | ") 27 | */ 28 | private $receiptDatetime; 29 | 30 | /** 31 | * @var float 32 | * 33 | * @Serializer\Type("float") 34 | */ 35 | private $total; 36 | 37 | /** 38 | * @var string 39 | * 40 | * @Serializer\Type("string") 41 | */ 42 | private $fnNumber; 43 | 44 | /** 45 | * @var string 46 | * 47 | * @Serializer\Type("string") 48 | */ 49 | private $ecrRegistrationNumber; 50 | 51 | /** 52 | * @var int 53 | * 54 | * @Serializer\Type("integer") 55 | */ 56 | private $fiscalDocumentNumber; 57 | 58 | /** 59 | * @var int 60 | * 61 | * @Serializer\Type("integer") 62 | */ 63 | private $fiscalDocumentAttribute; 64 | 65 | /** 66 | * @var string 67 | * 68 | * @Serializer\Type("string") 69 | */ 70 | private $fnsSite; 71 | 72 | public function getTotal(): float 73 | { 74 | return $this->total; 75 | } 76 | 77 | public function getFnNumber(): string 78 | { 79 | return $this->fnNumber; 80 | } 81 | 82 | public function getShiftNumber(): int 83 | { 84 | return $this->shiftNumber; 85 | } 86 | 87 | public function getReceiptDatetime(): \DateTimeInterface 88 | { 89 | return $this->receiptDatetime; 90 | } 91 | 92 | public function getFiscalReceiptNumber(): int 93 | { 94 | return $this->fiscalReceiptNumber; 95 | } 96 | 97 | public function getFiscalDocumentNumber(): int 98 | { 99 | return $this->fiscalDocumentNumber; 100 | } 101 | 102 | public function getEcrRegistrationNumber(): string 103 | { 104 | return $this->ecrRegistrationNumber; 105 | } 106 | 107 | public function getFiscalDocumentAttribute(): int 108 | { 109 | return $this->fiscalDocumentAttribute; 110 | } 111 | 112 | public function getFnsSite(): string 113 | { 114 | return $this->fnsSite; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/V5/DTO/Report/ReportResponse.php: -------------------------------------------------------------------------------- 1 | ") 55 | */ 56 | private $status; 57 | 58 | /** 59 | * @var Payload|null 60 | * 61 | * @Serializer\Type("Lamoda\AtolClient\V5\DTO\Report\Payload") 62 | */ 63 | private $payload; 64 | 65 | public function getUuid(): ?string 66 | { 67 | return $this->uuid; 68 | } 69 | 70 | public function getGroupCode(): ?string 71 | { 72 | return $this->groupCode; 73 | } 74 | 75 | public function getDaemonCode(): ?string 76 | { 77 | return $this->daemonCode; 78 | } 79 | 80 | public function getDeviceCode(): ?string 81 | { 82 | return $this->deviceCode; 83 | } 84 | 85 | public function getCallbackUrl(): ?string 86 | { 87 | return $this->callbackUrl; 88 | } 89 | 90 | public function getStatus(): ?Status 91 | { 92 | return $this->status; 93 | } 94 | 95 | public function getPayload(): ?Payload 96 | { 97 | return $this->payload; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/V5/DTO/Report/Status.php: -------------------------------------------------------------------------------- 1 | ") 35 | */ 36 | private $type; 37 | 38 | public function getErrorId(): string 39 | { 40 | return $this->errorId; 41 | } 42 | 43 | public function getCode(): int 44 | { 45 | return $this->code; 46 | } 47 | 48 | public function getText(): string 49 | { 50 | return $this->text; 51 | } 52 | 53 | public function getType(): ErrorType 54 | { 55 | return $this->type; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/V5/DTO/Shared/ErrorTrait.php: -------------------------------------------------------------------------------- 1 | error; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/V5/DTO/Shared/ErrorType.php: -------------------------------------------------------------------------------- 1 | ") 15 | * 16 | * @var \DateTime 17 | */ 18 | private $timestamp; 19 | 20 | /** 21 | * @return \DateTime 22 | */ 23 | public function getTimestamp(): \DateTime 24 | { 25 | return $this->timestamp; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Helper/AtolApiFactory.php: -------------------------------------------------------------------------------- 1 | setSerializationVisitor( 85 | 'atol_client', 86 | new JsonSerializationVisitorFactory() 87 | ); 88 | 89 | $builder->setDeserializationVisitor( 90 | 'atol_client', 91 | new JsonDeserializationVisitorFactory() 92 | ); 93 | 94 | $builder->configureHandlers(function (HandlerRegistry $handlerRegistry) { 95 | $handlerRegistry->registerSubscribingHandler(new EnumHandler()); 96 | $handlerRegistry->registerSubscribingHandler(new ExtendedDateHandler()); 97 | }); 98 | 99 | return $builder->build(); 100 | } 101 | 102 | private static function createValidator(): ValidatorInterface 103 | { 104 | return Validation::createValidatorBuilder() 105 | ->enableAnnotationMapping() 106 | ->getValidator(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /tests/Helper/ProtectedPropertiesTrait.php: -------------------------------------------------------------------------------- 1 | $value) { 28 | $property = $reflection->getProperty($key); 29 | $property->setAccessible(true); 30 | $property->setValue($object, $value); 31 | } 32 | } 33 | 34 | /** 35 | * Get values of protected properties. 36 | * 37 | * @param $object 38 | * @param array $keys 39 | * 40 | * @return array 41 | */ 42 | protected function getPropertiesValues($object, array $keys) 43 | { 44 | $reflection = new \ReflectionObject($object); 45 | $values = []; 46 | foreach ($keys as $key) { 47 | $property = $reflection->getProperty($key); 48 | $property->setAccessible(true); 49 | $values[$key] = $property->getValue($object); 50 | } 51 | 52 | return $values; 53 | } 54 | 55 | /** 56 | * Assert that object getters must return expected values. 57 | * 58 | * `['value' => 1]` checks `$this->assertSame(1, $object->getValue())` 59 | * 60 | * @param $object 61 | * @param array $expectedValues 62 | * @param array $boolGetters 63 | * @param string $message 64 | */ 65 | protected function assertGettersReturnSameValues($object, array $expectedValues, array $boolGetters = [], $message = '') 66 | { 67 | foreach ($expectedValues as $key => $expected) { 68 | $getter = in_array($key, $boolGetters) ? $key : 'get' . ucfirst($key); 69 | $actual = $object->{$getter}(); 70 | $this->assertSame($expected, $actual, "Incorrect '$key' value: " . $message); 71 | } 72 | } 73 | 74 | /** 75 | * Assert that object getters must return values from protected properties. 76 | * 77 | * @param $object 78 | * @param $values 79 | * @param array $boolGetters 80 | * @param string $message 81 | */ 82 | protected function assertGettersReturnProtectedValues($object, $values, array $boolGetters = [], $message = '') 83 | { 84 | $this->setPropertiesValues($object, $values); 85 | $this->assertGettersReturnSameValues($object, $values, $boolGetters, $message); 86 | } 87 | 88 | protected function assertGettersReturnSettersValues($object, $values, array $boolGetters = [], $message = '') 89 | { 90 | $this->setSettersValues($object, $values); 91 | $this->assertGettersReturnSameValues($object, $values, $boolGetters, $message); 92 | } 93 | 94 | protected function setSettersValues($object, array $values) 95 | { 96 | foreach ($values as $key => $value) { 97 | $setter = 'set' . ucfirst($key); 98 | $object->{$setter}($value); 99 | } 100 | } 101 | 102 | protected function assertSameProperties($object, array $expectedValues) 103 | { 104 | $actualValues = $this->getPropertiesValues($object, array_keys($expectedValues)); 105 | $this->assertSame($expectedValues, $actualValues); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /tests/Integrational/V4/AtolApiTest.php: -------------------------------------------------------------------------------- 1 | login = getenv('ATOL_API_TEST_ATOL_LOGIN'); 32 | $this->password = getenv('ATOL_API_TEST_ATOL_PASSWORD'); 33 | $this->groupCode = getenv('ATOL_API_TEST_ATOL_GROUP_CODE'); 34 | 35 | if ( 36 | empty($this->login) 37 | || empty($this->password) 38 | || empty($this->groupCode) 39 | ) { 40 | $this->markTestSkipped( 41 | 'Envs ATOL_API_TEST_ATOL_LOGIN, ' . 42 | 'ATOL_API_TEST_ATOL_PASSWORD and ' . 43 | 'ATOL_API_TEST_ATOL_GROUP_CODE must be defined' 44 | ); 45 | } 46 | } 47 | 48 | protected function createApi(): AtolApi 49 | { 50 | $client = new Client(); 51 | 52 | return AtolApiFactory::createV4($client, [], 'https://testonline.atol.ru/possystem/'); 53 | } 54 | 55 | protected function getLogin(): string 56 | { 57 | return $this->login; 58 | } 59 | 60 | protected function getPassword(): string 61 | { 62 | return $this->password; 63 | } 64 | 65 | protected function getGroupCode(): string 66 | { 67 | return $this->groupCode; 68 | } 69 | 70 | protected function setUpTestGetToken(): void 71 | { 72 | // nothing 73 | } 74 | 75 | protected function setUpTestGetTokenWithInvalidCredentials(): void 76 | { 77 | // nothing 78 | } 79 | 80 | protected function setUpTestSell(): void 81 | { 82 | // nothing 83 | } 84 | 85 | protected function setUpTestSellCorrection(): void 86 | { 87 | // nothing 88 | } 89 | 90 | protected function setUpTestSellWithInvalidRequest(): void 91 | { 92 | // nothing 93 | } 94 | 95 | protected function setUpTestSellCorrectionWithInvalidRequest(): void 96 | { 97 | // nothing 98 | } 99 | 100 | protected function setUpTestSellRefund(): void 101 | { 102 | // nothing 103 | } 104 | 105 | protected function setUpTestSellRefundWithInvalidRequest(): void 106 | { 107 | // nothing 108 | } 109 | 110 | protected function setUpTestReport(): void 111 | { 112 | // nothing 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /tests/Integrational/V5/AtolApiTest.php: -------------------------------------------------------------------------------- 1 | login = getenv('ATOL_API_V5_TEST_LOGIN'); 34 | $this->password = getenv('ATOL_API_V5_TEST_PASSWORD'); 35 | $this->groupCode = getenv('ATOL_API_V5_TEST_GROUP_CODE'); 36 | 37 | if ( 38 | empty($this->login) 39 | || empty($this->password) 40 | || empty($this->groupCode) 41 | ) { 42 | $this->markTestSkipped( 43 | 'Envs ATOL_API_V5_TEST_LOGIN, ' . 44 | 'ATOL_API_V5_TEST_PASSWORD and ' . 45 | 'ATOL_API_V5_TEST_GROUP_CODE must be defined' 46 | ); 47 | } 48 | } 49 | 50 | protected function createApi(): AtolApi 51 | { 52 | $client = new Client(); 53 | 54 | return AtolApiFactory::createV5($client, [], 'https://testonline.atol.ru/possystem/'); 55 | } 56 | 57 | protected function getLogin(): string 58 | { 59 | return $this->login; 60 | } 61 | 62 | protected function getPassword(): string 63 | { 64 | return $this->password; 65 | } 66 | 67 | protected function getGroupCode(): string 68 | { 69 | return $this->groupCode; 70 | } 71 | 72 | protected function setUpTestGetToken(): void 73 | { 74 | // nothing 75 | } 76 | 77 | protected function setUpTestGetTokenWithInvalidCredentials(): void 78 | { 79 | // nothing 80 | } 81 | 82 | protected function setUpTestSell(): void 83 | { 84 | // nothing 85 | } 86 | 87 | protected function setUpTestSellWithInvalidRequest(): void 88 | { 89 | // nothing 90 | } 91 | 92 | protected function setUpTestSellCorrection(): void 93 | { 94 | // nothing 95 | } 96 | 97 | protected function setUpTestSellCorrectionWithInvalidRequest(): void 98 | { 99 | // nothing 100 | } 101 | 102 | protected function setUpTestSellRefund(): void 103 | { 104 | // nothing 105 | } 106 | 107 | protected function setUpTestSellRefundWithInvalidRequest(): void 108 | { 109 | // nothing 110 | } 111 | 112 | protected function setUpTestReport(): void 113 | { 114 | // nothing 115 | } 116 | 117 | protected function setUpTestSellRefundCorrection(): void 118 | { 119 | // nothing 120 | } 121 | 122 | protected function setUpTestSellRefundCorrectionWithInvalidRequest(): void 123 | { 124 | // nothing 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /tests/Unit/Converter/ObjectConverterTest.php: -------------------------------------------------------------------------------- 1 | serializer = $this->createMock(SerializerInterface::class); 39 | $this->validator = $this->createMock(ValidatorInterface::class); 40 | $this->objectConverter = new ObjectConverter($this->serializer, $this->validator); 41 | } 42 | 43 | public function testGetRequestString() 44 | { 45 | $object = (object) []; 46 | $json = '{}'; 47 | 48 | /* @see ObjectConverter::assertValid() */ 49 | $this->validator 50 | ->expects($this->once()) 51 | ->method('validate') 52 | ->with($object) 53 | ->willReturn([]); 54 | 55 | /* @see ObjectConverter::serializeBodyObject() */ 56 | $this->serializer 57 | ->expects($this->once()) 58 | ->method('serialize') 59 | ->with($object, 'atol_client', $this->anything()) 60 | ->willReturn($json); 61 | 62 | $result = $this->objectConverter->getRequestString($object); 63 | $this->assertSame($json, $result); 64 | } 65 | 66 | /** 67 | * @expectedException \Lamoda\AtolClient\Exception\ParseException 68 | */ 69 | public function testGetRequestStringParseException() 70 | { 71 | /* @see ObjectConverter::assertValid() */ 72 | $this->validator 73 | ->method('validate') 74 | ->willReturn([]); 75 | 76 | /* @see ObjectConverter::serializeBodyObject() */ 77 | $this->serializer 78 | ->expects($this->once()) 79 | ->method('serialize') 80 | ->willThrowException(new \RuntimeException()); 81 | 82 | $this->objectConverter->getRequestString((object) []); 83 | } 84 | 85 | /** 86 | * @expectedException \Lamoda\AtolClient\Exception\ValidationException 87 | * @expectedExceptionCode 2 88 | */ 89 | public function testGetRequestStringInvalid() 90 | { 91 | $object = (object) []; 92 | $errors = $this->createMock(ConstraintViolationListInterface::class); 93 | 94 | /* @see ObjectConverter::assertValid() */ 95 | $this->validator 96 | ->expects($this->once()) 97 | ->method('validate') 98 | ->with($object) 99 | ->willReturn($errors); 100 | $errors 101 | ->expects($this->once()) 102 | ->method('count') 103 | ->willReturn(1); 104 | 105 | $this->objectConverter->getRequestString($object); 106 | } 107 | 108 | public function testGetResponseObject() 109 | { 110 | $class = 'class'; 111 | $json = 'json'; 112 | $object = (object) []; 113 | 114 | /* @see ObjectConverter::deserialize() */ 115 | $this->serializer 116 | ->expects($this->once()) 117 | ->method('deserialize') 118 | ->with($json, $class, 'atol_client') 119 | ->willReturn($object); 120 | /* @see ObjectConverter::assertValid() */ 121 | $this->validator 122 | ->expects($this->once()) 123 | ->method('validate') 124 | ->with($object) 125 | ->willReturn([]); 126 | 127 | $result = $this->objectConverter->getResponseObject($class, $json); 128 | $this->assertSame($object, $result); 129 | } 130 | 131 | /** 132 | * @expectedException \Lamoda\AtolClient\Exception\ParseException 133 | * @expectedExceptionCode 2 134 | */ 135 | public function testGetResponseObjectParseException() 136 | { 137 | /* @see ObjectConverter::deserialize() */ 138 | $this->serializer 139 | ->method('deserialize') 140 | ->willThrowException(new \RuntimeException()); 141 | 142 | $this->objectConverter->getResponseObject('class', 'json'); 143 | } 144 | 145 | /** 146 | * @expectedException \Lamoda\AtolClient\Exception\ValidationException 147 | * @expectedExceptionCode 2 148 | */ 149 | public function testGetResponseObjectInvalid() 150 | { 151 | $errors = $this->createMock(ConstraintViolationListInterface::class); 152 | 153 | /* @see ObjectConverter::assertValid() */ 154 | $this->serializer 155 | ->method('deserialize') 156 | ->willReturn((object) []); 157 | $this->validator 158 | ->method('validate') 159 | ->willReturn($errors); 160 | $errors 161 | ->expects($this->once()) 162 | ->method('count') 163 | ->willReturn(1); 164 | 165 | $this->objectConverter->getResponseObject('class', 'json'); 166 | } 167 | } 168 | -------------------------------------------------------------------------------- /tests/Unit/Exception/AtolErrorExceptionTest.php: -------------------------------------------------------------------------------- 1 | createMock(Error::class); 18 | $type = 'type'; 19 | 20 | $error 21 | ->expects($this->once()) 22 | ->method('getCode') 23 | ->willReturn($this->createMock(Error\ErrorCode::class)); 24 | $error 25 | ->expects($this->once()) 26 | ->method('getType') 27 | ->willReturn($type); 28 | 29 | $exception = AtolErrorException::becauseOfAtolError($error); 30 | $this->assertInstanceOf(AtolErrorException::class, $exception); 31 | $this->assertSame($type, $exception->getType()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /tests/Unit/Exception/ParseExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(ParseException::class, $exception); 20 | $this->assertSame($code, $exception->getCode()); 21 | $this->assertSame($previous, $exception->getPrevious()); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/Unit/Exception/TokenExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(TokenException::class, $exception); 20 | $this->assertSame($other->getCode(), $exception->getCode()); 21 | $this->assertSame($other, $exception->getPrevious()); 22 | $this->assertSame($other->getMessage(), $exception->getMessage()); 23 | } 24 | 25 | public function testBecauseOfAtolError() 26 | { 27 | $error = $this->createMock(Error::class); 28 | $error 29 | ->expects($this->once()) 30 | ->method('getCode') 31 | ->willReturn($this->createMock(Error\ErrorCode::class)); 32 | $exception = TokenException::becauseOfAtolError($error); 33 | $this->assertInstanceOf(TokenException::class, $exception); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/Unit/Exception/UnknownStatusExceptionTest.php: -------------------------------------------------------------------------------- 1 | createMock(ConstraintViolationInterface::class); 21 | $errors = new ConstraintViolationList([$error]); 22 | 23 | $error 24 | ->expects($this->once()) 25 | ->method('getMessage') 26 | ->willReturn($reasonMessage); 27 | 28 | $exception = ValidationException::becauseOfValidationErrors($errors, $code); 29 | $this->assertInstanceOf(ValidationException::class, $exception); 30 | $this->assertContains($reasonMessage, $exception->getMessage()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Unit/Exception/VatExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf(VatException::class, $exception); 19 | $this->assertContains((string) $type, $exception->getMessage()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/General/Error/ErrorCodeTest.php: -------------------------------------------------------------------------------- 1 | assertSame($value, (new ErrorCode($value))->getNumber()); 21 | } 22 | 23 | /** 24 | * @param int $value 25 | * @param bool $isTokenSuccess 26 | * @dataProvider dataAll 27 | */ 28 | public function testIsTokenSuccess(int $value, bool $isTokenSuccess) 29 | { 30 | $this->assertSame($isTokenSuccess, (new ErrorCode($value))->isTokenSuccess()); 31 | } 32 | 33 | /** 34 | * @param int $value 35 | * @param bool $isTokenSuccess 36 | * @param bool $isTokenError 37 | * @dataProvider dataAll 38 | */ 39 | public function testIsTokenError(int $value, bool $isTokenSuccess, bool $isTokenError) 40 | { 41 | $this->assertSame($isTokenError, (new ErrorCode($value))->isTokenError()); 42 | $this->assertSame($isTokenSuccess, (new ErrorCode($value))->isTokenSuccess()); 43 | } 44 | 45 | public function dataAll() 46 | { 47 | return [ 48 | [ErrorCode::NEW_TOKEN, true, false], 49 | [ErrorCode::STATE_MISSING_TOKEN, false, true], 50 | [ErrorCode::STATE_NOT_FOUND, false, false], 51 | [-100500, false, false], 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/General/ErrorTest.php: -------------------------------------------------------------------------------- 1 | assertGettersReturnProtectedValues($error, $values); 27 | $this->setPropertiesValues($error, ['code' => $propertyCode]); 28 | $this->assertEquals($codeFromGetter, $error->getCode()); 29 | } 30 | 31 | public function dataGetters() 32 | { 33 | return [ 34 | 'fill' => [ 35 | [ 36 | 'text' => 'text', 37 | 'type' => 'type', 38 | ], 39 | 1, 40 | new Error\ErrorCode(1), 41 | ], 42 | 'empty' => [ 43 | [ 44 | 'text' => null, 45 | 'type' => null, 46 | ], 47 | 2, 48 | new Error\ErrorCode(2), 49 | ], 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/GetTokenResponseTest.php: -------------------------------------------------------------------------------- 1 | assertGettersReturnProtectedValues($object, $values); 28 | $this->setPropertiesValues($object, ['code' => $codeInProperty]); 29 | $this->assertEquals($codeFromGetter, $object->getCode()); 30 | } 31 | 32 | public function dataGetters() 33 | { 34 | $values = [ 35 | 'text' => 'text', 36 | 'token' => 'token', 37 | ]; 38 | 39 | return [ 40 | 'default' => [$values, 1, new Error\ErrorCode(1)], 41 | ]; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Report/Response/PayloadTest.php: -------------------------------------------------------------------------------- 1 | assertGettersReturnProtectedValues( 24 | new Payload( 25 | $values['total'], 26 | $values['fnNumber'], 27 | $values['shiftNumber'], 28 | $values['receiptDatetime'], 29 | $values['fiscalReceiptNumber'], 30 | $values['fiscalDocumentNumber'], 31 | $values['ecrRegistrationNumber'], 32 | $values['fiscalDocumentAttribute'] 33 | ), 34 | $values 35 | ); 36 | } 37 | 38 | public function dataGetters() 39 | { 40 | return [ 41 | 'fill' => [ 42 | [ 43 | 'total' => 123, 44 | 'fnNumber' => 'number', 45 | 'shiftNumber' => 234, 46 | 'receiptDatetime' => new \DateTime(), 47 | 'fiscalReceiptNumber' => 345, 48 | 'fiscalDocumentNumber' => 456, 49 | 'ecrRegistrationNumber' => 'reg', 50 | 'fiscalDocumentAttribute' => 567, 51 | ], 52 | ], 53 | ]; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/ReportResponseTest.php: -------------------------------------------------------------------------------- 1 | assertGettersReturnProtectedValues(new ReportResponse(), $values); 27 | } 28 | 29 | public function dataGetters() 30 | { 31 | $values = [ 32 | 'uuid' => 'uuid', 33 | 'status' => new Status(Status::FAIL), 34 | 'timestamp' => new \DateTime(), 35 | 'error' => $this->createMock(Error::class), 36 | 'payload' => $this->createMock(Payload::class), 37 | 'callbackUrl' => 'url', 38 | ]; 39 | 40 | return [ 41 | 'default' => [$values], 42 | 'no_error' => [array_replace($values, [ 43 | 'error' => null, 44 | ])], 45 | ]; 46 | } 47 | 48 | public static function assertSame($expected, $actual, string $message = ''): void 49 | { 50 | parent::assertEquals($expected, $actual, $message = ''); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/Receipt/AttributesTest.php: -------------------------------------------------------------------------------- 1 | assertSameProperties($attributes, $values); 26 | $valuesWithGetters = array_intersect_key($values, array_flip($this->propertiesWithGetters)); 27 | $this->assertGettersReturnSameValues($attributes, $valuesWithGetters); 28 | } 29 | 30 | public function dataGetters() 31 | { 32 | return [ 33 | 'fill' => [ 34 | [ 35 | 'email' => 'email', 36 | 'phone' => 'phone', 37 | 'sno' => new Attributes\TaxSystem(Attributes\TaxSystem::OSN), 38 | ], 39 | ], 40 | 'null' => [ 41 | [ 42 | 'email' => null, 43 | 'phone' => null, 44 | 'sno' => null, 45 | ], 46 | ], 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/Receipt/ItemTest.php: -------------------------------------------------------------------------------- 1 | assertSame($values['name'], $attributes->getName()); 34 | $this->assertSame($values['price'], $attributes->getPrice()); 35 | $this->assertSame($values['quantity'], $attributes->getQuantity()); 36 | $this->assertSame($values['sum'], $attributes->getSum()); 37 | $this->assertSame($values['tax'], $attributes->getTax()); 38 | $this->assertSame($values['taxsum'], $attributes->getTaxsum()); 39 | } 40 | 41 | public function dataGetters() 42 | { 43 | return [ 44 | 'fill' => [ 45 | [ 46 | 'name' => 'name', 47 | 'price' => 123.45, 48 | 'quantity' => 234.56, 49 | 'sum' => 345.67, 50 | 'tax' => new Tax(Tax::VAT10), 51 | 'taxsum' => 456.78, 52 | ], 53 | ], 54 | ]; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/Receipt/PaymentTest.php: -------------------------------------------------------------------------------- 1 | assertSameProperties($attributes, $values); 25 | } 26 | 27 | public function dataGetters() 28 | { 29 | return [ 30 | 'fill' => [ 31 | [ 32 | 'sum' => 123.45, 33 | 'type' => new Payment\PaymentType(Payment\PaymentType::EXTENDED_A), 34 | ], 35 | ], 36 | ]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/Receipt/TaxTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($taxValue, $tax->getValue()); 28 | } 29 | 30 | public function dataFromInteger(): array 31 | { 32 | return [ 33 | [null, Tax::NONE], 34 | [0, Tax::VAT0], 35 | [10, Tax::VAT110], 36 | [18, Tax::VAT118], 37 | ]; 38 | } 39 | 40 | /** 41 | * @param int $integer 42 | * 43 | * @dataProvider dataFromIntegerException 44 | * @expectedException \Lamoda\AtolClient\Exception\VatException 45 | */ 46 | public function testFromIntegerException($integer): void 47 | { 48 | Tax::fromInteger($integer); 49 | } 50 | 51 | public function dataFromIntegerException(): array 52 | { 53 | return [ 54 | [110], 55 | [118], 56 | [92], 57 | ]; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/ReceiptTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($items, $receipt->getItems()); 30 | $this->assertEquals($total, $receipt->getTotal()); 31 | $this->assertEquals($payments, $receipt->getPayments()); 32 | $this->assertEquals($attributes, $receipt->getAttributes()); 33 | } 34 | 35 | /** 36 | * @return array 37 | */ 38 | public function dataProvider() 39 | { 40 | return [ 41 | [ 42 | [$this->createMock(Item::class)], 43 | 0.0, 44 | [$this->createMock(Payment::class)], 45 | $this->createMock(Attributes::class), 46 | ], 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/Sell/Request/ServiceTest.php: -------------------------------------------------------------------------------- 1 | assertSameProperties( 24 | new Service($values['inn'], $values['paymentAddress'], $values['callbackUrl']), 25 | $values 26 | ); 27 | } 28 | 29 | public function dataGetters() 30 | { 31 | return [ 32 | 'fill' => [ 33 | [ 34 | 'inn' => 'inn', 35 | 'paymentAddress' => 'paymentAddress', 36 | 'callbackUrl' => 'callbackUrl', 37 | ], 38 | ], 39 | 'null' => [ 40 | [ 41 | 'inn' => null, 42 | 'paymentAddress' => null, 43 | 'callbackUrl' => null, 44 | ], 45 | ], 46 | ]; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/SellRequestTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($service, $request->getService()); 41 | $this->assertEquals($receipt, $request->getReceipt()); 42 | $this->assertEquals($token, $request->getToken()); 43 | $this->assertEquals($externalId, $request->getExternalId()); 44 | $this->assertEquals($timestamp, $request->getTimestamp()); 45 | } 46 | 47 | /** 48 | * @return array 49 | */ 50 | public function dataProvider() 51 | { 52 | return [ 53 | [ 54 | $this->createMock(Service::class), 55 | $this->createMock(Receipt::class), 56 | 'token', 57 | 'externalId', 58 | new \DateTime(), 59 | ], 60 | ]; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Unit/V3/DTO/SellResponseTest.php: -------------------------------------------------------------------------------- 1 | assertGettersReturnProtectedValues(new SellResponse(), $values); 26 | } 27 | 28 | public function dataGetters() 29 | { 30 | $values = [ 31 | 'uuid' => 'uuid', 32 | 'status' => new Status(Status::FAIL), 33 | 'timestamp' => new \DateTime(), 34 | 'error' => $this->createMock(Error::class), 35 | ]; 36 | 37 | return [ 38 | 'default' => [$values], 39 | 'no_error' => [array_replace($values, [ 40 | 'error' => null, 41 | ])], 42 | 'no_uuid' => [array_replace($values, [ 43 | 'uuid' => null, 44 | ])], 45 | ]; 46 | } 47 | 48 | public static function assertSame($expected, $actual, string $message = ''): void 49 | { 50 | parent::assertEquals($expected, $actual, $message = ''); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Unit/V3/Validator/EmailOrPhoneTest.php: -------------------------------------------------------------------------------- 1 | assertSame($constraint->getTargets(), EmailOrPhone::CLASS_CONSTRAINT); 18 | $this->assertInternalType('string', $constraint->message); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Unit/V3/Validator/EmailOrPhoneValidatorTest.php: -------------------------------------------------------------------------------- 1 | mockContext(); 22 | $constraint = $this->mockConstraint(); 23 | $violation = $this->createMock(ConstraintViolationBuilderInterface::class); 24 | $constraint->method('__get')->with('message')->willReturn('123'); 25 | 26 | $context 27 | ->expects($this->once()) 28 | ->method('buildViolation') 29 | ->with($constraint->message) 30 | ->willReturn($violation); 31 | $violation 32 | ->expects($this->once()) 33 | ->method('atPath') 34 | ->willReturnSelf(); 35 | $violation 36 | ->expects($this->once()) 37 | ->method('addViolation'); 38 | 39 | $validator = new EmailOrPhoneValidator(); 40 | $validator->initialize($context); 41 | $validator->validate($this->mockAttributes(), $constraint); 42 | } 43 | 44 | /** 45 | * @dataProvider dataInvalid 46 | */ 47 | public function testValid(string $method) 48 | { 49 | $attributes = $this->mockAttributes(); 50 | $context = $this->mockContext(); 51 | 52 | $attributes 53 | ->expects($this->once()) 54 | ->method($method) 55 | ->willReturn('not false'); 56 | $context 57 | ->expects($this->never()) 58 | ->method('buildViolation'); 59 | 60 | $validator = new EmailOrPhoneValidator(); 61 | $validator->initialize($context); 62 | $validator->validate($attributes, $this->mockConstraint()); 63 | } 64 | 65 | public function dataInvalid() 66 | { 67 | return [ 68 | ['getEmail'], 69 | ['getPhone'], 70 | ]; 71 | } 72 | 73 | /** 74 | * @return Attributes|MockObject 75 | */ 76 | private function mockAttributes() 77 | { 78 | return $this->createMock(Attributes::class); 79 | } 80 | 81 | /** 82 | * @return MockObject|ExecutionContextInterface 83 | */ 84 | private function mockContext() 85 | { 86 | return $this->createMock(ExecutionContextInterface::class); 87 | } 88 | 89 | /** 90 | * @return MockObject|Constraint 91 | */ 92 | private function mockConstraint() 93 | { 94 | return $this->createMock(Constraint::class); 95 | } 96 | } 97 | --------------------------------------------------------------------------------