├── .editorconfig ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .scrutinizer.yml ├── .travis.yml ├── LICENSE ├── README.md ├── bootstrap.php ├── composer.json ├── phpunit.xml.dist ├── src ├── Exception │ ├── IsmpClientExceptionInterface.php │ ├── IsmpGeneralErrorException.php │ ├── IsmpRequestErrorException.php │ └── IsmpSerializerErrorException.php ├── Impl │ └── Serializer │ │ ├── SymfonySerializerAdapter.php │ │ ├── SymfonySerializerAdapterFactory.php │ │ ├── V3 │ │ ├── FacadeCisListResponseDenormalizer.php │ │ └── FacadeDocBodyResponseBodyDenormalizer.php │ │ └── V4 │ │ ├── FacadeCisListResponseDenormalizer.php │ │ └── FacadeDocBodyResponseBodyDenormalizer.php ├── Serializer │ └── SerializerInterface.php ├── V3 │ ├── Dto │ │ ├── AuthCertKeyResponse.php │ │ ├── AuthCertRequest.php │ │ ├── AuthCertResponse.php │ │ ├── DocumentCreateRequest.php │ │ ├── FacadeCisItemResponse.php │ │ ├── FacadeCisListRequest.php │ │ ├── FacadeCisListResponse.php │ │ ├── FacadeDocBodyResponse.php │ │ ├── FacadeDocBodyResponse │ │ │ ├── Body.php │ │ │ └── Body │ │ │ │ ├── DocumentDescription.php │ │ │ │ └── Products │ │ │ │ └── Product.php │ │ ├── FacadeDocListV2ItemResponse.php │ │ ├── FacadeDocListV2Query.php │ │ ├── FacadeDocListV2Response.php │ │ ├── FacadeMarkedProductsCertDoc.php │ │ ├── FacadeMarkedProductsResponse.php │ │ ├── FacadeOrderDetailsResponse.php │ │ ├── FacadeOrderRequest.php │ │ ├── FacadeOrderResponse.php │ │ └── ProductInfoResponse.php │ ├── Enum │ │ ├── DocumentLkType.php │ │ └── ProductGroup.php │ ├── IsmpApi.php │ └── IsmpApiInterface.php └── V4 │ ├── Dto │ ├── FacadeCisItemResponse.php │ ├── FacadeCisListRequest.php │ ├── FacadeCisListResponse.php │ ├── FacadeDocBodyResponse.php │ └── FacadeDocBodyResponse │ │ ├── Body.php │ │ └── Body │ │ ├── DocumentDescription.php │ │ └── Products │ │ └── Product.php │ ├── IsmpApi.php │ └── IsmpApiInterface.php └── tests ├── Impl └── Serializer │ ├── V3 │ ├── FacadeCisListResponseDenormalizerTest.php │ ├── FacadeDocBodyResponseBodyDenormalizerTest.php │ └── SymfonySerializerAdapterTest.php │ └── V4 │ ├── FacadeCisListResponseDenormalizerTest.php │ ├── FacadeDocBodyResponseBodyDenormalizerTest.php │ └── SymfonySerializerAdapterTest.php ├── Stub └── SerializerDenormalizer.php ├── V3 ├── Dto │ ├── FacadeDocListV2ItemResponseTest.php │ └── FacadeDocListV2QueryTest.php └── IsmpApiTest.php └── V4 └── IsmpApiTest.php /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | insert_final_newline = true 6 | charset = utf-8 7 | indent_style = space 8 | indent_size = 4 9 | 10 | [*.{yml,yaml}] 11 | indent_size = 2 12 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | tags: 7 | pull_request: 8 | 9 | env: 10 | DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-ansi --no-progress --no-suggest" 11 | 12 | jobs: 13 | build: 14 | runs-on: ${{ matrix.os }} 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | php: [7.2, 7.3, 7.4] 19 | os: [ubuntu-latest] 20 | env: [ 21 | 'low', 22 | 'high', 23 | ] 24 | name: PHP ${{ matrix.php }} Test ${{ matrix.env }} on ${{ matrix.os }} 25 | 26 | steps: 27 | - name: Checkout code 28 | uses: actions/checkout@v2 29 | 30 | - name: Install PHP 31 | uses: shivammathur/setup-php@v2 32 | with: 33 | php-version: ${{ matrix.php }} 34 | extensions: json, mbstring 35 | 36 | - name: Get Composer Cache Directory 37 | id: composer-cache 38 | run: echo "::set-output name=dir::$(composer config cache-files-dir)" 39 | 40 | - name: Cache dependencies 41 | uses: actions/cache@v1 42 | with: 43 | path: ${{ steps.composer-cache.outputs.dir }} 44 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} 45 | restore-keys: ${{ runner.os }}-composer- 46 | 47 | - name: Composer update with high level 48 | run: | 49 | if [ "$DEPENDENCIES" = 'high' ]; then 50 | composer update $DEFAULT_COMPOSER_FLAGS 51 | fi; 52 | 53 | if [ "$DEPENDENCIES" = 'low' ]; then 54 | composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest 55 | fi; 56 | env: 57 | DEPENDENCIES: ${{ matrix.env}} 58 | - name: Run tests 59 | run: ./vendor/bin/phpunit 60 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | /phpunit.xml 3 | /.php_cs 4 | /.php_cs.cache 5 | /composer.lock 6 | .DS_Store 7 | build/ 8 | .idea/ 9 | .phpunit.result.cache 10 | -------------------------------------------------------------------------------- /.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" 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 7.2 5 | - 7.3 6 | - 7.4snapshot 7 | - nightly 8 | env: 9 | matrix: 10 | - DEPENDENCIES=high 11 | - DEPENDENCIES=low 12 | global: 13 | - DEFAULT_COMPOSER_FLAGS="--prefer-dist --no-interaction --no-ansi --no-progress --no-suggest" 14 | sudo: false 15 | 16 | matrix: 17 | fast_finish: true 18 | allow_failures: 19 | - php: nightly 20 | - php: 7.4snapshot 21 | 22 | before_install: 23 | - travis_retry composer self-update 24 | 25 | install: 26 | - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi 27 | - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi 28 | -------------------------------------------------------------------------------- /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 | Lamoda CRPT ISMP Api Client 2 | ========================== 3 | 4 | [![Build Status](https://travis-ci.org/lamoda/crpt-ismp-api-client.svg?branch=master)](https://travis-ci.org/lamoda/crpt-ismp-api-client) 5 | [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/?branch=master) 6 | [![Code Coverage](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/?branch=master) 7 | [![Build Status](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/badges/build.png?b=master)](https://scrutinizer-ci.com/g/lamoda/crpt-ismp-api-client/build-status/master) 8 | [![Build Status](https://github.com/lamoda/crpt-ismp-api-client/workflows/CI/badge.svg?branch=master)](https://github.com/lamoda/crpt-ismp-api-client/workflows/CI/badge.svg?branch=master) 9 | 10 | ## Installation 11 | 12 | ### Composer 13 | 14 | ```sh 15 | composer require lamoda/crpt-ismp-api-client 16 | ``` 17 | 18 | ## Description 19 | 20 | This library implements API client for the Labeling and Traceability Information System 21 | (or "Информационная система маркировки и прослеживаемости" in Russian, ISMP) of the CRPT (https://markirovka.crpt.ru) 22 | 23 | Library implements V3 and V4 version of ISMP Api's 24 | 25 | Currently this client implements just a subset of the ISMP Api methods. 26 | 27 | ## Usage 28 | 29 | ```php 30 | 'http://ismp_uri', 39 | 'timeout' => 2.0, 40 | ]); 41 | 42 | $serializer = SymfonySerializerAdapterFactory::create(); 43 | 44 | $api = new IsmpApi($client, $serializer); 45 | 46 | // Call api methods... 47 | 48 | ``` 49 | -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | tests 21 | 22 | 23 | 24 | 25 | 26 | src 27 | 28 | ./vendor/ 29 | ./tests/ 30 | ./src/V3/Dto 31 | ./src/Exception 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /src/Exception/IsmpClientExceptionInterface.php: -------------------------------------------------------------------------------- 1 | getMessage() 14 | ), 0, $exception); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Exception/IsmpRequestErrorException.php: -------------------------------------------------------------------------------- 1 | getMessage() 23 | ), 0, $exception); 24 | 25 | $self->responseCode = $responseCode; 26 | $self->response = $response; 27 | 28 | return $self; 29 | } 30 | 31 | public function getResponse(): string 32 | { 33 | return $this->response; 34 | } 35 | 36 | public function getResponseCode(): int 37 | { 38 | return $this->responseCode; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Exception/IsmpSerializerErrorException.php: -------------------------------------------------------------------------------- 1 | getMessage() 14 | ), 0, $exception); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Impl/Serializer/SymfonySerializerAdapter.php: -------------------------------------------------------------------------------- 1 | serializer = $serializer; 21 | } 22 | 23 | public function serialize(object $object) 24 | { 25 | try { 26 | return $this->serializer->serialize($object, 'json'); 27 | } catch (\Throwable $throwable) { 28 | throw IsmpSerializerErrorException::becauseOfError($throwable); 29 | } 30 | } 31 | 32 | public function deserialize(string $class, $data): object 33 | { 34 | try { 35 | return $this->serializer->deserialize( 36 | $data, 37 | $class, 38 | 'json', 39 | ['disable_type_enforcement' => true] 40 | ); 41 | } catch (\Throwable $throwable) { 42 | throw IsmpSerializerErrorException::becauseOfError($throwable); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Impl/Serializer/SymfonySerializerAdapterFactory.php: -------------------------------------------------------------------------------- 1 | denormalizer) { 32 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); 33 | } 34 | if (!\is_array($data)) { 35 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); 36 | } 37 | if (FacadeCisListResponse::class !== $class) { 38 | throw new InvalidArgumentException('Unsupported class: ' . $class); 39 | } 40 | 41 | $items = []; 42 | foreach ($data as $datum) { 43 | $items[] = $this->denormalizer->denormalize($datum, FacadeCisItemResponse::class, $format, $context); 44 | } 45 | 46 | return new FacadeCisListResponse(...$items); 47 | } 48 | 49 | /** 50 | * {@inheritdoc} 51 | */ 52 | public function supportsDenormalization($data, $type, $format = null, array $context = []): bool 53 | { 54 | return FacadeCisListResponse::class === $type; 55 | } 56 | 57 | /** 58 | * {@inheritdoc} 59 | */ 60 | public function setDenormalizer(DenormalizerInterface $denormalizer) 61 | { 62 | $this->denormalizer = $denormalizer; 63 | } 64 | 65 | /** 66 | * {@inheritdoc} 67 | */ 68 | public function hasCacheableSupportsMethod(): bool 69 | { 70 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Impl/Serializer/V3/FacadeDocBodyResponseBodyDenormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer) { 31 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); 32 | } 33 | if (!\is_array($data)) { 34 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); 35 | } 36 | if (Body::class !== $class) { 37 | throw new InvalidArgumentException('Unsupported class: ' . $class); 38 | } 39 | 40 | $data[self::ORIGINAL_STRING_FIELD_KEY] = $this->denormalizer->serialize($data, $format, $context); 41 | 42 | return $this->denormalizer->denormalize($data, $class, $format, $context); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function supportsDenormalization($data, $type, $format = null, array $context = []): bool 49 | { 50 | return Body::class === $type 51 | && is_array($data) 52 | && !array_key_exists(self::ORIGINAL_STRING_FIELD_KEY, $data); 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function setDenormalizer(DenormalizerInterface $denormalizer): void 59 | { 60 | if (!$denormalizer instanceof SerializerInterface) { 61 | throw new InvalidArgumentException('Denormalizer must implement serializer interface also'); 62 | } 63 | 64 | $this->denormalizer = $denormalizer; 65 | } 66 | 67 | /** 68 | * {@inheritdoc} 69 | */ 70 | public function hasCacheableSupportsMethod(): bool 71 | { 72 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Impl/Serializer/V4/FacadeCisListResponseDenormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer) { 32 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); 33 | } 34 | if (!\is_array($data)) { 35 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); 36 | } 37 | if (FacadeCisListResponse::class !== $class) { 38 | throw new InvalidArgumentException('Unsupported class: ' . $class); 39 | } 40 | 41 | $items = []; 42 | foreach ($data as $datum) { 43 | $items[] = $this->denormalizer->denormalize($datum, FacadeCisItemResponse::class, $format, $context); 44 | } 45 | 46 | return new FacadeCisListResponse(...$items); 47 | } 48 | 49 | /** 50 | * {@inheritdoc} 51 | */ 52 | public function supportsDenormalization($data, $type, $format = null, array $context = []): bool 53 | { 54 | return FacadeCisListResponse::class === $type; 55 | } 56 | 57 | /** 58 | * {@inheritdoc} 59 | */ 60 | public function setDenormalizer(DenormalizerInterface $denormalizer) 61 | { 62 | $this->denormalizer = $denormalizer; 63 | } 64 | 65 | /** 66 | * {@inheritdoc} 67 | */ 68 | public function hasCacheableSupportsMethod(): bool 69 | { 70 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Impl/Serializer/V4/FacadeDocBodyResponseBodyDenormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer) { 31 | throw new BadMethodCallException('Please set a serializer before calling denormalize()!'); 32 | } 33 | if (!\is_array($data)) { 34 | throw new InvalidArgumentException('Data expected to be an array, ' . \gettype($data) . ' given.'); 35 | } 36 | if (Body::class !== $class) { 37 | throw new InvalidArgumentException('Unsupported class: ' . $class); 38 | } 39 | 40 | $data[self::ORIGINAL_STRING_FIELD_KEY] = $this->denormalizer->serialize($data, $format, $context); 41 | 42 | return $this->denormalizer->denormalize($data, $class, $format, $context); 43 | } 44 | 45 | /** 46 | * {@inheritdoc} 47 | */ 48 | public function supportsDenormalization($data, $type, $format = null, array $context = []): bool 49 | { 50 | return Body::class === $type 51 | && is_array($data) 52 | && !array_key_exists(self::ORIGINAL_STRING_FIELD_KEY, $data); 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function setDenormalizer(DenormalizerInterface $denormalizer): void 59 | { 60 | if (!$denormalizer instanceof SerializerInterface) { 61 | throw new InvalidArgumentException('Denormalizer must implement serializer interface also'); 62 | } 63 | 64 | $this->denormalizer = $denormalizer; 65 | } 66 | 67 | /** 68 | * {@inheritdoc} 69 | */ 70 | public function hasCacheableSupportsMethod(): bool 71 | { 72 | return $this->denormalizer instanceof CacheableSupportsMethodInterface && $this->denormalizer->hasCacheableSupportsMethod(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/Serializer/SerializerInterface.php: -------------------------------------------------------------------------------- 1 | uuid = $uuid; 25 | $this->data = $data; 26 | } 27 | 28 | public function getUuid(): string 29 | { 30 | return $this->uuid; 31 | } 32 | 33 | public function getData(): string 34 | { 35 | return $this->data; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/V3/Dto/AuthCertRequest.php: -------------------------------------------------------------------------------- 1 | uuid = $uuid; 21 | $this->data = $data; 22 | } 23 | 24 | public function getUuid(): string 25 | { 26 | return $this->uuid; 27 | } 28 | 29 | public function getData(): string 30 | { 31 | return $this->data; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/V3/Dto/AuthCertResponse.php: -------------------------------------------------------------------------------- 1 | token = $token; 20 | } 21 | 22 | public function getToken(): string 23 | { 24 | return $this->token; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/V3/Dto/DocumentCreateRequest.php: -------------------------------------------------------------------------------- 1 | productDocument = $productDocument; 38 | $this->documentFormat = $documentFormat; 39 | $this->signature = $signature; 40 | $this->productGroup = $productGroup; 41 | $this->type = $type; 42 | } 43 | 44 | public function getProductDocument(): string 45 | { 46 | return $this->productDocument; 47 | } 48 | 49 | public function getDocumentFormat(): string 50 | { 51 | return $this->documentFormat; 52 | } 53 | 54 | public function getSignature(): string 55 | { 56 | return $this->signature; 57 | } 58 | 59 | public function getProductGroup(): ?string 60 | { 61 | return $this->productGroup; 62 | } 63 | 64 | public function getType(): ?string 65 | { 66 | return $this->type; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeCisItemResponse.php: -------------------------------------------------------------------------------- 1 | cis = $cis; 89 | $this->gtin = $gtin; 90 | $this->status = $status; 91 | $this->emissionDate = $emissionDate; 92 | $this->packageType = $packageType; 93 | $this->countChildren = $countChildren; 94 | } 95 | 96 | public function getCis(): string 97 | { 98 | return $this->cis; 99 | } 100 | 101 | public function getGtin(): string 102 | { 103 | return $this->gtin; 104 | } 105 | 106 | public function getProducerName(): ?string 107 | { 108 | return $this->producerName; 109 | } 110 | 111 | public function setProducerName(string $producerName): void 112 | { 113 | $this->producerName = $producerName; 114 | } 115 | 116 | public function getStatus(): string 117 | { 118 | return $this->status; 119 | } 120 | 121 | public function getEmissionDate(): int 122 | { 123 | return $this->emissionDate; 124 | } 125 | 126 | public function getPackageType(): string 127 | { 128 | return $this->packageType; 129 | } 130 | 131 | public function getOwnerName(): ?string 132 | { 133 | return $this->ownerName; 134 | } 135 | 136 | public function setOwnerName(string $ownerName): void 137 | { 138 | $this->ownerName = $ownerName; 139 | } 140 | 141 | public function getOwnerInn(): ?string 142 | { 143 | return $this->ownerInn; 144 | } 145 | 146 | public function setOwnerInn(string $ownerInn): void 147 | { 148 | $this->ownerInn = $ownerInn; 149 | } 150 | 151 | public function getCountChildren(): int 152 | { 153 | return $this->countChildren; 154 | } 155 | 156 | public function getProductName(): ?string 157 | { 158 | return $this->productName; 159 | } 160 | 161 | public function setProductName(string $productName): void 162 | { 163 | $this->productName = $productName; 164 | } 165 | 166 | public function getBrand(): ?string 167 | { 168 | return $this->brand; 169 | } 170 | 171 | public function setBrand(string $brand): void 172 | { 173 | $this->brand = $brand; 174 | } 175 | 176 | public function getAgentInn(): ?string 177 | { 178 | return $this->agentInn; 179 | } 180 | 181 | public function setAgentInn(?string $agentInn): void 182 | { 183 | $this->agentInn = $agentInn; 184 | } 185 | 186 | public function getAgentName(): ?string 187 | { 188 | return $this->agentName; 189 | } 190 | 191 | public function setAgentName(?string $agentName): void 192 | { 193 | $this->agentName = $agentName; 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeCisListRequest.php: -------------------------------------------------------------------------------- 1 | cises = $cises; 15 | } 16 | 17 | /** 18 | * @return string[] 19 | */ 20 | public function getCises(): array 21 | { 22 | return $this->cises; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeCisListResponse.php: -------------------------------------------------------------------------------- 1 | items[$item->getCis()] = $item; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocBodyResponse.php: -------------------------------------------------------------------------------- 1 | number = $number; 85 | $this->docDate = $docDate; 86 | $this->type = $type; 87 | $this->status = $status; 88 | $this->senderName = $senderName; 89 | $this->content = $content; 90 | $this->body = $body; 91 | } 92 | 93 | public function getNumber(): string 94 | { 95 | return $this->number; 96 | } 97 | 98 | public function getDocDate(): string 99 | { 100 | return $this->docDate; 101 | } 102 | 103 | public function getType(): string 104 | { 105 | return $this->type; 106 | } 107 | 108 | public function getStatus(): string 109 | { 110 | return $this->status; 111 | } 112 | 113 | public function getSenderName(): ?string 114 | { 115 | return $this->senderName; 116 | } 117 | 118 | public function getContent(): ?string 119 | { 120 | return $this->content; 121 | } 122 | 123 | public function getBody(): ?Body 124 | { 125 | return $this->body; 126 | } 127 | 128 | public function getErrors(): ?array 129 | { 130 | return $this->errors; 131 | } 132 | 133 | public function setErrors(?array $errors): self 134 | { 135 | $this->errors = $errors; 136 | 137 | return $this; 138 | } 139 | 140 | public function getReceiverName(): ?string 141 | { 142 | return $this->receiverName; 143 | } 144 | 145 | public function setReceiverName(?string $receiverName): self 146 | { 147 | $this->receiverName = $receiverName; 148 | 149 | return $this; 150 | } 151 | 152 | public function getDownloadStatus(): ?string 153 | { 154 | return $this->downloadStatus; 155 | } 156 | 157 | public function setDownloadStatus(?string $downloadStatus): self 158 | { 159 | $this->downloadStatus = $downloadStatus; 160 | 161 | return $this; 162 | } 163 | 164 | public function getDownloadDesc(): ?string 165 | { 166 | return $this->downloadDesc; 167 | } 168 | 169 | public function setDownloadDesc(?string $downloadDesc): self 170 | { 171 | $this->downloadDesc = $downloadDesc; 172 | 173 | return $this; 174 | } 175 | 176 | public function getCisTotal(): ?string 177 | { 178 | return $this->cisTotal; 179 | } 180 | 181 | public function setCisTotal(?string $cisTotal): self 182 | { 183 | $this->cisTotal = $cisTotal; 184 | 185 | return $this; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocBodyResponse/Body.php: -------------------------------------------------------------------------------- 1 | originalString; 80 | } 81 | 82 | public function setOriginalString(?string $originalString): self 83 | { 84 | $this->originalString = $originalString; 85 | 86 | return $this; 87 | } 88 | 89 | public function getRegDate(): ?string 90 | { 91 | return $this->regDate; 92 | } 93 | 94 | public function setRegDate(?string $regDate): self 95 | { 96 | $this->regDate = $regDate; 97 | 98 | return $this; 99 | } 100 | 101 | public function getDocumentDescription(): ?DocumentDescription 102 | { 103 | return $this->documentDescription; 104 | } 105 | 106 | public function setDocumentDescription(?DocumentDescription $documentDescription): self 107 | { 108 | $this->documentDescription = $documentDescription; 109 | 110 | return $this; 111 | } 112 | 113 | public function getDocType(): ?string 114 | { 115 | return $this->docType; 116 | } 117 | 118 | public function setDocType(?string $docType): self 119 | { 120 | $this->docType = $docType; 121 | 122 | return $this; 123 | } 124 | 125 | public function getReceiver(): ?string 126 | { 127 | return $this->receiver; 128 | } 129 | 130 | public function setReceiver(?string $receiver): self 131 | { 132 | $this->receiver = $receiver; 133 | 134 | return $this; 135 | } 136 | 137 | public function getDocId(): ?string 138 | { 139 | return $this->docId; 140 | } 141 | 142 | public function setDocId(?string $docId): self 143 | { 144 | $this->docId = $docId; 145 | 146 | return $this; 147 | } 148 | 149 | /** 150 | * @return Product[] 151 | */ 152 | public function getProducts(): array 153 | { 154 | return $this->products; 155 | } 156 | 157 | public function setProducts(array $products): self 158 | { 159 | $this->products = $products; 160 | 161 | return $this; 162 | } 163 | 164 | public function getProductsList(): array 165 | { 166 | return $this->productsList; 167 | } 168 | 169 | public function setProductsList(array $productsList): self 170 | { 171 | $this->productsList = $productsList; 172 | 173 | return $this; 174 | } 175 | 176 | public function addProduct(Product $product): self 177 | { 178 | $this->products[spl_object_hash($product)] = $product; 179 | 180 | return $this; 181 | } 182 | 183 | public function removeProduct(Product $product): self 184 | { 185 | unset($this->products[spl_object_hash($product)]); 186 | 187 | return $this; 188 | } 189 | 190 | public function hasProducts(Product $product): bool 191 | { 192 | return array_key_exists(spl_object_hash($product), $this->products); 193 | } 194 | 195 | public function getTurnoverType(): ?string 196 | { 197 | return $this->turnoverType; 198 | } 199 | 200 | public function setTurnoverType(?string $turnoverType): self 201 | { 202 | $this->turnoverType = $turnoverType; 203 | 204 | return $this; 205 | } 206 | 207 | public function getDocumentNum(): ?string 208 | { 209 | return $this->documentNum; 210 | } 211 | 212 | public function setDocumentNum(?string $documentNum): self 213 | { 214 | $this->documentNum = $documentNum; 215 | 216 | return $this; 217 | } 218 | 219 | public function getDocumentDate(): ?string 220 | { 221 | return $this->documentDate; 222 | } 223 | 224 | public function setDocumentDate(?string $documentDate): self 225 | { 226 | $this->documentDate = $documentDate; 227 | 228 | return $this; 229 | } 230 | 231 | public function getSale(): ?string 232 | { 233 | return $this->sale; 234 | } 235 | 236 | public function setSale(?string $sale): self 237 | { 238 | $this->sale = $sale; 239 | 240 | return $this; 241 | } 242 | 243 | public function getWithdrawalFromTurnover(): ?string 244 | { 245 | return $this->withdrawalFromTurnover; 246 | } 247 | 248 | public function setWithdrawalFromTurnover(?string $withdrawalFromTurnover): self 249 | { 250 | $this->withdrawalFromTurnover = $withdrawalFromTurnover; 251 | 252 | return $this; 253 | } 254 | 255 | public function getTransferDate(): ?string 256 | { 257 | return $this->transferDate; 258 | } 259 | 260 | public function setTransferDate(?string $transferDate): self 261 | { 262 | $this->transferDate = $transferDate; 263 | 264 | return $this; 265 | } 266 | 267 | public function getReceiverInn(): ?string 268 | { 269 | return $this->receiverInn; 270 | } 271 | 272 | public function setReceiverInn(?string $receiverInn): self 273 | { 274 | $this->receiverInn = $receiverInn; 275 | 276 | return $this; 277 | } 278 | 279 | public function getOwnerInn(): ?string 280 | { 281 | return $this->ownerInn; 282 | } 283 | 284 | public function setOwnerInn(?string $ownerInn): self 285 | { 286 | $this->ownerInn = $ownerInn; 287 | 288 | return $this; 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocBodyResponse/Body/DocumentDescription.php: -------------------------------------------------------------------------------- 1 | participantInn; 37 | } 38 | 39 | public function setParticipantInn(?string $participantInn): self 40 | { 41 | $this->participantInn = $participantInn; 42 | 43 | return $this; 44 | } 45 | 46 | public function getMarkingType(): ?string 47 | { 48 | return $this->markingType; 49 | } 50 | 51 | public function setMarkingType(?string $markingType): self 52 | { 53 | $this->markingType = $markingType; 54 | 55 | return $this; 56 | } 57 | 58 | public function getProductionDate(): ?string 59 | { 60 | return $this->productionDate; 61 | } 62 | 63 | public function setProductionDate(?string $productionDate): self 64 | { 65 | $this->productionDate = $productionDate; 66 | 67 | return $this; 68 | } 69 | 70 | public function getProductionType(): ?string 71 | { 72 | return $this->productionType; 73 | } 74 | 75 | public function setProductionType(?string $productionType): self 76 | { 77 | $this->productionType = $productionType; 78 | 79 | return $this; 80 | } 81 | 82 | public function getProducerInn(): ?string 83 | { 84 | return $this->producerInn; 85 | } 86 | 87 | public function setProducerInn(?string $producerInn): self 88 | { 89 | $this->producerInn = $producerInn; 90 | 91 | return $this; 92 | } 93 | 94 | public function getOwnerInn(): ?string 95 | { 96 | return $this->ownerInn; 97 | } 98 | 99 | public function setOwnerInn(?string $ownerInn): self 100 | { 101 | $this->ownerInn = $ownerInn; 102 | 103 | return $this; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocBodyResponse/Body/Products/Product.php: -------------------------------------------------------------------------------- 1 | uituCode; 45 | } 46 | 47 | public function setUituCode(?string $uituCode): self 48 | { 49 | $this->uituCode = $uituCode; 50 | 51 | return $this; 52 | } 53 | 54 | public function getUitCode(): ?string 55 | { 56 | return $this->uitCode; 57 | } 58 | 59 | public function setUitCode(?string $uitCode): self 60 | { 61 | $this->uitCode = $uitCode; 62 | 63 | return $this; 64 | } 65 | 66 | public function getTnvedCode(): ?string 67 | { 68 | return $this->tnvedCode; 69 | } 70 | 71 | public function setTnvedCode(?string $tnvedCode): self 72 | { 73 | $this->tnvedCode = $tnvedCode; 74 | 75 | return $this; 76 | } 77 | 78 | public function getProducerInn(): ?string 79 | { 80 | return $this->producerInn; 81 | } 82 | 83 | public function setProducerInn(?string $producerInn): self 84 | { 85 | $this->producerInn = $producerInn; 86 | 87 | return $this; 88 | } 89 | 90 | public function getOwnerInn(): ?string 91 | { 92 | return $this->ownerInn; 93 | } 94 | 95 | public function setOwnerInn(?string $ownerInn): self 96 | { 97 | $this->ownerInn = $ownerInn; 98 | 99 | return $this; 100 | } 101 | 102 | public function getCertificateDocument(): ?string 103 | { 104 | return $this->certificateDocument; 105 | } 106 | 107 | public function setCertificateDocument(?string $certificateDocument): self 108 | { 109 | $this->certificateDocument = $certificateDocument; 110 | 111 | return $this; 112 | } 113 | 114 | public function getCertificateDocumentNumber(): ?string 115 | { 116 | return $this->certificateDocumentNumber; 117 | } 118 | 119 | public function setCertificateDocumentNumber(?string $certificateDocumentNumber): self 120 | { 121 | $this->certificateDocumentNumber = $certificateDocumentNumber; 122 | 123 | return $this; 124 | } 125 | 126 | public function getCertificateDocumentDate(): ?string 127 | { 128 | return $this->certificateDocumentDate; 129 | } 130 | 131 | public function setCertificateDocumentDate(?string $certificateDocumentDate): self 132 | { 133 | $this->certificateDocumentDate = $certificateDocumentDate; 134 | 135 | return $this; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocListV2ItemResponse.php: -------------------------------------------------------------------------------- 1 | number = $number; 45 | $this->docDate = $docDate; 46 | $this->receivedAt = $receivedAt; 47 | } 48 | 49 | public function getNumber(): string 50 | { 51 | return $this->number; 52 | } 53 | 54 | public function getDocDate(): string 55 | { 56 | return $this->docDate; 57 | } 58 | 59 | /** 60 | * @throws \Exception 61 | */ 62 | public function getDocDateDateTime(): \DateTimeImmutable 63 | { 64 | return new \DateTimeImmutable($this->docDate); 65 | } 66 | 67 | public function getReceivedAt(): string 68 | { 69 | return $this->receivedAt; 70 | } 71 | 72 | /** 73 | * @throws \Exception 74 | */ 75 | public function getReceivedAtDateTime(): \DateTimeImmutable 76 | { 77 | return new \DateTimeImmutable($this->receivedAt); 78 | } 79 | 80 | public function setType(?string $type): self 81 | { 82 | $this->type = $type; 83 | 84 | return $this; 85 | } 86 | 87 | public function setStatus(?string $status): self 88 | { 89 | $this->status = $status; 90 | 91 | return $this; 92 | } 93 | 94 | public function setSenderName(?string $senderName): self 95 | { 96 | $this->senderName = $senderName; 97 | 98 | return $this; 99 | } 100 | 101 | public function getType(): ?string 102 | { 103 | return $this->type; 104 | } 105 | 106 | public function getStatus(): ?string 107 | { 108 | return $this->status; 109 | } 110 | 111 | public function getSenderName(): ?string 112 | { 113 | return $this->senderName; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocListV2Query.php: -------------------------------------------------------------------------------- 1 | dateFrom; 95 | } 96 | 97 | public function setDateFrom(?\DateTimeInterface $dateFrom): void 98 | { 99 | $this->dateFrom = $dateFrom; 100 | } 101 | 102 | public function getDateTo(): ?\DateTimeInterface 103 | { 104 | return $this->dateTo; 105 | } 106 | 107 | public function setDateTo(?\DateTimeInterface $dateTo): void 108 | { 109 | $this->dateTo = $dateTo; 110 | } 111 | 112 | public function getNumber(): ?string 113 | { 114 | return $this->number; 115 | } 116 | 117 | public function setNumber(?string $number): void 118 | { 119 | $this->number = $number; 120 | } 121 | 122 | public function getDocumentStatus(): ?string 123 | { 124 | return $this->documentStatus; 125 | } 126 | 127 | public function setDocumentStatus(?string $documentStatus): void 128 | { 129 | $this->documentStatus = $documentStatus; 130 | } 131 | 132 | public function getDocumentType(): ?string 133 | { 134 | return $this->documentType; 135 | } 136 | 137 | public function setDocumentType(?string $documentType): void 138 | { 139 | $this->documentType = $documentType; 140 | } 141 | 142 | public function getInputFormat(): ?bool 143 | { 144 | return $this->inputFormat; 145 | } 146 | 147 | public function setInputFormat(?bool $inputFormat): void 148 | { 149 | $this->inputFormat = $inputFormat; 150 | } 151 | 152 | public function getParticipantInn(): ?string 153 | { 154 | return $this->participantInn; 155 | } 156 | 157 | public function setParticipantInn(?string $participantInn): void 158 | { 159 | $this->participantInn = $participantInn; 160 | } 161 | 162 | public function getOrder(): ?string 163 | { 164 | return $this->order; 165 | } 166 | 167 | public function setOrder(?string $order): void 168 | { 169 | $this->order = $order; 170 | } 171 | 172 | public function getDid(): ?string 173 | { 174 | return $this->did; 175 | } 176 | 177 | public function setDid(?string $did): void 178 | { 179 | $this->did = $did; 180 | } 181 | 182 | public function getOrderedColumnValue(): ?string 183 | { 184 | return $this->orderedColumnValue; 185 | } 186 | 187 | public function setOrderedColumnValue(?string $orderedColumnValue): void 188 | { 189 | $this->orderedColumnValue = $orderedColumnValue; 190 | } 191 | 192 | public function getOrderColumn(): ?string 193 | { 194 | return $this->orderColumn; 195 | } 196 | 197 | public function setOrderColumn(?string $orderColumn): void 198 | { 199 | $this->orderColumn = $orderColumn; 200 | } 201 | 202 | public function getPageDir(): ?string 203 | { 204 | return $this->pageDir; 205 | } 206 | 207 | public function setPageDir(?string $pageDir): void 208 | { 209 | $this->pageDir = $pageDir; 210 | } 211 | 212 | public function getLimit(): int 213 | { 214 | return $this->limit; 215 | } 216 | 217 | public function setLimit(int $limit): void 218 | { 219 | $this->limit = $limit; 220 | } 221 | 222 | public function toQueryArray(): array 223 | { 224 | $query = []; 225 | 226 | self::appendIfNotNull($query, 'dateTo', $this->dateTo, static function (\DateTimeInterface $value) { 227 | return $value->format(DATE_RFC3339_EXTENDED); 228 | }); 229 | self::appendIfNotNull($query, 'dateFrom', $this->dateFrom, static function (\DateTimeInterface $value) { 230 | return $value->format(DATE_RFC3339_EXTENDED); 231 | }); 232 | self::appendIfNotNull($query, 'number', $this->number); 233 | self::appendIfNotNull($query, 'documentStatus', $this->documentStatus); 234 | self::appendIfNotNull($query, 'documentType', $this->documentType); 235 | self::appendIfNotNull($query, 'inputFormat', $this->inputFormat, static function (bool $value) { 236 | return $value ? 'true' : 'false'; 237 | }); 238 | self::appendIfNotNull($query, 'participantInn', $this->participantInn); 239 | self::appendIfNotNull($query, 'order', $this->order); 240 | self::appendIfNotNull($query, 'did', $this->did); 241 | self::appendIfNotNull($query, 'orderedColumnValue', $this->orderedColumnValue); 242 | self::appendIfNotNull($query, 'orderColumn', $this->orderColumn); 243 | self::appendIfNotNull($query, 'pageDir', $this->pageDir); 244 | self::appendIfNotNull($query, 'limit', $this->limit); 245 | 246 | return $query; 247 | } 248 | 249 | private static function appendIfNotNull(array &$query, string $name, $value, callable $formatter = null): void 250 | { 251 | if ($value !== null) { 252 | $query[$name] = $formatter ? $formatter($value) : $value; 253 | } 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeDocListV2Response.php: -------------------------------------------------------------------------------- 1 | total = $total; 25 | $this->results = $results; 26 | } 27 | 28 | public function getTotal(): int 29 | { 30 | return $this->total; 31 | } 32 | 33 | /** 34 | * @return FacadeDocListV2ItemResponse[] 35 | */ 36 | public function getResults(): array 37 | { 38 | return $this->results; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeMarkedProductsCertDoc.php: -------------------------------------------------------------------------------- 1 | type = $type; 25 | $this->number = $number; 26 | $this->date = $date; 27 | } 28 | 29 | public function getType(): string 30 | { 31 | return $this->type; 32 | } 33 | 34 | public function getNumber(): string 35 | { 36 | return $this->number; 37 | } 38 | 39 | public function getDate(): string 40 | { 41 | return $this->date; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeMarkedProductsResponse.php: -------------------------------------------------------------------------------- 1 | cis = $cis; 181 | $this->gtin = $gtin; 182 | $this->sgtin = $sgtin; 183 | $this->producerName = $producerName; 184 | $this->producerInn = $producerInn; 185 | $this->status = $status; 186 | $this->emissionDate = $emissionDate; 187 | $this->emissionType = $emissionType; 188 | $this->prevCises = $prevCises; 189 | $this->nextCises = $nextCises; 190 | $this->packType = $packType; 191 | $this->countChildren = $countChildren; 192 | } 193 | 194 | public function getCis(): string 195 | { 196 | return $this->cis; 197 | } 198 | 199 | public function getGtin(): string 200 | { 201 | return $this->gtin; 202 | } 203 | 204 | public function getSgtin(): string 205 | { 206 | return $this->sgtin; 207 | } 208 | 209 | public function getProductName(): ?string 210 | { 211 | return $this->productName; 212 | } 213 | 214 | public function getOwnerName(): string 215 | { 216 | return $this->ownerName; 217 | } 218 | 219 | public function getOwnerInn(): string 220 | { 221 | return $this->ownerInn; 222 | } 223 | 224 | public function getProducerName(): string 225 | { 226 | return $this->producerName; 227 | } 228 | 229 | public function getProducerInn(): string 230 | { 231 | return $this->producerInn; 232 | } 233 | 234 | public function getAgentName(): ?string 235 | { 236 | return $this->agentName; 237 | } 238 | 239 | public function getAgentInn(): ?string 240 | { 241 | return $this->agentInn; 242 | } 243 | 244 | public function getStatus(): string 245 | { 246 | return $this->status; 247 | } 248 | 249 | public function getEmissionDate(): string 250 | { 251 | return $this->emissionDate; 252 | } 253 | 254 | public function getEmissionType(): string 255 | { 256 | return $this->emissionType; 257 | } 258 | 259 | public function getIntroducedDate(): ?string 260 | { 261 | return $this->introducedDate; 262 | } 263 | 264 | public function getName(): ?string 265 | { 266 | return $this->name; 267 | } 268 | 269 | public function getBrand(): ?string 270 | { 271 | return $this->brand; 272 | } 273 | 274 | public function getModel(): ?string 275 | { 276 | return $this->model; 277 | } 278 | 279 | /** 280 | * @return FacadeMarkedProductsCertDoc[] 281 | */ 282 | public function getPrevCises(): array 283 | { 284 | return $this->prevCises; 285 | } 286 | 287 | /** 288 | * @return FacadeMarkedProductsCertDoc[] 289 | */ 290 | public function getNextCises(): array 291 | { 292 | return $this->nextCises; 293 | } 294 | 295 | public function getCountry(): ?string 296 | { 297 | return $this->country; 298 | } 299 | 300 | public function getProductTypeDesc(): ?string 301 | { 302 | return $this->productTypeDesc; 303 | } 304 | 305 | public function getColor(): ?string 306 | { 307 | return $this->color; 308 | } 309 | 310 | public function getMaterialDown(): ?string 311 | { 312 | return $this->materialDown; 313 | } 314 | 315 | public function getMaterialUpper(): ?string 316 | { 317 | return $this->materialUpper; 318 | } 319 | 320 | public function getMaterialLining(): ?string 321 | { 322 | return $this->materialLining; 323 | } 324 | 325 | public function getPackType(): string 326 | { 327 | return $this->packType; 328 | } 329 | 330 | public function getCountChildren(): int 331 | { 332 | return $this->countChildren; 333 | } 334 | 335 | public function getGoodSignedFlag(): ?string 336 | { 337 | return $this->goodSignedFlag; 338 | } 339 | 340 | public function getGoodTurnFlag(): ?string 341 | { 342 | return $this->goodTurnFlag; 343 | } 344 | 345 | public function getGoodMarkFlag(): ?string 346 | { 347 | return $this->goodMarkFlag; 348 | } 349 | 350 | public function getLastDocId(): ?string 351 | { 352 | return $this->lastDocId; 353 | } 354 | 355 | public function setProductName(?string $productName): FacadeMarkedProductsResponse 356 | { 357 | $this->productName = $productName; 358 | return $this; 359 | } 360 | 361 | public function setOwnerName(?string $ownerName): self 362 | { 363 | $this->ownerName = $ownerName; 364 | 365 | return $this; 366 | } 367 | 368 | public function setOwnerInn(?string $ownerInn): self 369 | { 370 | $this->ownerInn = $ownerInn; 371 | 372 | return $this; 373 | } 374 | 375 | public function setAgentName(?string $agentName): FacadeMarkedProductsResponse 376 | { 377 | $this->agentName = $agentName; 378 | return $this; 379 | } 380 | 381 | public function setAgentInn(?string $agentInn): FacadeMarkedProductsResponse 382 | { 383 | $this->agentInn = $agentInn; 384 | return $this; 385 | } 386 | 387 | public function setIntroducedDate(?string $introducedDate): FacadeMarkedProductsResponse 388 | { 389 | $this->introducedDate = $introducedDate; 390 | return $this; 391 | } 392 | 393 | public function setName(?string $name): FacadeMarkedProductsResponse 394 | { 395 | $this->name = $name; 396 | return $this; 397 | } 398 | 399 | public function setBrand(?string $brand): FacadeMarkedProductsResponse 400 | { 401 | $this->brand = $brand; 402 | return $this; 403 | } 404 | 405 | public function setModel(?string $model): FacadeMarkedProductsResponse 406 | { 407 | $this->model = $model; 408 | return $this; 409 | } 410 | 411 | public function setCountry(?string $country): FacadeMarkedProductsResponse 412 | { 413 | $this->country = $country; 414 | return $this; 415 | } 416 | 417 | public function setProductTypeDesc(?string $productTypeDesc): FacadeMarkedProductsResponse 418 | { 419 | $this->productTypeDesc = $productTypeDesc; 420 | return $this; 421 | } 422 | 423 | public function setColor(?string $color): FacadeMarkedProductsResponse 424 | { 425 | $this->color = $color; 426 | return $this; 427 | } 428 | 429 | public function setMaterialDown(?string $materialDown): FacadeMarkedProductsResponse 430 | { 431 | $this->materialDown = $materialDown; 432 | return $this; 433 | } 434 | 435 | public function setMaterialUpper(?string $materialUpper): FacadeMarkedProductsResponse 436 | { 437 | $this->materialUpper = $materialUpper; 438 | return $this; 439 | } 440 | 441 | public function setMaterialLining(?string $materialLining): FacadeMarkedProductsResponse 442 | { 443 | $this->materialLining = $materialLining; 444 | return $this; 445 | } 446 | 447 | public function setGoodSignedFlag(?string $goodSignedFlag): FacadeMarkedProductsResponse 448 | { 449 | $this->goodSignedFlag = $goodSignedFlag; 450 | return $this; 451 | } 452 | 453 | public function setGoodTurnFlag(?string $goodTurnFlag): FacadeMarkedProductsResponse 454 | { 455 | $this->goodTurnFlag = $goodTurnFlag; 456 | return $this; 457 | } 458 | 459 | public function setGoodMarkFlag(?string $goodMarkFlag): FacadeMarkedProductsResponse 460 | { 461 | $this->goodMarkFlag = $goodMarkFlag; 462 | return $this; 463 | } 464 | 465 | public function setLastDocId(?string $lastDocId): FacadeMarkedProductsResponse 466 | { 467 | $this->lastDocId = $lastDocId; 468 | return $this; 469 | } 470 | } 471 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeOrderDetailsResponse.php: -------------------------------------------------------------------------------- 1 | orderId = $orderId; 44 | $this->orderStatus = $orderStatus; 45 | $this->orderCreationDate = $orderCreationDate; 46 | } 47 | 48 | public function getOrderId(): string 49 | { 50 | return $this->orderId; 51 | } 52 | 53 | public function getOrderStatus(): string 54 | { 55 | return $this->orderStatus; 56 | } 57 | 58 | public function setOrderStatusDetails(?string $orderStatusDetails): FacadeOrderDetailsResponse 59 | { 60 | $this->orderStatusDetails = $orderStatusDetails; 61 | 62 | return $this; 63 | } 64 | 65 | public function getOrderStatusDetails(): ?string 66 | { 67 | return $this->orderStatusDetails; 68 | } 69 | 70 | public function getOrderCreationDate(): int 71 | { 72 | return $this->orderCreationDate; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeOrderRequest.php: -------------------------------------------------------------------------------- 1 | document = $document; 25 | $this->documentFormat = $documentFormat; 26 | $this->signature = $signature; 27 | } 28 | 29 | public function getDocument(): string 30 | { 31 | return $this->document; 32 | } 33 | 34 | public function getDocumentFormat(): string 35 | { 36 | return $this->documentFormat; 37 | } 38 | 39 | public function getSignature(): string 40 | { 41 | return $this->signature; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/V3/Dto/FacadeOrderResponse.php: -------------------------------------------------------------------------------- 1 | orderId = $orderId; 24 | $this->orderStatus = $orderStatus; 25 | } 26 | 27 | public function getOrderId(): string 28 | { 29 | return $this->orderId; 30 | } 31 | 32 | public function getOrderStatus(): string 33 | { 34 | return $this->orderStatus; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/V3/Dto/ProductInfoResponse.php: -------------------------------------------------------------------------------- 1 | results = $results; 21 | $this->total = $total; 22 | } 23 | 24 | public function getResults(): array 25 | { 26 | return $this->results; 27 | } 28 | 29 | public function getTotal(): int 30 | { 31 | return $this->total; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/V3/Enum/DocumentLkType.php: -------------------------------------------------------------------------------- 1 | client = $client; 42 | $this->serializer = $serializer; 43 | } 44 | 45 | public function authCertKey(): AuthCertKeyResponse 46 | { 47 | $result = $this->request('GET', '/api/v3/auth/cert/key'); 48 | 49 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 50 | return $this->serializer->deserialize(AuthCertKeyResponse::class, $result); 51 | } 52 | 53 | public function authCert(AuthCertRequest $request, ?string $connection = null): AuthCertResponse 54 | { 55 | $body = $this->serializer->serialize($request); 56 | $result = $this->request( 57 | 'POST', 58 | sprintf('/api/v3/auth/cert/%s', $connection), 59 | $body 60 | ); 61 | 62 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 63 | return $this->serializer->deserialize(AuthCertResponse::class, $result); 64 | } 65 | 66 | public function facadeOrder(string $token, FacadeOrderRequest $request): FacadeOrderResponse 67 | { 68 | $body = $this->serializer->serialize($request); 69 | $result = $this->request('POST', '/api/v3/facade/order/', $body, null, $token); 70 | 71 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 72 | return $this->serializer->deserialize(FacadeOrderResponse::class, $result); 73 | } 74 | 75 | public function facadeOrderDetails(string $token, string $orderId): FacadeOrderDetailsResponse 76 | { 77 | $result = $this->request('GET', sprintf('/api/v3/facade/order/%s/details', $orderId), null, null, $token); 78 | 79 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 80 | return $this->serializer->deserialize(FacadeOrderDetailsResponse::class, $result); 81 | } 82 | 83 | public function facadeDocListV2(string $token, FacadeDocListV2Query $query): FacadeDocListV2Response 84 | { 85 | $result = $this->request('GET', '/api/v3/facade/doc/listV2', null, $query->toQueryArray(), $token); 86 | 87 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 88 | return $this->serializer->deserialize(FacadeDocListV2Response::class, $result); 89 | } 90 | 91 | public function facadeDocBody( 92 | string $token, 93 | string $docId, 94 | ?int $limit = null, 95 | ?string $orderColumn = null, 96 | ?string $orderedColumnValue = null, 97 | ?string $pageDir = null 98 | ): FacadeDocBodyResponse { 99 | $query = null; 100 | if ($limit !== null) { 101 | $query['limit'] = $limit; 102 | } 103 | if ($orderColumn !== null) { 104 | $query['orderColumn'] = $orderColumn; 105 | } 106 | if ($orderedColumnValue !== null) { 107 | $query['orderedColumnValue'] = $orderedColumnValue; 108 | } 109 | if ($pageDir !== null) { 110 | $query['pageDir'] = $pageDir; 111 | } 112 | 113 | $result = $this->request('GET', sprintf('/api/v3/facade/doc/%s/body', $docId), null, $query, $token); 114 | 115 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 116 | return $this->serializer->deserialize(FacadeDocBodyResponse::class, $result); 117 | } 118 | 119 | public function facadeCisList(string $token, FacadeCisListRequest $request): FacadeCisListResponse 120 | { 121 | $body = $this->serializer->serialize($request); 122 | $response = $this->request('POST', '/api/v3/facade/cis/cis_list', $body, null, $token); 123 | 124 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 125 | return $this->serializer->deserialize(FacadeCisListResponse::class, $response); 126 | } 127 | 128 | public function facadeMarkedProducts(string $token, string $cis): FacadeMarkedProductsResponse 129 | { 130 | $response = $this->request('GET', '/api/v3/facade/marked_products/info', null, ['cis' => $cis], $token); 131 | 132 | /** @noinspection PhpIncompatibleReturnTypeInspection */ 133 | return $this->serializer->deserialize(FacadeMarkedProductsResponse::class, $response); 134 | } 135 | 136 | public function lkDocumentsCreate(string $token, DocumentCreateRequest $request): string 137 | { 138 | assert($request->getType() !== null, 'Document type is required for lkDocumentsCreate'); 139 | assert($request->getProductGroup() !== null, 'Product group is required for lkDocumentsCreate'); 140 | 141 | $body = $this->serializer->serialize($request); 142 | 143 | return $this->request( 144 | 'POST', 145 | '/api/v3/lk/documents/create', 146 | $body, 147 | ['pg' => $request->getProductGroup()], 148 | $token 149 | ); 150 | } 151 | 152 | public function lkImportSend(string $token, DocumentCreateRequest $request): string 153 | { 154 | $body = $this->serializer->serialize($request); 155 | 156 | return $this->request('POST', '/api/v3/lk/import/send', $body, null, $token); 157 | } 158 | 159 | public function lkReceiptSend(string $token, DocumentCreateRequest $request): string 160 | { 161 | $body = $this->serializer->serialize($request); 162 | 163 | return $this->request('POST', '/api/v3/lk/receipt/send', $body, null, $token); 164 | } 165 | 166 | public function lkDocumentsShipmentCreate(string $token, DocumentCreateRequest $request): string 167 | { 168 | $body = $this->serializer->serialize($request); 169 | 170 | return $this->request('POST', '/api/v3/lk/documents/shipment/create', $body, null, $token); 171 | } 172 | 173 | public function lkDocumentsAcceptanceCreate(string $token, DocumentCreateRequest $request): string 174 | { 175 | $body = $this->serializer->serialize($request); 176 | 177 | return $this->request('POST', '/api/v3/lk/documents/acceptance/create', $body, null, $token); 178 | } 179 | 180 | public function productInfo(string $token, array $gtins): ProductInfoResponse 181 | { 182 | $gtinsList = implode(',', $gtins); 183 | 184 | $result = $this->request('GET', 'api/v3/product/info', null, [ 185 | 'gtins' => $gtinsList, 186 | ], $token); 187 | 188 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 189 | return $this->serializer->deserialize(ProductInfoResponse::class, $result); 190 | } 191 | 192 | private function request(string $method, string $uri, $body = null, $query = null, string $token = null): string 193 | { 194 | $options = [ 195 | RequestOptions::BODY => $body, 196 | RequestOptions::HEADERS => [ 197 | 'Content-Type' => 'application/json', 198 | ], 199 | RequestOptions::HTTP_ERRORS => true, 200 | RequestOptions::QUERY => $query, 201 | ]; 202 | 203 | if ($token) { 204 | $options[RequestOptions::HEADERS]['Authorization'] = 'Bearer ' . $token; 205 | } 206 | 207 | $uri = ltrim($uri, '/'); 208 | 209 | try { 210 | $result = $this->client->request($method, $uri, $options); 211 | } catch (\Throwable $exception) { 212 | /* @noinspection PhpUnhandledExceptionInspection */ 213 | throw $this->handleRequestException($exception); 214 | } 215 | 216 | return (string)$result->getBody(); 217 | } 218 | 219 | private function handleRequestException(\Throwable $exception): \Throwable 220 | { 221 | if ($exception instanceof BadResponseException) { 222 | $response = $exception->getResponse(); 223 | $responseBody = $response ? (string)$response->getBody() : ''; 224 | $responseCode = $response ? $response->getStatusCode() : 0; 225 | 226 | return IsmpRequestErrorException::becauseOfErrorResponse($responseCode, $responseBody, $exception); 227 | } 228 | 229 | return IsmpGeneralErrorException::becauseOfError($exception); 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/V3/IsmpApiInterface.php: -------------------------------------------------------------------------------- 1 | cis; 80 | } 81 | 82 | public function setCis(string $cis): void 83 | { 84 | $this->cis = $cis; 85 | } 86 | 87 | public function getGtin(): ?string 88 | { 89 | return $this->gtin; 90 | } 91 | 92 | public function setGtin(?string $gtin): void 93 | { 94 | $this->gtin = $gtin; 95 | } 96 | 97 | public function getProducerName(): ?string 98 | { 99 | return $this->producerName; 100 | } 101 | 102 | public function setProducerName(?string $producerName): void 103 | { 104 | $this->producerName = $producerName; 105 | } 106 | 107 | public function getStatus(): string 108 | { 109 | return $this->status; 110 | } 111 | 112 | public function setStatus(string $status): void 113 | { 114 | $this->status = $status; 115 | } 116 | 117 | public function getEmissionDate(): string 118 | { 119 | return $this->emissionDate; 120 | } 121 | 122 | public function setEmissionDate(string $emissionDate): void 123 | { 124 | $this->emissionDate = $emissionDate; 125 | } 126 | 127 | public function getEmissionType(): string 128 | { 129 | return $this->emissionType; 130 | } 131 | 132 | public function setEmissionType(string $emissionType): void 133 | { 134 | $this->emissionType = $emissionType; 135 | } 136 | 137 | public function getProducedDate(): ?string 138 | { 139 | return $this->producedDate; 140 | } 141 | 142 | public function setProducedDate(?string $producedDate): void 143 | { 144 | $this->producedDate = $producedDate; 145 | } 146 | 147 | public function getPackType(): string 148 | { 149 | return $this->packType; 150 | } 151 | 152 | public function setPackType(string $packType): void 153 | { 154 | $this->packType = $packType; 155 | } 156 | 157 | public function getOwnerName(): ?string 158 | { 159 | return $this->ownerName; 160 | } 161 | 162 | public function setOwnerName(?string $ownerName): void 163 | { 164 | $this->ownerName = $ownerName; 165 | } 166 | 167 | public function getOwnerInn(): ?string 168 | { 169 | return $this->ownerInn; 170 | } 171 | 172 | public function setOwnerInn(?string $ownerInn): void 173 | { 174 | $this->ownerInn = $ownerInn; 175 | } 176 | 177 | public function getProductName(): ?string 178 | { 179 | return $this->productName; 180 | } 181 | 182 | public function setProductName(?string $productName): void 183 | { 184 | $this->productName = $productName; 185 | } 186 | 187 | public function getBrand(): ?string 188 | { 189 | return $this->brand; 190 | } 191 | 192 | public function setBrand(?string $brand): void 193 | { 194 | $this->brand = $brand; 195 | } 196 | 197 | public function getPrevCises(): ?array 198 | { 199 | return $this->prevCises; 200 | } 201 | 202 | public function setPrevCises(?array $prevCises): void 203 | { 204 | $this->prevCises = $prevCises; 205 | } 206 | 207 | public function getNextCises(): ?array 208 | { 209 | return $this->nextCises; 210 | } 211 | 212 | public function setNextCises(?array $nextCises): void 213 | { 214 | $this->nextCises = $nextCises; 215 | } 216 | 217 | public function getStatusEx(): ?string 218 | { 219 | return $this->statusEx; 220 | } 221 | 222 | public function setStatusEx(?string $statusEx): void 223 | { 224 | $this->statusEx = $statusEx; 225 | } 226 | 227 | public function getChildren(): ?array 228 | { 229 | return $this->children; 230 | } 231 | 232 | public function setChildren(array $children): void 233 | { 234 | $this->children = $children; 235 | } 236 | 237 | public function getCountChildren(): ?int 238 | { 239 | return $this->countChildren; 240 | } 241 | 242 | public function setCountChildren(?int $countChildren): void 243 | { 244 | $this->countChildren = $countChildren; 245 | } 246 | 247 | public function getParent(): ?string 248 | { 249 | return $this->parent; 250 | } 251 | 252 | public function setParent(?string $parent): void 253 | { 254 | $this->parent = $parent; 255 | } 256 | 257 | public function getLastDocId(): ?string 258 | { 259 | return $this->lastDocId; 260 | } 261 | 262 | public function setLastDocId(?string $lastDocId): void 263 | { 264 | $this->lastDocId = $lastDocId; 265 | } 266 | 267 | public function getIntroducedDate(): ?string 268 | { 269 | return $this->introducedDate; 270 | } 271 | 272 | public function setIntroducedDate(?string $introducedDate): void 273 | { 274 | $this->introducedDate = $introducedDate; 275 | } 276 | 277 | public function getAgentInn(): ?string 278 | { 279 | return $this->agentInn; 280 | } 281 | 282 | public function setAgentInn(?string $agentInn): void 283 | { 284 | $this->agentInn = $agentInn; 285 | } 286 | 287 | public function getAgentName(): ?string 288 | { 289 | return $this->agentName; 290 | } 291 | 292 | public function setAgentName(?string $agentName): void 293 | { 294 | $this->agentName = $agentName; 295 | } 296 | 297 | public function getLastStatusChangeDate(): string 298 | { 299 | return $this->lastStatusChangeDate; 300 | } 301 | 302 | public function setLastStatusChangeDate(string $lastStatusChangeDate): void 303 | { 304 | $this->lastStatusChangeDate = $lastStatusChangeDate; 305 | } 306 | 307 | public function getTurnoverType(): ?string 308 | { 309 | return $this->turnoverType; 310 | } 311 | 312 | public function setTurnoverType(?string $turnoverType): void 313 | { 314 | $this->turnoverType = $turnoverType; 315 | } 316 | 317 | public function getProductGroup(): string 318 | { 319 | return $this->productGroup; 320 | } 321 | 322 | public function setProductGroup(string $productGroup): void 323 | { 324 | $this->productGroup = $productGroup; 325 | } 326 | 327 | public function getTnVed10(): ?string 328 | { 329 | return $this->tnVed10; 330 | } 331 | 332 | public function setTnVed10(?string $tnVed10): void 333 | { 334 | $this->tnVed10 = $tnVed10; 335 | } 336 | 337 | public function getMarkWithdraw(): ?bool 338 | { 339 | return $this->markWithdraw; 340 | } 341 | 342 | public function setMarkWithdraw(?bool $markWithdraw): void 343 | { 344 | $this->markWithdraw = $markWithdraw; 345 | } 346 | 347 | public function getCertDoc(): array 348 | { 349 | return $this->certDoc; 350 | } 351 | 352 | public function setCertDoc(array $certDoc): void 353 | { 354 | $this->certDoc = $certDoc; 355 | } 356 | 357 | public function getWithdrawReason(): ?string 358 | { 359 | return $this->withdrawReason; 360 | } 361 | 362 | public function setWithdrawReason(?string $withdrawReason): void 363 | { 364 | $this->withdrawReason = $withdrawReason; 365 | } 366 | 367 | public function getWithdrawReasonOther(): ?string 368 | { 369 | return $this->withdrawReasonOther; 370 | } 371 | 372 | public function setWithdrawReasonOther(?string $withdrawReasonOther): void 373 | { 374 | $this->withdrawReasonOther = $withdrawReasonOther; 375 | } 376 | } 377 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeCisListRequest.php: -------------------------------------------------------------------------------- 1 | cises = $cises; 15 | } 16 | 17 | /** 18 | * @return string[] 19 | */ 20 | public function getCises(): array 21 | { 22 | return $this->cises; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeCisListResponse.php: -------------------------------------------------------------------------------- 1 | setItems(...$items); 20 | } 21 | 22 | /** 23 | * @return FacadeCisItemResponse[] 24 | */ 25 | public function getItems(): array 26 | { 27 | return $this->items; 28 | } 29 | 30 | public function setItems(FacadeCisItemResponse ...$items): self 31 | { 32 | foreach ($items as $item) { 33 | $this->items[$item->getCis()] = $item; 34 | } 35 | return $this; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeDocBodyResponse.php: -------------------------------------------------------------------------------- 1 | number = $number; 85 | $this->docDate = $docDate; 86 | $this->type = $type; 87 | $this->status = $status; 88 | $this->senderName = $senderName; 89 | $this->content = $content; 90 | $this->body = $body; 91 | } 92 | 93 | public function getNumber(): string 94 | { 95 | return $this->number; 96 | } 97 | 98 | public function getDocDate(): string 99 | { 100 | return $this->docDate; 101 | } 102 | 103 | public function getType(): string 104 | { 105 | return $this->type; 106 | } 107 | 108 | public function getStatus(): string 109 | { 110 | return $this->status; 111 | } 112 | 113 | public function getSenderName(): ?string 114 | { 115 | return $this->senderName; 116 | } 117 | 118 | public function getContent(): ?string 119 | { 120 | return $this->content; 121 | } 122 | 123 | public function getBody(): ?Body 124 | { 125 | return $this->body; 126 | } 127 | 128 | public function getErrors(): ?array 129 | { 130 | return $this->errors; 131 | } 132 | 133 | public function setErrors(?array $errors): self 134 | { 135 | $this->errors = $errors; 136 | 137 | return $this; 138 | } 139 | 140 | public function getReceiverName(): ?string 141 | { 142 | return $this->receiverName; 143 | } 144 | 145 | public function setReceiverName(?string $receiverName): self 146 | { 147 | $this->receiverName = $receiverName; 148 | 149 | return $this; 150 | } 151 | 152 | public function getDownloadStatus(): ?string 153 | { 154 | return $this->downloadStatus; 155 | } 156 | 157 | public function setDownloadStatus(?string $downloadStatus): self 158 | { 159 | $this->downloadStatus = $downloadStatus; 160 | 161 | return $this; 162 | } 163 | 164 | public function getDownloadDesc(): ?string 165 | { 166 | return $this->downloadDesc; 167 | } 168 | 169 | public function setDownloadDesc(?string $downloadDesc): self 170 | { 171 | $this->downloadDesc = $downloadDesc; 172 | 173 | return $this; 174 | } 175 | 176 | public function getCisTotal(): ?string 177 | { 178 | return $this->cisTotal; 179 | } 180 | 181 | public function setCisTotal(?string $cisTotal): self 182 | { 183 | $this->cisTotal = $cisTotal; 184 | 185 | return $this; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeDocBodyResponse/Body.php: -------------------------------------------------------------------------------- 1 | originalString; 80 | } 81 | 82 | public function setOriginalString(?string $originalString): self 83 | { 84 | $this->originalString = $originalString; 85 | 86 | return $this; 87 | } 88 | 89 | public function getRegDate(): ?string 90 | { 91 | return $this->regDate; 92 | } 93 | 94 | public function setRegDate(?string $regDate): self 95 | { 96 | $this->regDate = $regDate; 97 | 98 | return $this; 99 | } 100 | 101 | public function getDocumentDescription(): ?DocumentDescription 102 | { 103 | return $this->documentDescription; 104 | } 105 | 106 | public function setDocumentDescription(?DocumentDescription $documentDescription): self 107 | { 108 | $this->documentDescription = $documentDescription; 109 | 110 | return $this; 111 | } 112 | 113 | public function getDocType(): ?string 114 | { 115 | return $this->docType; 116 | } 117 | 118 | public function setDocType(?string $docType): self 119 | { 120 | $this->docType = $docType; 121 | 122 | return $this; 123 | } 124 | 125 | public function getReceiver(): ?string 126 | { 127 | return $this->receiver; 128 | } 129 | 130 | public function setReceiver(?string $receiver): self 131 | { 132 | $this->receiver = $receiver; 133 | 134 | return $this; 135 | } 136 | 137 | public function getDocId(): ?string 138 | { 139 | return $this->docId; 140 | } 141 | 142 | public function setDocId(?string $docId): self 143 | { 144 | $this->docId = $docId; 145 | 146 | return $this; 147 | } 148 | 149 | /** 150 | * @return Product[] 151 | */ 152 | public function getProducts(): array 153 | { 154 | return $this->products; 155 | } 156 | 157 | public function setProducts(array $products): self 158 | { 159 | $this->products = $products; 160 | 161 | return $this; 162 | } 163 | 164 | public function getProductsList(): array 165 | { 166 | return $this->productsList; 167 | } 168 | 169 | public function setProductsList(array $productsList): self 170 | { 171 | $this->productsList = $productsList; 172 | 173 | return $this; 174 | } 175 | 176 | public function addProduct(Product $product): self 177 | { 178 | $this->products[spl_object_hash($product)] = $product; 179 | 180 | return $this; 181 | } 182 | 183 | public function removeProduct(Product $product): self 184 | { 185 | unset($this->products[spl_object_hash($product)]); 186 | 187 | return $this; 188 | } 189 | 190 | public function hasProducts(Product $product): bool 191 | { 192 | return array_key_exists(spl_object_hash($product), $this->products); 193 | } 194 | 195 | public function getTurnoverType(): ?string 196 | { 197 | return $this->turnoverType; 198 | } 199 | 200 | public function setTurnoverType(?string $turnoverType): self 201 | { 202 | $this->turnoverType = $turnoverType; 203 | 204 | return $this; 205 | } 206 | 207 | public function getDocumentNum(): ?string 208 | { 209 | return $this->documentNum; 210 | } 211 | 212 | public function setDocumentNum(?string $documentNum): self 213 | { 214 | $this->documentNum = $documentNum; 215 | 216 | return $this; 217 | } 218 | 219 | public function getDocumentDate(): ?string 220 | { 221 | return $this->documentDate; 222 | } 223 | 224 | public function setDocumentDate(?string $documentDate): self 225 | { 226 | $this->documentDate = $documentDate; 227 | 228 | return $this; 229 | } 230 | 231 | public function getSale(): ?string 232 | { 233 | return $this->sale; 234 | } 235 | 236 | public function setSale(?string $sale): self 237 | { 238 | $this->sale = $sale; 239 | 240 | return $this; 241 | } 242 | 243 | public function getWithdrawalFromTurnover(): ?string 244 | { 245 | return $this->withdrawalFromTurnover; 246 | } 247 | 248 | public function setWithdrawalFromTurnover(?string $withdrawalFromTurnover): self 249 | { 250 | $this->withdrawalFromTurnover = $withdrawalFromTurnover; 251 | 252 | return $this; 253 | } 254 | 255 | public function getTransferDate(): ?string 256 | { 257 | return $this->transferDate; 258 | } 259 | 260 | public function setTransferDate(?string $transferDate): self 261 | { 262 | $this->transferDate = $transferDate; 263 | 264 | return $this; 265 | } 266 | 267 | public function getReceiverInn(): ?string 268 | { 269 | return $this->receiverInn; 270 | } 271 | 272 | public function setReceiverInn(?string $receiverInn): self 273 | { 274 | $this->receiverInn = $receiverInn; 275 | 276 | return $this; 277 | } 278 | 279 | public function getOwnerInn(): ?string 280 | { 281 | return $this->ownerInn; 282 | } 283 | 284 | public function setOwnerInn(?string $ownerInn): self 285 | { 286 | $this->ownerInn = $ownerInn; 287 | 288 | return $this; 289 | } 290 | } 291 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeDocBodyResponse/Body/DocumentDescription.php: -------------------------------------------------------------------------------- 1 | participantInn; 37 | } 38 | 39 | public function setParticipantInn(?string $participantInn): self 40 | { 41 | $this->participantInn = $participantInn; 42 | 43 | return $this; 44 | } 45 | 46 | public function getMarkingType(): ?string 47 | { 48 | return $this->markingType; 49 | } 50 | 51 | public function setMarkingType(?string $markingType): self 52 | { 53 | $this->markingType = $markingType; 54 | 55 | return $this; 56 | } 57 | 58 | public function getProductionDate(): ?string 59 | { 60 | return $this->productionDate; 61 | } 62 | 63 | public function setProductionDate(?string $productionDate): self 64 | { 65 | $this->productionDate = $productionDate; 66 | 67 | return $this; 68 | } 69 | 70 | public function getProductionType(): ?string 71 | { 72 | return $this->productionType; 73 | } 74 | 75 | public function setProductionType(?string $productionType): self 76 | { 77 | $this->productionType = $productionType; 78 | 79 | return $this; 80 | } 81 | 82 | public function getProducerInn(): ?string 83 | { 84 | return $this->producerInn; 85 | } 86 | 87 | public function setProducerInn(?string $producerInn): self 88 | { 89 | $this->producerInn = $producerInn; 90 | 91 | return $this; 92 | } 93 | 94 | public function getOwnerInn(): ?string 95 | { 96 | return $this->ownerInn; 97 | } 98 | 99 | public function setOwnerInn(?string $ownerInn): self 100 | { 101 | $this->ownerInn = $ownerInn; 102 | 103 | return $this; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/V4/Dto/FacadeDocBodyResponse/Body/Products/Product.php: -------------------------------------------------------------------------------- 1 | uituCode; 45 | } 46 | 47 | public function setUituCode(?string $uituCode): self 48 | { 49 | $this->uituCode = $uituCode; 50 | 51 | return $this; 52 | } 53 | 54 | public function getUitCode(): ?string 55 | { 56 | return $this->uitCode; 57 | } 58 | 59 | public function setUitCode(?string $uitCode): self 60 | { 61 | $this->uitCode = $uitCode; 62 | 63 | return $this; 64 | } 65 | 66 | public function getTnvedCode(): ?string 67 | { 68 | return $this->tnvedCode; 69 | } 70 | 71 | public function setTnvedCode(?string $tnvedCode): self 72 | { 73 | $this->tnvedCode = $tnvedCode; 74 | 75 | return $this; 76 | } 77 | 78 | public function getProducerInn(): ?string 79 | { 80 | return $this->producerInn; 81 | } 82 | 83 | public function setProducerInn(?string $producerInn): self 84 | { 85 | $this->producerInn = $producerInn; 86 | 87 | return $this; 88 | } 89 | 90 | public function getOwnerInn(): ?string 91 | { 92 | return $this->ownerInn; 93 | } 94 | 95 | public function setOwnerInn(?string $ownerInn): self 96 | { 97 | $this->ownerInn = $ownerInn; 98 | 99 | return $this; 100 | } 101 | 102 | public function getCertificateDocument(): ?string 103 | { 104 | return $this->certificateDocument; 105 | } 106 | 107 | public function setCertificateDocument(?string $certificateDocument): self 108 | { 109 | $this->certificateDocument = $certificateDocument; 110 | 111 | return $this; 112 | } 113 | 114 | public function getCertificateDocumentNumber(): ?string 115 | { 116 | return $this->certificateDocumentNumber; 117 | } 118 | 119 | public function setCertificateDocumentNumber(?string $certificateDocumentNumber): self 120 | { 121 | $this->certificateDocumentNumber = $certificateDocumentNumber; 122 | 123 | return $this; 124 | } 125 | 126 | public function getCertificateDocumentDate(): ?string 127 | { 128 | return $this->certificateDocumentDate; 129 | } 130 | 131 | public function setCertificateDocumentDate(?string $certificateDocumentDate): self 132 | { 133 | $this->certificateDocumentDate = $certificateDocumentDate; 134 | 135 | return $this; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/V4/IsmpApi.php: -------------------------------------------------------------------------------- 1 | client = $client; 45 | $this->serializer = $serializer; 46 | $this->ismpApiV3 = $ismpApiV3 ?? new IsmpApiV3($client, $serializer); 47 | } 48 | 49 | public function facadeDocBody(string $token, string $docId, ?int $limit = null, ?string $orderColumn = null, ?string $orderedColumnValue = null, ?string $pageDir = null): FacadeDocBodyResponse 50 | { 51 | $query = null; 52 | if ($limit !== null) { 53 | $query['limit'] = $limit; 54 | } 55 | if ($orderColumn !== null) { 56 | $query['orderColumn'] = $orderColumn; 57 | } 58 | if ($orderedColumnValue !== null) { 59 | $query['orderedColumnValue'] = $orderedColumnValue; 60 | } 61 | if ($pageDir !== null) { 62 | $query['pageDir'] = $pageDir; 63 | } 64 | 65 | $result = $this->request('GET', sprintf('/api/v4/facade/doc/%s/body', $docId), null, $query, $token); 66 | 67 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 68 | return $this->serializer->deserialize(FacadeDocBodyResponse::class, $result); 69 | } 70 | 71 | public function facadeCisList(string $token, FacadeCisListRequest $request): FacadeCisListResponse 72 | { 73 | $body = $this->serializer->serialize($request); 74 | $response = $this->request('POST', '/api/v4/facade/cis/cis_list', $body, null, $token); 75 | 76 | /* @noinspection PhpIncompatibleReturnTypeInspection */ 77 | return $this->serializer->deserialize(FacadeCisListResponse::class, $response); 78 | } 79 | 80 | public function authCertKey(): AuthCertKeyResponse 81 | { 82 | return $this->ismpApiV3->authCertKey(); 83 | } 84 | 85 | public function authCert(AuthCertRequest $request, ?string $connection = null): AuthCertResponse 86 | { 87 | return $this->ismpApiV3->authCert($request, $connection); 88 | } 89 | 90 | public function facadeDocListV2(string $token, FacadeDocListV2Query $query): FacadeDocListV2Response 91 | { 92 | return $this->ismpApiV3->facadeDocListV2($token, $query); 93 | } 94 | 95 | public function lkDocumentsCreate(string $token, DocumentCreateRequest $request): string 96 | { 97 | return $this->ismpApiV3->lkDocumentsCreate($token, $request); 98 | } 99 | 100 | public function productInfo(string $token, array $gtins): ProductInfoResponse 101 | { 102 | return $this->ismpApiV3->productInfo($token, $gtins); 103 | } 104 | 105 | public function facadeMarkedProducts(string $token, string $cis): FacadeMarkedProductsResponse 106 | { 107 | return $this->ismpApiV3->facadeMarkedProducts($token, $cis); 108 | } 109 | 110 | private function request(string $method, string $uri, $body = null, $query = null, string $token = null): string 111 | { 112 | $options = [ 113 | RequestOptions::BODY => $body, 114 | RequestOptions::HEADERS => [ 115 | 'Content-Type' => 'application/json', 116 | ], 117 | RequestOptions::HTTP_ERRORS => true, 118 | RequestOptions::QUERY => $query, 119 | ]; 120 | 121 | if ($token) { 122 | $options[RequestOptions::HEADERS]['Authorization'] = 'Bearer ' . $token; 123 | } 124 | 125 | $uri = ltrim($uri, '/'); 126 | 127 | try { 128 | $result = $this->client->request($method, $uri, $options); 129 | } catch (\Throwable $exception) { 130 | /* @noinspection PhpUnhandledExceptionInspection */ 131 | throw $this->handleRequestException($exception); 132 | } 133 | 134 | return (string)$result->getBody(); 135 | } 136 | 137 | private function handleRequestException(\Throwable $exception): \Throwable 138 | { 139 | if ($exception instanceof BadResponseException) { 140 | $response = $exception->getResponse(); 141 | $responseBody = $response ? (string)$response->getBody() : ''; 142 | $responseCode = $response ? $response->getStatusCode() : 0; 143 | 144 | return IsmpRequestErrorException::becauseOfErrorResponse($responseCode, $responseBody, $exception); 145 | } 146 | 147 | return IsmpGeneralErrorException::becauseOfError($exception); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/V4/IsmpApiInterface.php: -------------------------------------------------------------------------------- 1 | inner = $this->createMock(DenormalizerInterface::class); 30 | $this->denormalizer = new FacadeCisListResponseDenormalizer(); 31 | } 32 | 33 | /** 34 | * @dataProvider dataSupportsDenormalization 35 | */ 36 | public function testSupportsDenormalization(string $type, bool $expected): void 37 | { 38 | $result = $this->denormalizer->supportsDenormalization([], $type); 39 | 40 | $this->assertEquals($expected, $result); 41 | } 42 | 43 | public function dataSupportsDenormalization(): array 44 | { 45 | return [ 46 | [ 47 | FacadeCisListResponse::class, 48 | true, 49 | ], 50 | [ 51 | \stdClass::class, 52 | false, 53 | ], 54 | ]; 55 | } 56 | 57 | public function testDenormalizationWhenDenormalizerIsNotSet(): void 58 | { 59 | $this->expectException(BadMethodCallException::class); 60 | $this->denormalizer->denormalize([], FacadeCisListResponse::class); 61 | } 62 | 63 | public function testDenormalizationWhenWrongData(): void 64 | { 65 | $this->denormalizer->setDenormalizer($this->inner); 66 | 67 | $this->expectException(InvalidArgumentException::class); 68 | $this->denormalizer->denormalize('wrong', FacadeCisListResponse::class); 69 | } 70 | 71 | public function testDenormalizationWhenWrongType(): void 72 | { 73 | $this->denormalizer->setDenormalizer($this->inner); 74 | 75 | $this->expectException(InvalidArgumentException::class); 76 | $this->denormalizer->denormalize([], \stdClass::class); 77 | } 78 | 79 | public function testDenormalizationWorks(): void 80 | { 81 | $this->denormalizer->setDenormalizer($this->inner); 82 | 83 | $item1 = new FacadeCisItemResponse('', '', '', 0, '', 0); 84 | $item2 = new FacadeCisItemResponse('', '', '', 0, '', 0); 85 | 86 | $expectedResult = new FacadeCisListResponse($item1, $item2); 87 | 88 | $this->inner->expects($this->exactly(2)) 89 | ->method('denormalize') 90 | ->withConsecutive( 91 | ['first', FacadeCisItemResponse::class, null, []], 92 | ['second', FacadeCisItemResponse::class, null, []] 93 | ) 94 | ->willReturnOnConsecutiveCalls( 95 | $item1, 96 | $item2 97 | ); 98 | 99 | $result = $this->denormalizer->denormalize([ 100 | 'first', 101 | 'second', 102 | ], FacadeCisListResponse::class); 103 | 104 | $this->assertEquals($expectedResult, $result); 105 | } 106 | 107 | public function testHasCacheableSupportsMethod(): void 108 | { 109 | $this->denormalizer->setDenormalizer($this->inner); 110 | 111 | $result = $this->denormalizer->hasCacheableSupportsMethod(); 112 | $this->assertFalse($result); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /tests/Impl/Serializer/V3/FacadeDocBodyResponseBodyDenormalizerTest.php: -------------------------------------------------------------------------------- 1 | inner = $this->createMock(SerializerDenormalizer::class); 28 | $this->denormalizer = new FacadeDocBodyResponseBodyDenormalizer(); 29 | } 30 | 31 | /** 32 | * @dataProvider dataSupportsDenormalization 33 | */ 34 | public function testSupportsDenormalization(string $type, array $data, bool $expected): void 35 | { 36 | $result = $this->denormalizer->supportsDenormalization($data, $type); 37 | 38 | $this->assertEquals($expected, $result); 39 | } 40 | 41 | public function dataSupportsDenormalization(): array 42 | { 43 | return [ 44 | [ 45 | Body::class, 46 | [ 47 | 'original_string' => 'foobar', 48 | ], 49 | false, 50 | ], 51 | [ 52 | Body::class, 53 | [], 54 | true, 55 | ], 56 | [ 57 | \stdClass::class, 58 | [], 59 | false, 60 | ], 61 | ]; 62 | } 63 | 64 | public function testDenormalizeWithDenormalizerIsNotSet(): void 65 | { 66 | $this->expectException(BadMethodCallException::class); 67 | $this->denormalizer->denormalize([], Body::class); 68 | } 69 | 70 | public function testDenormalizeWithWrongData(): void 71 | { 72 | $this->denormalizer->setDenormalizer($this->inner); 73 | 74 | $this->expectException(InvalidArgumentException::class); 75 | $this->denormalizer->denormalize('wrong', Body::class); 76 | } 77 | 78 | public function testDenormalizeWithWrongType(): void 79 | { 80 | $this->denormalizer->setDenormalizer($this->inner); 81 | 82 | $this->expectException(InvalidArgumentException::class); 83 | $this->denormalizer->denormalize([], \stdClass::class); 84 | } 85 | 86 | public function testSetDenormalizerWithNoSerializer(): void 87 | { 88 | $this->expectException(InvalidArgumentException::class); 89 | $this->denormalizer->setDenormalizer($this->createMock(DenormalizerInterface::class)); 90 | } 91 | 92 | public function testDenormalize(): void 93 | { 94 | $this->denormalizer->setDenormalizer($this->inner); 95 | 96 | $originalBodyData = [ 97 | 'some_new_crpt_field' => true, 98 | 'document_description' => 'description', 99 | 'products' => [ 100 | [ 101 | 'uit_code' => '010464005741102021PMRanDom32406404', 102 | 'product_cost' => 42, 103 | 'product_tax' => 1.1, 104 | 'product_description' => 'product description 2' 105 | ], 106 | [ 107 | 'uit_code' => '010RanDom463007357256021c140640422', 108 | 'product_cost' => 42, 109 | 'product_tax' => 1.1, 110 | 'product_description' => 'product description 2' 111 | ], 112 | ] 113 | ]; 114 | $expectedResult = new Body(); 115 | $property = new \ReflectionProperty(Body::class, 'originalString'); 116 | $property->setAccessible(true); 117 | $property->setValue($expectedResult, json_encode($originalBodyData)); 118 | $property = new \ReflectionProperty(Body::class, 'documentDescription'); 119 | $property->setAccessible(true); 120 | $property->setValue($expectedResult, 'description'); 121 | 122 | $this->inner->expects($this->once()) 123 | ->method('serialize') 124 | ->with($originalBodyData, null, []) 125 | ->willReturn($originalBodyData); 126 | $enrichedOriginalBodyData = array_merge($originalBodyData, ['original_string' => $originalBodyData]); 127 | $this->inner->expects($this->once()) 128 | ->method('denormalize') 129 | ->with($enrichedOriginalBodyData, Body::class, null, []) 130 | ->willReturn($expectedResult); 131 | 132 | $result = $this->denormalizer->denormalize( 133 | $originalBodyData, 134 | Body::class 135 | ); 136 | 137 | $this->assertEquals($expectedResult, $result); 138 | } 139 | 140 | public function testHasCacheableSupportsMethod(): void 141 | { 142 | $this->denormalizer->setDenormalizer($this->inner); 143 | 144 | $result = $this->denormalizer->hasCacheableSupportsMethod(); 145 | $this->assertFalse($result); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/Impl/Serializer/V3/SymfonySerializerAdapterTest.php: -------------------------------------------------------------------------------- 1 | serializer = SymfonySerializerAdapterFactory::create(); 29 | } 30 | 31 | /** 32 | * @dataProvider dataDeserialize 33 | */ 34 | public function testDeserialize(string $class, string $data, object $expected): void 35 | { 36 | $result = $this->serializer->deserialize($class, $data); 37 | 38 | $this->assertEquals($expected, $result); 39 | } 40 | 41 | public function dataDeserialize(): array 42 | { 43 | return [ 44 | [ 45 | AuthCertResponse::class, 46 | json_encode( 47 | [ 48 | 'token' => 'test_token', 49 | ] 50 | ), 51 | new AuthCertResponse( 52 | 'test_token' 53 | ), 54 | ], 55 | [ 56 | FacadeDocListV2Response::class, 57 | json_encode( 58 | [ 59 | 'total' => 25, 60 | 'results' => [ 61 | [ 62 | 'number' => 'b917dfb0-523d-41e0-9e64-e8bf0052c5bd', 63 | 'docDate' => '2019-01-18T06:45:35.630Z', 64 | 'receivedAt' => '2019-01-19T06:45:35.630Z', 65 | 'type' => 'LP_INTRODUCE_GOODS', 66 | 'status' => 'CHECKED_OK', 67 | 'senderName' => 'test', 68 | ], 69 | ], 70 | ] 71 | ), 72 | new FacadeDocListV2Response( 73 | 25, 74 | [ 75 | (new FacadeDocListV2ItemResponse( 76 | 'b917dfb0-523d-41e0-9e64-e8bf0052c5bd', 77 | '2019-01-18T06:45:35.630Z', 78 | '2019-01-19T06:45:35.630Z' 79 | ))->setType('LP_INTRODUCE_GOODS') 80 | ->setStatus('CHECKED_OK') 81 | ->setSenderName('test') 82 | ] 83 | ), 84 | ], 85 | 'agent item' => [ 86 | FacadeMarkedProductsResponse::class, 87 | json_encode( 88 | [ 89 | 'cis' => '010290000021360921&XjcbJ.KYB+pT', 90 | 'gtin' => '02900000213609', 91 | 'sgtin' => '&XjcbJ.KYB+pT', 92 | 'producerName' => 'ООО "ОБУВЬОПТ"', 93 | 'producerInn' => '7731362094', 94 | 'ownerName' => 'ООО "ОБУВЬОПТ"', 95 | 'ownerInn' => '7731362094', 96 | 'agentName' => 'ООО "Купишуз"', 97 | 'agentInn' => '7705935687', 98 | 'emissionDate' => '2020-01-21T13:04:54.416Z', 99 | 'introducedDate' => '2020-01-31T18:11:15.139Z', 100 | 'emissionType' => 'REMAINS', 101 | 'lastDocId' => '6e71f305-1ee4-4f1c-92ab-4a69f5bb7bf8', 102 | 'prevCises' => [], 103 | 'nextCises' => [], 104 | 'status' => 'INTRODUCED', 105 | 'countChildren' => 0, 106 | 'packType' => 'UNIT' 107 | ] 108 | ), 109 | (new FacadeMarkedProductsResponse( 110 | '010290000021360921&XjcbJ.KYB+pT', 111 | '02900000213609', 112 | '&XjcbJ.KYB+pT', 113 | 'ООО "ОБУВЬОПТ"', 114 | '7731362094', 115 | 'INTRODUCED', 116 | '2020-01-21T13:04:54.416Z', 117 | 'REMAINS', 118 | [], 119 | [], 120 | 'UNIT', 121 | 0 122 | )) 123 | ->setOwnerInn('7731362094') 124 | ->setOwnerName('ООО "ОБУВЬОПТ"') 125 | ->setAgentName('ООО "Купишуз"') 126 | ->setAgentInn('7705935687') 127 | ->setLastDocId('6e71f305-1ee4-4f1c-92ab-4a69f5bb7bf8') 128 | ->setIntroducedDate('2020-01-31T18:11:15.139Z') 129 | ], 130 | [ 131 | FacadeMarkedProductsResponse::class, 132 | json_encode( 133 | [ 134 | 'cis' => "010463007034375021UptR1qHZW6\"B'", 135 | 'gtin' => '04630070343750', 136 | 'sgtin' => "UptR1qHZW6\"B'", 137 | 'productName' => 'Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380', 138 | 'producerName' => 'ООО "Купишуз"', 139 | 'producerInn' => '7705935687', 140 | 'ownerName' => 'ООО "Купишуз"', 141 | 'ownerInn' => '7705935687', 142 | 'emissionDate' => '2020-02-17T07:48:13.797Z', 143 | 'emissionType' => 'FOREIGN', 144 | 'name' => 'Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380', 145 | 'brand' => 'Chiara Ferragni Collection', 146 | 'model' => 'CF2612', 147 | 'prevCises' => [], 148 | 'nextCises' => [], 149 | 'status' => 'APPLIED', 150 | 'countChildren' => 0, 151 | 'packType' => 'UNIT', 152 | 'country' => 'ИТАЛИЯ', 153 | 'productTypeDesc' => 'КЕДЫ', 154 | 'color' => '005', 155 | 'materialDown' => '100 - резина', 156 | 'materialUpper' => '100 - натуральная кожа', 157 | 'goodSignedFlag' => 'true', 158 | 'materialLining' => '100 - натуральная кожа', 159 | 'goodTurnFlag' => 'true', 160 | 'goodMarkFlag' => 'true' 161 | ] 162 | ), 163 | (new FacadeMarkedProductsResponse( 164 | "010463007034375021UptR1qHZW6\"B'", 165 | '04630070343750', 166 | "UptR1qHZW6\"B'", 167 | 'ООО "Купишуз"', 168 | '7705935687', 169 | 'APPLIED', 170 | '2020-02-17T07:48:13.797Z', 171 | 'FOREIGN', 172 | [], 173 | [], 174 | 'UNIT', 175 | 0 176 | )) 177 | ->setOwnerInn('7705935687') 178 | ->setOwnerName('ООО "Купишуз"') 179 | ->setProductName('Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380') 180 | ->setName('Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380') 181 | ->setBrand('Chiara Ferragni Collection') 182 | ->setModel('CF2612') 183 | ->setCountry('ИТАЛИЯ') 184 | ->setProductTypeDesc('КЕДЫ') 185 | ->setColor('005') 186 | ->setMaterialDown('100 - резина') 187 | ->setMaterialUpper('100 - натуральная кожа') 188 | ->setMaterialLining('100 - натуральная кожа') 189 | ->setGoodSignedFlag('true') 190 | ->setGoodTurnFlag('true') 191 | ->setGoodMarkFlag('true') 192 | ], 193 | ]; 194 | } 195 | 196 | /** 197 | * @dataProvider dataSerialize 198 | */ 199 | public function testSerialize(object $data, string $expected): void 200 | { 201 | $result = $this->serializer->serialize($data); 202 | 203 | $this->assertJsonStringEqualsJsonString($expected, $result); 204 | } 205 | 206 | public function dataSerialize(): array 207 | { 208 | return [ 209 | [ 210 | new AuthCertRequest( 211 | 'uuid_value', 212 | 'data_value' 213 | ), 214 | <<expectException(IsmpSerializerErrorException::class); 228 | 229 | $this->serializer->deserialize('NOT_A_CLASS', null); 230 | } 231 | 232 | public function testSerializeError(): void 233 | { 234 | $this->expectException(IsmpSerializerErrorException::class); 235 | 236 | $this->serializer->serialize(new class { 237 | public function getProperty(): string 238 | { 239 | throw new \Exception(); 240 | } 241 | }); 242 | } 243 | } 244 | -------------------------------------------------------------------------------- /tests/Impl/Serializer/V4/FacadeCisListResponseDenormalizerTest.php: -------------------------------------------------------------------------------- 1 | inner = $this->createMock(DenormalizerInterface::class); 30 | $this->denormalizer = new FacadeCisListResponseDenormalizer(); 31 | } 32 | 33 | /** 34 | * @dataProvider dataSupportsDenormalization 35 | */ 36 | public function testSupportsDenormalization(string $type, bool $expected): void 37 | { 38 | $result = $this->denormalizer->supportsDenormalization([], $type); 39 | 40 | $this->assertEquals($expected, $result); 41 | } 42 | 43 | public function dataSupportsDenormalization(): array 44 | { 45 | return [ 46 | [ 47 | FacadeCisListResponse::class, 48 | true, 49 | ], 50 | [ 51 | \stdClass::class, 52 | false, 53 | ], 54 | ]; 55 | } 56 | 57 | public function testDenormalizationWhenDenormalizerIsNotSet(): void 58 | { 59 | $this->expectException(BadMethodCallException::class); 60 | $this->denormalizer->denormalize([], FacadeCisListResponse::class); 61 | } 62 | 63 | public function testDenormalizationWhenWrongData(): void 64 | { 65 | $this->denormalizer->setDenormalizer($this->inner); 66 | 67 | $this->expectException(InvalidArgumentException::class); 68 | $this->denormalizer->denormalize('wrong', FacadeCisListResponse::class); 69 | } 70 | 71 | public function testDenormalizationWhenWrongType(): void 72 | { 73 | $this->denormalizer->setDenormalizer($this->inner); 74 | 75 | $this->expectException(InvalidArgumentException::class); 76 | $this->denormalizer->denormalize([], \stdClass::class); 77 | } 78 | 79 | public function testDenormalizationWorks(): void 80 | { 81 | $this->denormalizer->setDenormalizer($this->inner); 82 | 83 | $item1 = new FacadeCisItemResponse(); 84 | $item1->setCis('cis1'); 85 | $item1->setCertDoc([ 86 | 'type' => 'SOME_CERTIFICATE', 87 | 'number' => '000001', 88 | 'date' => '2021-08-24', 89 | ]); 90 | $item2 = new FacadeCisItemResponse(); 91 | $item2->setCis('cis2'); 92 | $item2->setCertDoc([ 93 | 'type' => 'SOME_CERTIFICATE', 94 | 'number' => '000002', 95 | 'date' => '2021-08-24', 96 | ]); 97 | 98 | $expectedResult = new FacadeCisListResponse($item1, $item2); 99 | 100 | $this->inner->expects($this->exactly(2)) 101 | ->method('denormalize') 102 | ->withConsecutive( 103 | ['first', FacadeCisItemResponse::class, null, []], 104 | ['second', FacadeCisItemResponse::class, null, []] 105 | ) 106 | ->willReturnOnConsecutiveCalls( 107 | $item1, 108 | $item2 109 | ); 110 | 111 | $result = $this->denormalizer->denormalize([ 112 | 'first', 113 | 'second', 114 | ], FacadeCisListResponse::class); 115 | 116 | $this->assertEquals($expectedResult, $result); 117 | } 118 | 119 | public function testHasCacheableSupportsMethod(): void 120 | { 121 | $this->denormalizer->setDenormalizer($this->inner); 122 | 123 | $result = $this->denormalizer->hasCacheableSupportsMethod(); 124 | $this->assertFalse($result); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /tests/Impl/Serializer/V4/FacadeDocBodyResponseBodyDenormalizerTest.php: -------------------------------------------------------------------------------- 1 | inner = $this->createMock(SerializerDenormalizer::class); 28 | $this->denormalizer = new FacadeDocBodyResponseBodyDenormalizer(); 29 | } 30 | 31 | /** 32 | * @dataProvider dataSupportsDenormalization 33 | */ 34 | public function testSupportsDenormalization(string $type, array $data, bool $expected): void 35 | { 36 | $result = $this->denormalizer->supportsDenormalization($data, $type); 37 | 38 | $this->assertEquals($expected, $result); 39 | } 40 | 41 | public function dataSupportsDenormalization(): array 42 | { 43 | return [ 44 | [ 45 | Body::class, 46 | [ 47 | 'original_string' => 'foobar', 48 | ], 49 | false, 50 | ], 51 | [ 52 | Body::class, 53 | [], 54 | true, 55 | ], 56 | [ 57 | \stdClass::class, 58 | [], 59 | false, 60 | ], 61 | ]; 62 | } 63 | 64 | public function testDenormalizeWithDenormalizerIsNotSet(): void 65 | { 66 | $this->expectException(BadMethodCallException::class); 67 | $this->denormalizer->denormalize([], Body::class); 68 | } 69 | 70 | public function testDenormalizeWithWrongData(): void 71 | { 72 | $this->denormalizer->setDenormalizer($this->inner); 73 | 74 | $this->expectException(InvalidArgumentException::class); 75 | $this->denormalizer->denormalize('wrong', Body::class); 76 | } 77 | 78 | public function testDenormalizeWithWrongType(): void 79 | { 80 | $this->denormalizer->setDenormalizer($this->inner); 81 | 82 | $this->expectException(InvalidArgumentException::class); 83 | $this->denormalizer->denormalize([], \stdClass::class); 84 | } 85 | 86 | public function testSetDenormalizerWithNoSerializer(): void 87 | { 88 | $this->expectException(InvalidArgumentException::class); 89 | $this->denormalizer->setDenormalizer($this->createMock(DenormalizerInterface::class)); 90 | } 91 | 92 | public function testDenormalize(): void 93 | { 94 | $this->denormalizer->setDenormalizer($this->inner); 95 | 96 | $originalBodyData = [ 97 | 'some_new_crpt_field' => true, 98 | 'document_description' => 'description', 99 | 'products' => [ 100 | [ 101 | 'uit_code' => '010464005741102021PMRanDom32406404', 102 | 'product_cost' => 42, 103 | 'product_tax' => 1.1, 104 | 'product_description' => 'product description 2' 105 | ], 106 | [ 107 | 'uit_code' => '010RanDom463007357256021c140640422', 108 | 'product_cost' => 42, 109 | 'product_tax' => 1.1, 110 | 'product_description' => 'product description 2' 111 | ], 112 | ] 113 | ]; 114 | $expectedResult = new Body(); 115 | $property = new \ReflectionProperty(Body::class, 'originalString'); 116 | $property->setAccessible(true); 117 | $property->setValue($expectedResult, json_encode($originalBodyData)); 118 | $property = new \ReflectionProperty(Body::class, 'documentDescription'); 119 | $property->setAccessible(true); 120 | $property->setValue($expectedResult, 'description'); 121 | 122 | $this->inner->expects($this->once()) 123 | ->method('serialize') 124 | ->with($originalBodyData, null, []) 125 | ->willReturn($originalBodyData); 126 | $enrichedOriginalBodyData = array_merge($originalBodyData, ['original_string' => $originalBodyData]); 127 | $this->inner->expects($this->once()) 128 | ->method('denormalize') 129 | ->with($enrichedOriginalBodyData, Body::class, null, []) 130 | ->willReturn($expectedResult); 131 | 132 | $result = $this->denormalizer->denormalize( 133 | $originalBodyData, 134 | Body::class 135 | ); 136 | 137 | $this->assertEquals($expectedResult, $result); 138 | } 139 | 140 | public function testHasCacheableSupportsMethod(): void 141 | { 142 | $this->denormalizer->setDenormalizer($this->inner); 143 | 144 | $result = $this->denormalizer->hasCacheableSupportsMethod(); 145 | $this->assertFalse($result); 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /tests/Impl/Serializer/V4/SymfonySerializerAdapterTest.php: -------------------------------------------------------------------------------- 1 | serializer = SymfonySerializerAdapterFactory::create(); 29 | } 30 | 31 | /** 32 | * @dataProvider dataDeserialize 33 | */ 34 | public function testDeserialize(string $class, string $data, object $expected): void 35 | { 36 | $result = $this->serializer->deserialize($class, $data); 37 | 38 | $this->assertEquals($expected, $result); 39 | } 40 | 41 | public function dataDeserialize(): array 42 | { 43 | return [ 44 | [ 45 | AuthCertResponse::class, 46 | json_encode( 47 | [ 48 | 'token' => 'test_token', 49 | ] 50 | ), 51 | new AuthCertResponse('test_token'), 52 | ], 53 | [ 54 | FacadeDocListV2Response::class, 55 | json_encode( 56 | [ 57 | 'total' => 25, 58 | 'results' => [ 59 | [ 60 | 'number' => 'b917dfb0-523d-41e0-9e64-e8bf0052c5bd', 61 | 'docDate' => '2019-01-18T06:45:35.630Z', 62 | 'receivedAt' => '2019-01-19T06:45:35.630Z', 63 | 'type' => 'LP_INTRODUCE_GOODS', 64 | 'status' => 'CHECKED_OK', 65 | 'senderName' => 'test', 66 | ], 67 | ], 68 | ] 69 | ), 70 | new FacadeDocListV2Response( 71 | 25, 72 | [ 73 | (new FacadeDocListV2ItemResponse( 74 | 'b917dfb0-523d-41e0-9e64-e8bf0052c5bd', 75 | '2019-01-18T06:45:35.630Z', 76 | '2019-01-19T06:45:35.630Z' 77 | ))->setType('LP_INTRODUCE_GOODS') 78 | ->setStatus('CHECKED_OK') 79 | ->setSenderName('test') 80 | ] 81 | ), 82 | ], 83 | 'agent item' => [ 84 | FacadeMarkedProductsResponse::class, 85 | json_encode( 86 | [ 87 | 'cis' => '010290000021360921&XjcbJ.KYB+pT', 88 | 'gtin' => '02900000213609', 89 | 'sgtin' => '&XjcbJ.KYB+pT', 90 | 'producerName' => 'ООО "ОБУВЬОПТ"', 91 | 'producerInn' => '7731362094', 92 | 'ownerName' => 'ООО "ОБУВЬОПТ"', 93 | 'ownerInn' => '7731362094', 94 | 'agentName' => 'ООО "Купишуз"', 95 | 'agentInn' => '7705935687', 96 | 'emissionDate' => '2020-01-21T13:04:54.416Z', 97 | 'introducedDate' => '2020-01-31T18:11:15.139Z', 98 | 'emissionType' => 'REMAINS', 99 | 'lastDocId' => '6e71f305-1ee4-4f1c-92ab-4a69f5bb7bf8', 100 | 'prevCises' => [], 101 | 'nextCises' => [], 102 | 'status' => 'INTRODUCED', 103 | 'countChildren' => 0, 104 | 'packType' => 'UNIT' 105 | ] 106 | ), 107 | (new FacadeMarkedProductsResponse( 108 | '010290000021360921&XjcbJ.KYB+pT', 109 | '02900000213609', 110 | '&XjcbJ.KYB+pT', 111 | 'ООО "ОБУВЬОПТ"', 112 | '7731362094', 113 | 'INTRODUCED', 114 | '2020-01-21T13:04:54.416Z', 115 | 'REMAINS', 116 | [], 117 | [], 118 | 'UNIT', 119 | 0 120 | )) 121 | ->setOwnerInn('7731362094') 122 | ->setOwnerName('ООО "ОБУВЬОПТ"') 123 | ->setAgentName('ООО "Купишуз"') 124 | ->setAgentInn('7705935687') 125 | ->setLastDocId('6e71f305-1ee4-4f1c-92ab-4a69f5bb7bf8') 126 | ->setIntroducedDate('2020-01-31T18:11:15.139Z') 127 | ], 128 | [ 129 | FacadeMarkedProductsResponse::class, 130 | json_encode( 131 | [ 132 | 'cis' => "010463007034375021UptR1qHZW6\"B'", 133 | 'gtin' => '04630070343750', 134 | 'sgtin' => "UptR1qHZW6\"B'", 135 | 'productName' => 'Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380', 136 | 'producerName' => 'ООО "Купишуз"', 137 | 'producerInn' => '7705935687', 138 | 'ownerName' => 'ООО "Купишуз"', 139 | 'ownerInn' => '7705935687', 140 | 'emissionDate' => '2020-02-17T07:48:13.797Z', 141 | 'emissionType' => 'FOREIGN', 142 | 'name' => 'Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380', 143 | 'brand' => 'Chiara Ferragni Collection', 144 | 'model' => 'CF2612', 145 | 'prevCises' => [], 146 | 'nextCises' => [], 147 | 'status' => 'APPLIED', 148 | 'countChildren' => 0, 149 | 'packType' => 'UNIT', 150 | 'country' => 'ИТАЛИЯ', 151 | 'productTypeDesc' => 'КЕДЫ', 152 | 'color' => '005', 153 | 'materialDown' => '100 - резина', 154 | 'materialUpper' => '100 - натуральная кожа', 155 | 'goodSignedFlag' => 'true', 156 | 'materialLining' => '100 - натуральная кожа', 157 | 'goodTurnFlag' => 'true', 158 | 'goodMarkFlag' => 'true' 159 | ] 160 | ), 161 | (new FacadeMarkedProductsResponse( 162 | "010463007034375021UptR1qHZW6\"B'", 163 | '04630070343750', 164 | "UptR1qHZW6\"B'", 165 | 'ООО "Купишуз"', 166 | '7705935687', 167 | 'APPLIED', 168 | '2020-02-17T07:48:13.797Z', 169 | 'FOREIGN', 170 | [], 171 | [], 172 | 'UNIT', 173 | 0 174 | )) 175 | ->setOwnerInn('7705935687') 176 | ->setOwnerName('ООО "Купишуз"') 177 | ->setProductName('Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380') 178 | ->setName('Жен Полуботинки кроссовые типа кеды 005 модель CF2612 размер производителя 38 EUR, российский 37 код в учетной системе CH057AWHPGH0E380') 179 | ->setBrand('Chiara Ferragni Collection') 180 | ->setModel('CF2612') 181 | ->setCountry('ИТАЛИЯ') 182 | ->setProductTypeDesc('КЕДЫ') 183 | ->setColor('005') 184 | ->setMaterialDown('100 - резина') 185 | ->setMaterialUpper('100 - натуральная кожа') 186 | ->setMaterialLining('100 - натуральная кожа') 187 | ->setGoodSignedFlag('true') 188 | ->setGoodTurnFlag('true') 189 | ->setGoodMarkFlag('true') 190 | ], 191 | ]; 192 | } 193 | 194 | /** 195 | * @dataProvider dataSerialize 196 | */ 197 | public function testSerialize(object $data, string $expected): void 198 | { 199 | $result = $this->serializer->serialize($data); 200 | 201 | $this->assertJsonStringEqualsJsonString($expected, $result); 202 | } 203 | 204 | public function dataSerialize(): array 205 | { 206 | return [ 207 | [ 208 | new AuthCertRequest( 209 | 'uuid_value', 210 | 'data_value' 211 | ), 212 | <<expectException(IsmpSerializerErrorException::class); 226 | 227 | $this->serializer->deserialize('NOT_A_CLASS', null); 228 | } 229 | 230 | public function testSerializeError(): void 231 | { 232 | $this->expectException(IsmpSerializerErrorException::class); 233 | 234 | $this->serializer->serialize(new class { 235 | public function getProperty(): string 236 | { 237 | throw new \Exception(); 238 | } 239 | }); 240 | } 241 | } 242 | -------------------------------------------------------------------------------- /tests/Stub/SerializerDenormalizer.php: -------------------------------------------------------------------------------- 1 | model = (new FacadeDocListV2ItemResponse( 20 | 'document_number_1', 21 | '2019-12-02T13:54:41.566Z', 22 | '2019-12-03T13:54:41.566Z' 23 | )) 24 | ->setType('LP_SHIP_GOODS') 25 | ->setStatus('WAIT_ACCEPTANCE') 26 | ->setSenderName('ООО "ТАПИБУ"'); 27 | } 28 | 29 | public function testGetReceivedAtDateTime(): void 30 | { 31 | $result = $this->model->getReceivedAtDateTime(); 32 | 33 | $this->assertEquals(new \DateTimeImmutable('2019-12-03T13:54:41.566Z'), $result); 34 | } 35 | 36 | public function testGetDocDateDateTime(): void 37 | { 38 | $result = $this->model->getDocDateDateTime(); 39 | 40 | $this->assertEquals(new \DateTimeImmutable('2019-12-02T13:54:41.566Z'), $result); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/V3/Dto/FacadeDocListV2QueryTest.php: -------------------------------------------------------------------------------- 1 | assertSame($expected, $query->toQueryArray()); 18 | } 19 | 20 | public function dataToQueryArray(): iterable 21 | { 22 | $query = new FacadeDocListV2Query(); 23 | yield 'query without parameters' => [ 24 | 'query' => $query, 25 | 'expected' => ['limit' => 10], 26 | ]; 27 | 28 | $dateTests = [ 29 | 'DateTime in UTC timezone' => [ 30 | new \DateTime('2019-12-16 18:45:11', new \DateTimeZone('UTC')), 31 | '2019-12-16T18:45:11.000+00:00', 32 | ], 33 | 'DateTimeImmutable in custom timezone' => [ 34 | new \DateTimeImmutable('2019-12-16 18:45:11', new \DateTimeZone('Europe/Moscow')), 35 | '2019-12-16T18:45:11.000+03:00', 36 | ], 37 | ]; 38 | 39 | foreach ($dateTests as $name => [$date, $expected]) { 40 | $query = new FacadeDocListV2Query(); 41 | $query->setDateFrom($date); 42 | yield 'dateFrom: ' . $name => [ 43 | 'query' => $query, 44 | 'expected' => ['dateFrom' => $expected, 'limit' => 10], 45 | ]; 46 | 47 | $query = new FacadeDocListV2Query(); 48 | $query->setDateTo($date); 49 | yield 'dateTo: ' . $name => [ 50 | 'query' => $query, 51 | 'expected' => ['dateTo' => $expected, 'limit' => 10], 52 | ]; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/V4/IsmpApiTest.php: -------------------------------------------------------------------------------- 1 | client = $this->createMock(ClientInterface::class); 58 | $this->serializer = $this->createMock(SerializerInterface::class); 59 | 60 | $this->api = new IsmpApi( 61 | $this->client, 62 | $this->serializer 63 | ); 64 | } 65 | 66 | public function testExceptionWithHttpCode(): void 67 | { 68 | $this->client 69 | ->method('request') 70 | ->willThrowException(new BadResponseException('Bad response', $this->createMock(RequestInterface::class))); 71 | 72 | $this->expectException(IsmpRequestErrorException::class); 73 | $this->api->authCertKey(); 74 | } 75 | 76 | public function testGeneralException(): void 77 | { 78 | $this->client 79 | ->method('request') 80 | ->willThrowException(new \RuntimeException()); 81 | 82 | $this->expectException(IsmpGeneralErrorException::class); 83 | $this->api->authCertKey(); 84 | } 85 | 86 | public function testAuthCertKey(): void 87 | { 88 | $expectedResult = new AuthCertKeyResponse(self::UUID, self::RANDOM_DATA); 89 | 90 | $this->serializer 91 | ->method('deserialize') 92 | ->with( 93 | get_class($expectedResult), 94 | self::API_RESPONSE 95 | ) 96 | ->willReturn($expectedResult); 97 | 98 | $this->client->expects($this->once()) 99 | ->method('request') 100 | ->with( 101 | 'GET', 102 | 'api/v3/auth/cert/key', 103 | [ 104 | RequestOptions::BODY => null, 105 | RequestOptions::HEADERS => [ 106 | 'Content-Type' => 'application/json', 107 | ], 108 | RequestOptions::HTTP_ERRORS => true, 109 | RequestOptions::QUERY => null, 110 | ] 111 | ) 112 | ->willReturn( 113 | (new Response()) 114 | ->withBody(stream_for(self::API_RESPONSE)) 115 | ); 116 | 117 | $result = $this->api->authCertKey(); 118 | 119 | $this->assertEquals($expectedResult, $result); 120 | } 121 | 122 | /** 123 | * @dataProvider provideTestAuthCertData 124 | * @param AuthCertRequest $request 125 | * @param string|null $connection 126 | * @param AuthCertResponse $expectedResult 127 | */ 128 | public function testAuthCert( 129 | AuthCertRequest $request, 130 | ?string $connection, 131 | AuthCertResponse $expectedResult 132 | ): void { 133 | $this->serializer 134 | ->method('serialize') 135 | ->with($request) 136 | ->willReturn(self::SERIALIZED_VALUE); 137 | 138 | $this->serializer 139 | ->method('deserialize') 140 | ->with( 141 | get_class($expectedResult), 142 | self::API_RESPONSE 143 | ) 144 | ->willReturn($expectedResult); 145 | 146 | $this->client->expects($this->once()) 147 | ->method('request') 148 | ->with( 149 | 'POST', 150 | sprintf('api/v3/auth/cert/%s', $connection), 151 | [ 152 | RequestOptions::BODY => self::SERIALIZED_VALUE, 153 | RequestOptions::HEADERS => [ 154 | 'Content-Type' => 'application/json', 155 | ], 156 | RequestOptions::HTTP_ERRORS => true, 157 | RequestOptions::QUERY => null, 158 | ] 159 | ) 160 | ->willReturn( 161 | (new Response()) 162 | ->withBody(stream_for(self::API_RESPONSE)) 163 | ); 164 | 165 | $result = $this->api->authCert($request, $connection); 166 | 167 | $this->assertEquals($expectedResult, $result); 168 | } 169 | 170 | public function provideTestAuthCertData(): iterable 171 | { 172 | yield 'Without connection' => [ 173 | $request = new AuthCertRequest(self::UUID, self::RANDOM_DATA), 174 | null, 175 | $response = new AuthCertResponse('token-value') 176 | ]; 177 | 178 | yield 'With connection' => [ 179 | $request, 180 | 'connection', 181 | $response 182 | ]; 183 | } 184 | 185 | public function testFacadeDocListV2(): void 186 | { 187 | $query = new FacadeDocListV2Query(); 188 | $query->setDocumentStatus(FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK); 189 | $query->setDateFrom(new \DateTimeImmutable('2019-01-01 11:12:13', new \DateTimeZone('UTC'))); 190 | $expectedResult = new FacadeDocListV2Response(0); 191 | 192 | $this->serializer 193 | ->method('deserialize') 194 | ->with( 195 | get_class($expectedResult), 196 | self::API_RESPONSE 197 | ) 198 | ->willReturn($expectedResult); 199 | 200 | $this->client->expects($this->once()) 201 | ->method('request') 202 | ->with( 203 | 'GET', 204 | 'api/v3/facade/doc/listV2', 205 | [ 206 | RequestOptions::BODY => null, 207 | RequestOptions::HEADERS => [ 208 | 'Content-Type' => 'application/json', 209 | 'Authorization' => 'Bearer ' . self::TOKEN, 210 | ], 211 | RequestOptions::HTTP_ERRORS => true, 212 | RequestOptions::QUERY => [ 213 | 'documentStatus' => FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK, 214 | 'dateFrom' => '2019-01-01T11:12:13.000+00:00', 215 | 'limit' => $query->getLimit(), 216 | ], 217 | ] 218 | ) 219 | ->willReturn( 220 | (new Response()) 221 | ->withBody(stream_for(self::API_RESPONSE)) 222 | ); 223 | 224 | $result = $this->api->facadeDocListV2(self::TOKEN, $query); 225 | 226 | $this->assertEquals($expectedResult, $result); 227 | } 228 | 229 | /** 230 | * @dataProvider provideTestFacadeDocBodyData 231 | */ 232 | public function testFacadeDocBody( 233 | ?int $limitOption, 234 | ?string $orderColumnOption, 235 | ?string $orderedColumnValueOption, 236 | ?string $pageDirOption, 237 | array $expectedOptions 238 | ): void { 239 | $expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test'); 240 | $expectedResult->setCisTotal('100'); 241 | 242 | $this->serializer 243 | ->method('deserialize') 244 | ->with( 245 | get_class($expectedResult), 246 | self::API_RESPONSE 247 | ) 248 | ->willReturn($expectedResult); 249 | 250 | $this->client->expects($this->once()) 251 | ->method('request') 252 | ->with( 253 | 'GET', 254 | sprintf('api/v4/facade/doc/%s/body', self::IDENTITY), 255 | $expectedOptions 256 | ) 257 | ->willReturn( 258 | (new Response()) 259 | ->withBody(stream_for(self::API_RESPONSE)) 260 | ); 261 | 262 | $result = $this->api->facadeDocBody( 263 | self::TOKEN, 264 | self::IDENTITY, 265 | $limitOption, 266 | $orderColumnOption, 267 | $orderedColumnValueOption, 268 | $pageDirOption 269 | ); 270 | 271 | $this->assertEquals($expectedResult, $result); 272 | } 273 | 274 | public function provideTestFacadeDocBodyData(): iterable 275 | { 276 | yield 'all nullable parameters' => [ 277 | null, 278 | null, 279 | null, 280 | null, 281 | [ 282 | RequestOptions::BODY => null, 283 | RequestOptions::HEADERS => [ 284 | 'Content-Type' => 'application/json', 285 | 'Authorization' => 'Bearer ' . self::TOKEN, 286 | ], 287 | RequestOptions::HTTP_ERRORS => true, 288 | RequestOptions::QUERY => null, 289 | ], 290 | ]; 291 | 292 | yield 'only limit' => [ 293 | 1000, 294 | null, 295 | null, 296 | null, 297 | [ 298 | RequestOptions::BODY => null, 299 | RequestOptions::HEADERS => [ 300 | 'Content-Type' => 'application/json', 301 | 'Authorization' => 'Bearer ' . self::TOKEN, 302 | ], 303 | RequestOptions::HTTP_ERRORS => true, 304 | RequestOptions::QUERY => [ 305 | 'limit' => 1000, 306 | ], 307 | ], 308 | ]; 309 | 310 | yield 'only order column option' => [ 311 | null, 312 | 'order-column', 313 | null, 314 | null, 315 | [ 316 | RequestOptions::BODY => null, 317 | RequestOptions::HEADERS => [ 318 | 'Content-Type' => 'application/json', 319 | 'Authorization' => 'Bearer ' . self::TOKEN, 320 | ], 321 | RequestOptions::HTTP_ERRORS => true, 322 | RequestOptions::QUERY => [ 323 | 'orderColumn' => 'order-column', 324 | ], 325 | ], 326 | ]; 327 | 328 | yield 'only ordered column value option' => [ 329 | null, 330 | null, 331 | 'ordered-column-value', 332 | null, 333 | [ 334 | RequestOptions::BODY => null, 335 | RequestOptions::HEADERS => [ 336 | 'Content-Type' => 'application/json', 337 | 'Authorization' => 'Bearer ' . self::TOKEN, 338 | ], 339 | RequestOptions::HTTP_ERRORS => true, 340 | RequestOptions::QUERY => [ 341 | 'orderedColumnValue' => 'ordered-column-value', 342 | ], 343 | ], 344 | ]; 345 | 346 | yield 'only page dir option' => [ 347 | null, 348 | null, 349 | null, 350 | 'page-dir', 351 | [ 352 | RequestOptions::BODY => null, 353 | RequestOptions::HEADERS => [ 354 | 'Content-Type' => 'application/json', 355 | 'Authorization' => 'Bearer ' . self::TOKEN, 356 | ], 357 | RequestOptions::HTTP_ERRORS => true, 358 | RequestOptions::QUERY => [ 359 | 'pageDir' => 'page-dir' 360 | ], 361 | ], 362 | ]; 363 | 364 | 365 | yield 'all parameters' => [ 366 | 1000, 367 | 'order-column', 368 | 'ordered-column-value', 369 | 'page-dir', 370 | [ 371 | RequestOptions::BODY => null, 372 | RequestOptions::HEADERS => [ 373 | 'Content-Type' => 'application/json', 374 | 'Authorization' => 'Bearer ' . self::TOKEN, 375 | ], 376 | RequestOptions::HTTP_ERRORS => true, 377 | RequestOptions::QUERY => [ 378 | 'limit' => 1000, 379 | 'orderColumn' => 'order-column', 380 | 'orderedColumnValue' => 'ordered-column-value', 381 | 'pageDir' => 'page-dir', 382 | ], 383 | ], 384 | ]; 385 | } 386 | 387 | public function testFacadeCisList(): void 388 | { 389 | $request = new FacadeCisListRequest(self::IDENTITY); 390 | $expectedResult = new FacadeCisListResponse(); 391 | $requestBody = '{"cises": [' . self::IDENTITY . ']}'; 392 | 393 | $this->serializer 394 | ->method('serialize') 395 | ->with($request) 396 | ->willReturn($requestBody); 397 | 398 | $this->serializer 399 | ->method('deserialize') 400 | ->with( 401 | get_class($expectedResult), 402 | self::API_RESPONSE 403 | ) 404 | ->willReturn($expectedResult); 405 | 406 | $this->client->expects($this->once()) 407 | ->method('request') 408 | ->with( 409 | 'POST', 410 | 'api/v4/facade/cis/cis_list', 411 | [ 412 | RequestOptions::BODY => $requestBody, 413 | RequestOptions::HEADERS => [ 414 | 'Content-Type' => 'application/json', 415 | 'Authorization' => 'Bearer ' . self::TOKEN, 416 | ], 417 | RequestOptions::HTTP_ERRORS => true, 418 | RequestOptions::QUERY => null, 419 | ] 420 | ) 421 | ->willReturn( 422 | (new Response()) 423 | ->withBody(stream_for(self::API_RESPONSE)) 424 | ); 425 | 426 | $result = $this->api->facadeCisList(self::TOKEN, $request); 427 | 428 | $this->assertEquals($expectedResult, $result); 429 | } 430 | 431 | public function testLkDocumentsCreate(): void 432 | { 433 | $request = new DocumentCreateRequest( 434 | 'document', 435 | 'MANUAL', 436 | 'signature', 437 | ProductGroup::SHOES, 438 | DocumentLkType::LP_INTRODUCE_GOODS 439 | ); 440 | 441 | $this->serializer 442 | ->method('serialize') 443 | ->with($request) 444 | ->willReturn(self::SERIALIZED_VALUE); 445 | 446 | $this->client->expects($this->once()) 447 | ->method('request') 448 | ->with( 449 | 'POST', 450 | 'api/v3/lk/documents/create', 451 | [ 452 | RequestOptions::BODY => self::SERIALIZED_VALUE, 453 | RequestOptions::HEADERS => [ 454 | 'Content-Type' => 'application/json', 455 | 'Authorization' => 'Bearer ' . self::TOKEN, 456 | ], 457 | RequestOptions::HTTP_ERRORS => true, 458 | RequestOptions::QUERY => ['pg' => ProductGroup::SHOES], 459 | ] 460 | ) 461 | ->willReturn( 462 | (new Response()) 463 | ->withBody(stream_for(self::API_RESPONSE)) 464 | ); 465 | 466 | $result = $this->api->lkDocumentsCreate(self::TOKEN, $request); 467 | 468 | $this->assertEquals(self::API_RESPONSE, $result); 469 | } 470 | 471 | public function testProductInfo(): void 472 | { 473 | $request = ['aaa', 'bbb']; 474 | $expectedResult = new ProductInfoResponse([], 0); 475 | 476 | $this->serializer 477 | ->method('deserialize') 478 | ->with( 479 | get_class($expectedResult), 480 | self::API_RESPONSE 481 | ) 482 | ->willReturn($expectedResult); 483 | 484 | $this->client->expects($this->once()) 485 | ->method('request') 486 | ->with( 487 | 'GET', 488 | 'api/v3/product/info', 489 | [ 490 | RequestOptions::BODY => null, 491 | RequestOptions::HEADERS => [ 492 | 'Content-Type' => 'application/json', 493 | 'Authorization' => 'Bearer ' . self::TOKEN, 494 | ], 495 | RequestOptions::HTTP_ERRORS => true, 496 | RequestOptions::QUERY => [ 497 | 'gtins' => implode(',', $request), 498 | ], 499 | ] 500 | ) 501 | ->willReturn( 502 | (new Response()) 503 | ->withBody(stream_for(self::API_RESPONSE)) 504 | ); 505 | 506 | $result = $this->api->productInfo(self::TOKEN, $request); 507 | 508 | $this->assertEquals($expectedResult, $result); 509 | } 510 | } 511 | --------------------------------------------------------------------------------