├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml └── src ├── CdekClient.php ├── Common ├── AdditionalService.php ├── Address.php ├── Attempt.php ├── Call.php ├── CallCourier.php ├── CallDelay.php ├── CallFail.php ├── CallGood.php ├── ChangePeriod.php ├── City.php ├── Fillable.php ├── Item.php ├── OfficeImage.php ├── Order.php ├── Package.php ├── Pvz.php ├── Reason.php ├── State.php ├── Status.php └── WeightLimit.php ├── Contracts ├── JsonRequest.php ├── ParamRequest.php ├── Request.php ├── ShouldAuthorize.php └── XmlRequest.php ├── LaravelCdekServiceProvider.php ├── Requests ├── CalculationAuthorizedRequest.php ├── CalculationRequest.php ├── Concerns │ ├── Authorized.php │ ├── OrdersAware.php │ └── RequestCore.php ├── DeleteRequest.php ├── DeliveryRequest.php ├── InfoReportRequest.php ├── PrintReceiptsRequest.php ├── PvzListRequest.php └── StatusReportRequest.php ├── Responses ├── CalculationResponse.php ├── DeleteResponse.php ├── DeliveryResponse.php ├── InfoReportResponse.php ├── PrintReceiptsResponse.php ├── PvzListResponse.php ├── StatusReportResponse.php └── Types │ ├── AdditionalService.php │ ├── Error.php │ ├── Message.php │ ├── PrintReceiptsError.php │ └── Result.php └── Serialization └── NullableDateTimeHandler.php /LICENSE: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright © appwilio 4 | Copyright © JhaoDa 5 | Copyright © greabock 6 | 7 | > Permission is hereby granted, free of charge, to any person obtaining a copy 8 | > of this software and associated documentation files (the "Software"), to deal 9 | > in the Software without restriction, including without limitation the rights 10 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | > copies of the Software, and to permit persons to whom the Software is 12 | > furnished to do so, subject to the following conditions: 13 | > 14 | > The above copyright notice and this permission notice shall be included in 15 | > all copies or substantial portions of the Software. 16 | > 17 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | > THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SDK для СДЭК 2 | 3 | [![Total Downloads](https://poser.pugx.org/appwilio/cdek-sdk/downloads)](https://packagist.org/packages/appwilio/cdek-sdk) 4 | [![Latest Stable Version](https://poser.pugx.org/appwilio/cdek-sdk/version)](https://packagist.org/packages/appwilio/cdek-sdk) 5 | [![License](https://poser.pugx.org/appwilio/cdek-sdk/license)](https://packagist.org/packages/appwilio/cdek-sdk) 6 | 7 | ### Это будет самое полное SDK для cdek.ru 8 | 9 | Возможности: 10 | 11 | - :unlock:расчёт стоимости доставки (API калькулятора v1.1) 12 | - :unlock:получение списка пунктов выдачи заказов (ПВЗ) с фильтрацией 13 | - управление заказами 14 | - формирование новых заказов 15 | - генерация квитанции в PDF 16 | - удаление заказов 17 | - получение информации по заказам (отчёт «Информация по заказам») 18 | - трекинг заказов (отчёт «Статусы заказов») 19 | - [ ] прозвон получателя 20 | - [ ] вызов курьера 21 | 22 | > Работа с API возможна только при наличии договора с СДЭК (кроме методов, отмеченных как:unlock:). 23 | 24 | 25 | Существует [хард-форк](https://github.com/sanmai/cdek-sdk) этого SDK — с даунгрейдом до PHP 7.0, большей поддержкой методов API и более полной документацией. Мы планируем сделаем бэкпорт всего этого добра, как только дойдут руки... 26 | 27 | ## Установка 28 | 29 | > Минимальные требования — PHP 7.1+. 30 | 31 | ```bash 32 | composer require appwilio/cdek-sdk 33 | ``` 34 | 35 | ## Конфигурация 36 | 37 | ### Laravel 5.1+ 38 | ```php 39 | // config/app.php 40 | 41 | 'providers' => [ 42 | // ... 43 | 44 | \Appwilio\CdekSDK\LaravelCdekServiceProvider::class 45 | 46 | // ... 47 | ] 48 | 49 | // config/services.php 50 | 51 | 'cdek' => [ 52 | 'account' => env('CDEK_ACCOUNT', ''), 53 | 'password' => env('CDEK_PASSWORD', ''), 54 | 'guzzle_options' => [ // необязательные параметры 55 | 'base_uri' => 'https://integration.cdek-asia.cn', 56 | 'timeout' => 5 57 | ] 58 | ], 59 | ``` 60 | 61 | ### Иные фреймворки/без фреймворка 62 | ```php 63 | require_once '../vendor/autoload.php'; 64 | 65 | \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists'); 66 | 67 | $client = new \Appwilio\CdekSDK\CdekClient('account', 'password', $guzzleOptions = [ 68 | 'timeout' => 5 69 | ]); 70 | ``` 71 | 72 | [Параметры Guzzle](http://docs.guzzlephp.org/en/stable/request-options.html) 73 | 74 | ## Использование 75 | 76 | ### Расчёт стоимости доставки 77 | 78 | ```php 79 | use Appwilio\CdekSDK\Requests\CalculationRequest; 80 | 81 | // для выполнения авторизованного запроса используется 82 | // $request = CalculationRequest::withAuthorization(); 83 | 84 | $request = (new CalculationRequest()) 85 | ->setSenderCityPostCode('295000') 86 | ->setReceiverCityPostCode('652632') 87 | ->addGood([ 88 | 'weight' => 0.2, 89 | 'length' => 10, 90 | 'width' => 10, 91 | 'height' => 10, 92 | ]); 93 | 94 | $response = $client->sendCalculationRequest($request) 95 | ``` 96 | 97 | ### Трекинг 98 | 99 | ```php 100 | use \Appwilio\CdekSDK\Common\Order; 101 | use Appwilio\CdekSDK\Requests\StatusReportRequest; 102 | 103 | $request = (new StatusReportRequest()) 104 | ->setShowHistory(); 105 | 106 | $request->addOrder(new Order(['Number' => '89754564'])); 107 | $request->addOrder(new Order(['DispatchNumber' => '2222222222'])); 108 | 109 | $response = $client->sendStatusReportRequest($request); 110 | ``` 111 | 112 | ## Авторы 113 | 114 | - [greabock](https://github.com/greabock) 115 | - [JhaoDa](https://github.com/jhaoda) 116 | 117 | ## Лицензия 118 | 119 | Данный SDK распространяется под лицензией [MIT](http://opensource.org/licenses/MIT). 120 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "appwilio/cdek-sdk", 3 | "keywords": ["CDEK", "sdk", "delivery"], 4 | "homepage": "https://github.com/appwilio/cdek-sdk", 5 | "description": "CDEK API SDK (cdek.ru)", 6 | "type": "library", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Roman Sokharev", 11 | "email": "greabock17@gmail.com", 12 | "role": "Creator" 13 | }, 14 | { 15 | "name": "JhaoDa", 16 | "email": "jhaoda@gmail.com", 17 | "role": "Developer" 18 | } 19 | ], 20 | "support": { 21 | "email": "jhaoda@gmail.com", 22 | "issues": "https://github.com/appwilio/cdek-sdk/issues" 23 | }, 24 | "require": { 25 | "php": ">=7.1", 26 | "jms/serializer": "^1.8", 27 | "guzzlehttp/guzzle": "^6.3" 28 | }, 29 | "require-dev": { 30 | "phpunit/phpunit": "^6.3", 31 | "illuminate/support": "5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.*" 32 | }, 33 | "autoload": { 34 | "psr-4": { 35 | "Appwilio\\CdekSDK\\": "src/" 36 | } 37 | }, 38 | "scripts": { 39 | "test": "vendor/bin/phpunit" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | tests 15 | 16 | 17 | 18 | 19 | src/ 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/CdekClient.php: -------------------------------------------------------------------------------- 1 | [ 47 | Requests\DeleteRequest::class => Responses\DeleteResponse::class, 48 | Requests\PvzListRequest::class => Responses\PvzListResponse::class, 49 | Requests\DeliveryRequest::class => Responses\DeliveryResponse::class, 50 | Requests\InfoReportRequest::class => Responses\InfoReportResponse::class, 51 | Requests\StatusReportRequest::class => Responses\StatusReportResponse::class, 52 | Requests\PrintReceiptsRequest::class => Responses\PrintReceiptsResponse::class 53 | ], 54 | 'json' => [ 55 | Requests\CalculationRequest::class => Responses\CalculationResponse::class, 56 | Requests\CalculationAuthorizedRequest::class => Responses\CalculationResponse::class, 57 | ], 58 | ]; 59 | 60 | /** @var GuzzleClient */ 61 | private $http; 62 | 63 | /** @var string */ 64 | private $account; 65 | 66 | /** @var string */ 67 | private $password; 68 | 69 | /** @var Serializer */ 70 | private $serializer; 71 | 72 | public function __construct(?string $account = null, ?string $password = null, array $guzzleOptions = []) 73 | { 74 | $this->account = $account; 75 | $this->password = $password; 76 | 77 | $this->http = new GuzzleClient(array_merge([ 78 | 'base_uri' => self::ENDPOINT_URI, 79 | 'timeout' => 10, 80 | ], $guzzleOptions)); 81 | 82 | $this->serializer = SerializerBuilder::create()->configureHandlers(function (HandlerRegistry $registry) { 83 | $registry->registerSubscribingHandler(new NullableDateTimeHandler()); 84 | })->build(); 85 | } 86 | 87 | public function sendRequest(Request $request) 88 | { 89 | if ($request instanceof ShouldAuthorize) { 90 | $date = new \DateTimeImmutable(); 91 | 92 | $request->date($date)->credentials($this->account, $this->getSecure($date)); 93 | } 94 | 95 | $response = $this->http->request( 96 | $request->getMethod(), 97 | $request->getAddress(), 98 | $this->extractOptions($request) 99 | ); 100 | 101 | return $this->deserialize($request, $response); 102 | } 103 | 104 | public function __call($name, $arguments) 105 | { 106 | if (0 === strpos($name, 'send')) { 107 | return $this->sendRequest(...$arguments); 108 | } 109 | 110 | throw new \BadMethodCallException(sprintf('Method [%s] not found in [%s].', $name, __CLASS__)); 111 | } 112 | 113 | private function deserialize(Request $request, ResponseInterface $response) 114 | { 115 | if (! $this->isTextResponse($response)) { 116 | return $response; 117 | } 118 | 119 | $class = \get_class($request); 120 | 121 | foreach ($this->maps as $format => $map) { 122 | if (array_key_exists($class, $map)) { 123 | return $this->serializer->deserialize((string) $response->getBody(), $map[$class], $format); 124 | } 125 | } 126 | 127 | throw new \Exception("Class [$class] not mapped."); 128 | } 129 | 130 | private function getSecure(\DateTimeInterface $date): string 131 | { 132 | return md5($date->format('Y-m-d')."&{$this->password}"); 133 | } 134 | 135 | private function isTextResponse(ResponseInterface $response): bool 136 | { 137 | $header = $response->hasHeader('Content-Type') 138 | ? $response->getHeader('Content-Type')[0] 139 | : ''; 140 | 141 | return 0 === strpos($header, 'text/xml') || 0 === strpos($header, 'application/json'); 142 | } 143 | 144 | private function extractOptions(Request $request): array 145 | { 146 | if ($request instanceof ParamRequest) { 147 | if ($request->getMethod() === 'GET') { 148 | return [ 149 | 'query' => $request->getParams() 150 | ]; 151 | } 152 | 153 | return [ 154 | 'form_params' => $request->getParams() 155 | ]; 156 | } 157 | 158 | if ($request instanceof XmlRequest) { 159 | return [ 160 | 'form_params' => [ 161 | 'xml_request' => $this->serializer->serialize($request, 'xml') 162 | ] 163 | ]; 164 | } 165 | 166 | if ($request instanceof JsonRequest) { 167 | return [ 168 | 'body' => json_encode($request->getBody()), 169 | 'headers' => [ 170 | 'Content-Type' => 'application/json' 171 | ], 172 | ]; 173 | } 174 | 175 | return []; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/Common/AdditionalService.php: -------------------------------------------------------------------------------- 1 | ServiceCode; 43 | } 44 | 45 | public function getSum(): float 46 | { 47 | return $this->Sum; 48 | } 49 | 50 | public static function create($code): self 51 | { 52 | return new static([ 53 | 'ServiceCode' => $code, 54 | ]); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Common/Address.php: -------------------------------------------------------------------------------- 1 | SenderName; 70 | } 71 | 72 | public function getPvzCode(): string 73 | { 74 | return $this->PvzCode; 75 | } 76 | 77 | public function getFlat(): string 78 | { 79 | return $this->Flat; 80 | } 81 | 82 | public function getHouse(): string 83 | { 84 | return $this->House; 85 | } 86 | 87 | public function getStreet(): string 88 | { 89 | return $this->Street; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Common/Attempt.php: -------------------------------------------------------------------------------- 1 | ") 35 | * 36 | * @var \DateTimeImmutable 37 | */ 38 | protected $Date; 39 | 40 | /** 41 | * @JMS\XmlAttribute 42 | * @JMS\SerializedName("TimeBeg") 43 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 44 | * 45 | * @var \DateTimeImmutable 46 | */ 47 | protected $TimeBeg; 48 | 49 | /** 50 | * @JMS\XmlAttribute 51 | * @JMS\SerializedName("TimeEnd") 52 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 53 | * 54 | * @var \DateTimeImmutable 55 | */ 56 | protected $TimeEnd; 57 | 58 | /** 59 | * @JMS\XmlAttribute 60 | * @JMS\SerializedName("RecipientName") 61 | * @JMS\Type("string") 62 | * 63 | * @var string 64 | */ 65 | protected $RecipientName; 66 | 67 | /** 68 | * @JMS\XmlAttribute 69 | * @JMS\SerializedName("Phone") 70 | * @JMS\Type("string") 71 | * 72 | * @var string 73 | */ 74 | protected $Phone; 75 | 76 | /** 77 | * @JMS\SerializedName("Address") 78 | * @JMS\Type("Appwilio\CdekSDK\Requests\DeliveryRequest\Address") 79 | * 80 | * @var Address 81 | */ 82 | protected $Address; 83 | 84 | /** 85 | * @JMS\SerializedName('ScheduleCode') 86 | * @JMS\XmlAttribute 87 | * @JMS\Type('int') 88 | * 89 | * @var int 90 | */ 91 | public $ScheduleCode; 92 | 93 | /** 94 | * @JMS\SerializedName('ScheduleDescription') 95 | * @JMS\XmlAttribute 96 | * @JMS\Type('string') 97 | * 98 | * @var string 99 | */ 100 | public $ScheduleDescription; 101 | 102 | public function getId(): string 103 | { 104 | return $this->ID; 105 | } 106 | 107 | public function getDate(): \DateTimeImmutable 108 | { 109 | return $this->Date; 110 | } 111 | 112 | public function getTimeBeg(): \DateTimeImmutable 113 | { 114 | return $this->TimeBeg; 115 | } 116 | 117 | public function getTimeEnd(): \DateTimeImmutable 118 | { 119 | return $this->TimeEnd; 120 | } 121 | 122 | public function getRecipientName(): string 123 | { 124 | return $this->RecipientName; 125 | } 126 | 127 | public function getPhone(): string 128 | { 129 | return $this->Phone; 130 | } 131 | 132 | public function getAddress(): Address 133 | { 134 | return $this->Address; 135 | } 136 | 137 | public function getScheduleCode(): int 138 | { 139 | return $this->ScheduleCode; 140 | } 141 | 142 | public function getScheduleDescription(): string 143 | { 144 | return $this->ScheduleDescription; 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/Common/Call.php: -------------------------------------------------------------------------------- 1 | ") 31 | * 32 | * @var CallGood[]|array 33 | */ 34 | public $CallGood = []; 35 | 36 | /** 37 | * @JMS\SerializedName("CallFail") 38 | * @JMS\XmlList(entry="Good") 39 | * @JMS\Type("array") 40 | * 41 | * @var CallFail[]|array 42 | */ 43 | public $CallFail = []; 44 | 45 | /** 46 | * @JMS\SerializedName("CallDelay") 47 | * @JMS\XmlList(entry="Good") 48 | * @JMS\Type("array") 49 | * 50 | * @var CallDelay[]|array 51 | */ 52 | public $CallDelay; 53 | } 54 | -------------------------------------------------------------------------------- /src/Common/CallCourier.php: -------------------------------------------------------------------------------- 1 | ") 26 | * 27 | * @var \DateTimeImmutable 28 | */ 29 | public $Date; 30 | 31 | /** 32 | * @JMS\XmlAttribute 33 | * @JMS\SerializedName("TimeBeg") 34 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 35 | * 36 | * @var \DateTimeImmutable 37 | */ 38 | public $TimeBeg; 39 | 40 | /** 41 | * @JMS\XmlAttribute 42 | * @JMS\SerializedName("TimeEnd") 43 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 44 | * 45 | * @var \DateTimeImmutable 46 | */ 47 | public $TimeEnd; 48 | 49 | /** 50 | * @JMS\XmlAttribute 51 | * @JMS\SerializedName("LunchBeg") 52 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 53 | * 54 | * @var \DateTimeImmutable 55 | */ 56 | public $LunchBeg; 57 | 58 | /** 59 | * @JMS\XmlAttribute 60 | * @JMS\SerializedName("LunchEnd") 61 | * @JMS\Type("DateTimeImmutable<'H:i:s'>") 62 | * 63 | * @var \DateTimeImmutable 64 | */ 65 | public $LunchEnd; 66 | 67 | /** 68 | * @JMS\XmlAttribute 69 | * @JMS\SerializedName("SendCityCode") 70 | * @JMS\Type("integer") 71 | * 72 | * @var integer 73 | */ 74 | public $SendCityCode; 75 | 76 | /** 77 | * @JMS\XmlAttribute 78 | * @JMS\SerializedName("SendPhone") 79 | * @JMS\Type("string") 80 | * 81 | * @var string 82 | */ 83 | public $SendPhone; 84 | 85 | /** 86 | * @JMS\XmlAttribute 87 | * @JMS\SerializedName("Comment") 88 | * @JMS\Type("string") 89 | * 90 | * @var string 91 | */ 92 | public $Comment; 93 | 94 | /** 95 | * @JMS\SerializedName("SendAddress") 96 | * @JMS\Type("Appwilio\CdekSDK\Common\Address") 97 | * 98 | * @var Address 99 | */ 100 | public $SendAddress; 101 | 102 | public function getDate(): \DateTimeImmutable 103 | { 104 | return $this->Date; 105 | } 106 | 107 | public function getTimeBeg(): \DateTimeImmutable 108 | { 109 | return $this->TimeBeg; 110 | } 111 | 112 | public function getTimeEnd(): \DateTimeImmutable 113 | { 114 | return $this->TimeEnd; 115 | } 116 | 117 | public function getLunchBeg(): \DateTimeImmutable 118 | { 119 | return $this->LunchBeg; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/Common/CallDelay.php: -------------------------------------------------------------------------------- 1 | ") 31 | * 32 | * @var \DateTimeImmutable 33 | */ 34 | public $Date; 35 | 36 | /** 37 | * @JMS\XmlAttribute 38 | * @JMS\SerializedName("DateNext") 39 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 40 | * 41 | * @var \DateTimeImmutable 42 | */ 43 | public $DateNext; 44 | } 45 | -------------------------------------------------------------------------------- /src/Common/CallFail.php: -------------------------------------------------------------------------------- 1 | ") 28 | * 29 | * @var \DateTimeImmutable 30 | */ 31 | protected $Date; 32 | 33 | /** 34 | * @JMS\XmlAttribute 35 | * @JMS\SerializedName("ReasonCode") 36 | * @JMS\Type("int") 37 | * 38 | * @var int 39 | */ 40 | protected $ReasonCode; 41 | 42 | /** 43 | * @JMS\XmlAttribute 44 | * @JMS\SerializedName("ReasonDescription") 45 | * @JMS\Type("string") 46 | * 47 | * @var string 48 | */ 49 | protected $ReasonDescription; 50 | 51 | public function getDate(): \DateTimeImmutable 52 | { 53 | return $this->Date; 54 | } 55 | 56 | public function getReasonCode(): int 57 | { 58 | return $this->ReasonCode; 59 | } 60 | 61 | public function getReasonDescription(): string 62 | { 63 | return $this->ReasonDescription; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Common/CallGood.php: -------------------------------------------------------------------------------- 1 | ") 29 | * 30 | * @var \DateTimeImmutable 31 | */ 32 | protected $Date; 33 | 34 | /** 35 | * @JMS\XmlAttribute 36 | * @JMS\SerializedName("DateDeliv") 37 | * @JMS\Type("DateTimeImmutable<'Y-m-d'>") 38 | * 39 | * @var \DateTimeImmutable 40 | */ 41 | protected $DateDeliv; 42 | 43 | public function getDate(): \DateTimeImmutable 44 | { 45 | return $this->Date; 46 | } 47 | 48 | public function getDateDeliv(): \DateTimeImmutable 49 | { 50 | return $this->DateDeliv; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Common/ChangePeriod.php: -------------------------------------------------------------------------------- 1 | ") 24 | * 25 | * @var \DateTimeImmutable 26 | */ 27 | public $DateBeg; 28 | 29 | /** 30 | * @JMS\XmlAttribute 31 | * @JMS\SerializedName("DateEnd") 32 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 33 | * 34 | * @var \DateTimeImmutable 35 | */ 36 | public $DateEnd; 37 | 38 | public function __construct(\DateTimeInterface $start, \DateTimeInterface $end) 39 | { 40 | $this->DateBeg = $start; 41 | $this->DateEnd = $end; 42 | } 43 | 44 | /** 45 | * @JMS\XmlAttribute 46 | * @JMS\SerializedName("DateFirst") 47 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 48 | * @JMS\VirtualProperty() 49 | */ 50 | public function getDateFirst() 51 | { 52 | return $this->DateBeg; 53 | } 54 | 55 | /** 56 | * @JMS\XmlAttribute 57 | * @JMS\SerializedName("DateLast") 58 | * @JMS\Type("DateTime<'Y-m-d\TH:i:sP'>") 59 | * @JMS\VirtualProperty() 60 | */ 61 | public function getDateLast() 62 | { 63 | return $this->DateEnd; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Common/City.php: -------------------------------------------------------------------------------- 1 | Code; 52 | } 53 | 54 | public function getPostCode(): string 55 | { 56 | return $this->PostCode; 57 | } 58 | 59 | public function getName(): string 60 | { 61 | return $this->Name; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Common/Fillable.php: -------------------------------------------------------------------------------- 1 | $value) { 21 | if (property_exists($this, $key)) { 22 | $this->{$key} = $value; 23 | } else { 24 | throw new \InvalidArgumentException(sprintf( 25 | 'Property "%s" does not exist in class "%s"', $key, static::class 26 | )); 27 | } 28 | } 29 | } 30 | 31 | public static function create($data) 32 | { 33 | return new static($data); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Common/Item.php: -------------------------------------------------------------------------------- 1 | WareKey; 93 | } 94 | 95 | public function getCost(): float 96 | { 97 | return $this->Cost; 98 | } 99 | 100 | public function getPayment(): float 101 | { 102 | return $this->Payment; 103 | } 104 | 105 | public function getWeight(): int 106 | { 107 | return $this->Weight; 108 | } 109 | 110 | public function getAmount(): int 111 | { 112 | return $this->Amount; 113 | } 114 | 115 | public function getComment(): string 116 | { 117 | return $this->Comment; 118 | } 119 | 120 | public function getDelivAmount(): int 121 | { 122 | return $this->DelivAmount; 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/Common/OfficeImage.php: -------------------------------------------------------------------------------- 1 | ") 31 | * 32 | * @var \DateTimeImmutable 33 | */ 34 | protected $Date; 35 | 36 | /** 37 | * @JMS\XmlAttribute 38 | * @JMS\SerializedName("Number") 39 | * @JMS\Type("string") 40 | * 41 | * @var string 42 | */ 43 | protected $Number; 44 | 45 | /** 46 | * @JMS\XmlAttribute 47 | * @JMS\SerializedName("DispatchNumber") 48 | * @JMS\Type("string") 49 | * 50 | * @var string 51 | */ 52 | protected $DispatchNumber; 53 | 54 | /** 55 | * @JMS\XmlAttribute 56 | * @JMS\SerializedName("RecipientName") 57 | * @JMS\Type("string") 58 | * 59 | * @var string 60 | */ 61 | protected $RecipientName; 62 | 63 | /** 64 | * @JMS\XmlAttribute 65 | * @JMS\SerializedName("RecipientEmail") 66 | * @JMS\Type("string") 67 | * 68 | * @var string 69 | */ 70 | protected $RecipientEmail; 71 | 72 | /** 73 | * @JMS\XmlAttribute 74 | * @JMS\SerializedName("RecipientCurrency") 75 | * @JMS\Type("string") 76 | * 77 | * @var string 78 | */ 79 | protected $RecipientCurrency; 80 | 81 | /** 82 | * @JMS\XmlAttribute 83 | * @JMS\SerializedName("Phone") 84 | * @JMS\Type("string") 85 | * 86 | * @var string 87 | */ 88 | protected $Phone; 89 | 90 | /** 91 | * @JMS\XmlAttribute 92 | * @JMS\SerializedName("TariffTypeCode") 93 | * @JMS\Type("integer") 94 | * 95 | * @var integer 96 | */ 97 | protected $TariffTypeCode; 98 | 99 | /** 100 | * @JMS\XmlAttribute 101 | * @JMS\SerializedName("DeliveryRecipientCost") 102 | * @JMS\Type("float") 103 | * 104 | * @var float 105 | */ 106 | protected $DeliveryRecipientCost; 107 | 108 | /** 109 | * @JMS\XmlAttribute 110 | * @JMS\SerializedName("ItemsCurrency") 111 | * @JMS\Type("string") 112 | * 113 | * @var string 114 | */ 115 | protected $ItemsCurrency; 116 | 117 | /** 118 | * @JMS\XmlAttribute 119 | * @JMS\SerializedName("Comment") 120 | * @JMS\Type("string") 121 | * 122 | * @var string 123 | */ 124 | protected $Comment; 125 | 126 | /** 127 | * @JMS\SerializedName("Status") 128 | * @JMS\Type("Appwilio\CdekSDK\Common\Status") 129 | * 130 | * @var Status|null 131 | */ 132 | protected $Status; 133 | 134 | /** 135 | * @JMS\SerializedName("Reason") 136 | * @JMS\Type("Appwilio\CdekSDK\Common\Reason") 137 | * 138 | * @var Reason 139 | */ 140 | protected $Reason; 141 | 142 | /** 143 | * @JMS\SerializedName("DelayReason") 144 | * @JMS\Type("Appwilio\CdekSDK\Common\Reason") 145 | * 146 | * @var Reason 147 | */ 148 | protected $DelayReason; 149 | 150 | /** 151 | * @JMS\SerializedName("Address") 152 | * @JMS\Type("Appwilio\CdekSDK\Common\Address") 153 | * 154 | * @var Address 155 | */ 156 | protected $Address; 157 | 158 | /** 159 | * @JMS\XmlList(entry="Attempt", inline=true) 160 | * @JMS\Type("array") 161 | * 162 | * @var array|Attempt[] 163 | */ 164 | protected $attempts = []; 165 | 166 | /** 167 | * @JMS\XmlList(entry="AddedService", inline=true) 168 | * @JMS\Type("array") 169 | * @var array|AdditionalService[] 170 | */ 171 | protected $addedServices = []; 172 | 173 | /** 174 | * @JMS\XmlList(entry="AddService", inline=true) 175 | * @JMS\Type("array") 176 | * @var array|AdditionalService[] 177 | */ 178 | protected $additionalServices = []; 179 | 180 | /** 181 | * @JMS\SerializedName("Schedule") 182 | * @JMS\XmlList(entry="Attempt") 183 | * @JMS\Type("array")\ 184 | * 185 | * @var array|Attempt[] 186 | */ 187 | protected $scheduleAttempts = []; 188 | 189 | /** 190 | * @JMS\XmlList(entry="Package", inline=true) 191 | * @JMS\Type("array") 192 | * 193 | * @var array|Package[] 194 | */ 195 | protected $packages = []; 196 | 197 | /** 198 | * @JMS\SerializedName("CallCourier") 199 | * @JMS\XmlList(entry="Call") 200 | * @JMS\Type("array") 201 | * 202 | * @var array|CallCourier[] 203 | */ 204 | protected $courierCalls = []; 205 | 206 | /** 207 | * @JMS\XmlAttribute 208 | * @JMS\SerializedName("Weight") 209 | * @JMS\Type("float") 210 | * 211 | * @var float 212 | */ 213 | protected $Weight; 214 | 215 | /** 216 | * @JMS\XmlAttribute 217 | * @JMS\SerializedName("DeliverySum") 218 | * @JMS\Type("float") 219 | * 220 | * @var float 221 | */ 222 | protected $DeliverySum; 223 | 224 | /** 225 | * @JMS\XmlAttribute 226 | * @JMS\SerializedName("DateLastChange") 227 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 228 | * 229 | * @var \DateTimeImmutable 230 | */ 231 | protected $DateLastChange; 232 | 233 | /** 234 | * @JMS\XmlAttribute 235 | * @JMS\SerializedName("CashOnDeliv") 236 | * @JMS\Type("float") 237 | * 238 | * @var float 239 | */ 240 | protected $CashOnDeliv; 241 | 242 | /** 243 | * @JMS\XmlAttribute 244 | * @JMS\SerializedName("CashOnDelivFac") 245 | * @JMS\Type("float") 246 | * 247 | * @var float 248 | */ 249 | protected $CashOnDelivFac; 250 | 251 | /** 252 | * @JMS\XmlAttribute 253 | * @JMS\SerializedName("DeliveryMode") 254 | * @JMS\Type("int") 255 | * @var int 256 | */ 257 | protected $DeliveryMode; 258 | 259 | /** 260 | * @JMS\XmlAttribute 261 | * @JMS\SerializedName("PvzCode") 262 | * @JMS\Type("string") 263 | * 264 | * @var string 265 | */ 266 | protected $PvzCode; 267 | 268 | /** 269 | * @JMS\XmlAttribute 270 | * @JMS\SerializedName("DeliveryVariant") 271 | * @JMS\Type("string") 272 | * 273 | * @var string 274 | */ 275 | protected $DeliveryVariant; 276 | 277 | /** 278 | * @JMS\SerializedName("SendCity") 279 | * @JMS\Type("Appwilio\CdekSDK\Common\City") 280 | * 281 | * @var City 282 | */ 283 | protected $SendCity; 284 | 285 | /** 286 | * @JMS\XmlAttribute 287 | * @JMS\SerializedName("SendCityName") 288 | * @JMS\Type("string") 289 | * 290 | * @var string 291 | */ 292 | protected $SendCityName; 293 | 294 | /** 295 | * @JMS\SerializedName("RecCity") 296 | * @JMS\Type("Appwilio\CdekSDK\Common\City") 297 | * 298 | * @var City 299 | */ 300 | protected $RecCity; 301 | 302 | /** 303 | * @JMS\XmlAttribute 304 | * @JMS\SerializedName("RecCityName") 305 | * @JMS\Type("string") 306 | * 307 | * @var string 308 | */ 309 | protected $RecCityName; 310 | 311 | /** 312 | * @JMS\XmlAttribute 313 | * @JMS\SerializedName("Msg") 314 | * @JMS\Type("string") 315 | * 316 | * @var string 317 | */ 318 | protected $Msg; 319 | 320 | /** 321 | * @JMS\XmlAttribute 322 | * @JMS\SerializedName("SellerName") 323 | * @JMS\Type("string") 324 | * 325 | * @var string 326 | */ 327 | protected $SellerName; 328 | 329 | /** 330 | * @JMS\XmlAttribute 331 | * @JMS\SerializedName("ShipperAddress") 332 | * @JMS\Type("string") 333 | * 334 | * @var string 335 | */ 336 | protected $SellerAddress; 337 | 338 | /** 339 | * @JMS\XmlAttribute 340 | * @JMS\SerializedName("ShipperName") 341 | * @JMS\Type("string") 342 | * 343 | * @var string 344 | */ 345 | protected $ShipperName; 346 | 347 | /** 348 | * @JMS\XmlAttribute 349 | * @JMS\SerializedName("SellerAddress") 350 | * @JMS\Type("string") 351 | * 352 | * @var string 353 | */ 354 | protected $ShipperAddress; 355 | 356 | /** 357 | * @JMS\SerializedName("Call") 358 | * @JMS\Type("Appwilio\CdekSDK\Common\Call") 359 | * 360 | * @var Call 361 | */ 362 | public $Call; 363 | 364 | /** 365 | * @JMS\SerializedName("ReturnOrder") 366 | * @JMS\Type("Appwilio\CdekSDK\Common\Order") 367 | * @var Order 368 | */ 369 | public $ReturnOrder; 370 | 371 | /** 372 | * @JMS\XmlAttribute 373 | * @JMS\SerializedName("ActNumber") 374 | * @JMS\Type("int") 375 | * 376 | * @var int 377 | */ 378 | public $ActNumber; 379 | 380 | /** 381 | * @JMS\XmlAttribute 382 | * @JMS\SerializedName("DeliveryDate") 383 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 384 | * 385 | * @var \DateTimeImmutable|null 386 | */ 387 | public $DeliveryDate; 388 | 389 | /** 390 | * @JMS\XmlAttribute 391 | * @JMS\SerializedName("ReturnDispatchNumber") 392 | * @JMS\Type("int") 393 | * 394 | * @var int 395 | */ 396 | public $ReturnDispatchNumber; 397 | 398 | public function callCourier(CallCourier $call) 399 | { 400 | $this->courierCalls[] = $call; 401 | } 402 | 403 | public function addService(AdditionalService $service) 404 | { 405 | $this->additionalServices[] = $service; 406 | } 407 | 408 | public function addScheduleAttempt(Attempt $attempt) 409 | { 410 | $this->scheduleAttempts[] = $attempt; 411 | } 412 | 413 | public function setAddress(Address $address) 414 | { 415 | $this->Address = $address; 416 | 417 | return $this; 418 | } 419 | 420 | public function addPackage(Package $package) 421 | { 422 | $this->packages[] = $package; 423 | 424 | return $this; 425 | } 426 | 427 | public function getDate(): \DateTimeImmutable 428 | { 429 | return $this->Date; 430 | } 431 | 432 | public function getNumber(): string 433 | { 434 | return (string) $this->Number; 435 | } 436 | 437 | public function getDispatchNumber(): string 438 | { 439 | return (string) $this->DispatchNumber; 440 | } 441 | 442 | /** 443 | * @JMS\VirtualProperty 444 | * @JMS\XmlAttribute 445 | * @JMS\SerializedName("SendCityCode") 446 | * @JMS\Type("integer") 447 | * 448 | * @return int|null 449 | */ 450 | public function getSendCityCode(): ?int 451 | { 452 | return $this->SendCity ? $this->SendCity->getCode() : null; 453 | } 454 | 455 | /** 456 | * @JMS\VirtualProperty 457 | * @JMS\XmlAttribute 458 | * @JMS\SerializedName("SendCityPostCode") 459 | * @JMS\Type("string") 460 | * 461 | * @return null|string 462 | */ 463 | public function getSendCityPostCode(): ?string 464 | { 465 | return $this->SendCity ? $this->SendCity->getPostCode() : null; 466 | } 467 | 468 | /** 469 | * @JMS\VirtualProperty 470 | * @JMS\XmlAttribute 471 | * @JMS\SerializedName("RecCityCode") 472 | * @JMS\Type("integer") 473 | * 474 | * @return int|null 475 | */ 476 | public function getRecCityCode(): ?int 477 | { 478 | return $this->RecCity ? $this->RecCity->getCode() : null; 479 | } 480 | 481 | /** 482 | * @JMS\VirtualProperty 483 | * @JMS\XmlAttribute 484 | * @JMS\SerializedName("RecCityPostCode") 485 | * @JMS\Type("string") 486 | * 487 | * @return null|string 488 | */ 489 | public function getRecCityPostCode(): ?string 490 | { 491 | return $this->RecCity ? $this->RecCity->getPostCode() : null; 492 | } 493 | 494 | public function getRecipientName(): string 495 | { 496 | return (string) $this->RecipientName; 497 | } 498 | 499 | public function getDeliveryRecipientCost(): float 500 | { 501 | return (float) $this->DeliveryRecipientCost; 502 | } 503 | 504 | public function getTariffTypeCode(): int 505 | { 506 | return (int) $this->TariffTypeCode; 507 | } 508 | 509 | public function getPhone(): string 510 | { 511 | return (string) $this->Phone; 512 | } 513 | 514 | public function getRecipientEmail(): string 515 | { 516 | return (string) $this->RecipientEmail; 517 | } 518 | 519 | public function getRecipientCurrency(): string 520 | { 521 | return (string) $this->RecipientCurrency; 522 | } 523 | 524 | public function getItemsCurrency(): string 525 | { 526 | return (string) $this->ItemsCurrency; 527 | } 528 | 529 | public function getComment(): string 530 | { 531 | return (string) $this->Comment; 532 | } 533 | 534 | public function getSellerName(): string 535 | { 536 | return (string) $this->SellerName; 537 | } 538 | 539 | public function getAddress(): Address 540 | { 541 | return $this->Address; 542 | } 543 | 544 | /** 545 | * @return AdditionalService[]|array 546 | */ 547 | public function getAdditionalServices() 548 | { 549 | return array_merge($this->additionalServices, $this->addedServices); 550 | } 551 | 552 | /** 553 | * @return Attempt[]|array 554 | */ 555 | public function getScheduleAttempts() 556 | { 557 | return $this->scheduleAttempts; 558 | } 559 | 560 | /** 561 | * @return Package[]|array 562 | */ 563 | public function getPackages() 564 | { 565 | return $this->packages; 566 | } 567 | 568 | /** 569 | * @return CallCourier[]|array 570 | */ 571 | public function getCourierCalls() 572 | { 573 | return $this->courierCalls; 574 | } 575 | 576 | public function getStatus(): ?Status 577 | { 578 | return $this->Status; 579 | } 580 | 581 | public function getReason(): Reason 582 | { 583 | return $this->Reason; 584 | } 585 | 586 | public function getDelayReason(): Reason 587 | { 588 | return $this->DelayReason; 589 | } 590 | 591 | /** 592 | * @return Attempt[]|array 593 | */ 594 | public function getAttempts() 595 | { 596 | return $this->attempts; 597 | } 598 | 599 | public function getWeight(): float 600 | { 601 | return (float) $this->Weight; 602 | } 603 | 604 | public function getDeliverySum(): float 605 | { 606 | return (float) $this->DeliverySum; 607 | } 608 | 609 | public function getDateLastChange(): \DateTimeImmutable 610 | { 611 | return $this->DateLastChange; 612 | } 613 | 614 | public function getCashOnDeliv(): float 615 | { 616 | return (float) $this->CashOnDeliv; 617 | } 618 | 619 | public function getCashOnDelivFac(): float 620 | { 621 | return (float) $this->CashOnDelivFac; 622 | } 623 | 624 | public function getDeliveryMode(): int 625 | { 626 | return (int) $this->DeliveryMode; 627 | } 628 | 629 | public function getPvzCode(): string 630 | { 631 | return (string) $this->PvzCode; 632 | } 633 | 634 | public function getDeliveryVariant(): string 635 | { 636 | return (string) $this->DeliveryVariant; 637 | } 638 | 639 | public function getSenderCity(): City 640 | { 641 | return $this->SendCity; 642 | } 643 | 644 | public function getRecipientCity(): City 645 | { 646 | return $this->RecCity; 647 | } 648 | 649 | public function getMessage(): string 650 | { 651 | return (string) $this->Msg; 652 | } 653 | } 654 | -------------------------------------------------------------------------------- /src/Common/Package.php: -------------------------------------------------------------------------------- 1 | ") 79 | * 80 | * @var array|Item[] 81 | */ 82 | protected $items = []; 83 | 84 | public function addItem(Item $item) 85 | { 86 | $this->items[] = $item; 87 | 88 | return $this; 89 | } 90 | 91 | public function getNumber(): string 92 | { 93 | return $this->Number; 94 | } 95 | 96 | public function getBarCode(): string 97 | { 98 | return $this->BarCode; 99 | } 100 | 101 | public function getWeight(): int 102 | { 103 | return $this->Weight; 104 | } 105 | 106 | public function getSizeA(): int 107 | { 108 | return $this->SizeA; 109 | } 110 | 111 | public function getSizeB(): int 112 | { 113 | return $this->SizeB; 114 | } 115 | 116 | public function getSizeC(): int 117 | { 118 | return $this->SizeC; 119 | } 120 | 121 | public function getVolumeWeight(): float 122 | { 123 | return ($this->SizeA * $this->SizeB * $this->SizeC) / 5000; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Common/Pvz.php: -------------------------------------------------------------------------------- 1 | $field = $this->$field === 'есть' || $this->$field === 'true'; 259 | } 260 | } 261 | } 262 | -------------------------------------------------------------------------------- /src/Common/Reason.php: -------------------------------------------------------------------------------- 1 | ") 24 | * 25 | * @var \DateTimeImmutable 26 | */ 27 | public $Date; 28 | 29 | /** 30 | * @JMS\XmlAttribute 31 | * @JMS\SerializedName("Code") 32 | * @JMS\Type("int") 33 | * 34 | * @var int 35 | */ 36 | public $Code; 37 | 38 | /** 39 | * @JMS\XmlAttribute 40 | * @JMS\SerializedName("Description") 41 | * @JMS\Type("string") 42 | * 43 | * @var string 44 | */ 45 | public $Description; 46 | 47 | /** 48 | * @JMS\XmlList(entry="State", inline=true) 49 | * @JMS\Type("array") 50 | * 51 | * @var State[]|array 52 | */ 53 | public $states = []; 54 | } 55 | -------------------------------------------------------------------------------- /src/Common/State.php: -------------------------------------------------------------------------------- 1 | ") 24 | * 25 | * @var \DateTimeImmutable 26 | */ 27 | public $Date; 28 | 29 | /** 30 | * @JMS\XmlAttribute 31 | * @JMS\SerializedName("Code") 32 | * @JMS\Type("int") 33 | * 34 | * @var int 35 | */ 36 | public $Code; 37 | 38 | /** 39 | * @JMS\XmlAttribute 40 | * @JMS\SerializedName("Description") 41 | * @JMS\Type("string") 42 | * 43 | * @var string 44 | */ 45 | public $Description; 46 | 47 | /** 48 | * @JMS\XmlAttribute 49 | * @JMS\SerializedName("CityName") 50 | * @JMS\Type("string") 51 | * 52 | * @var string 53 | */ 54 | public $CityName; 55 | 56 | /** 57 | * @JMS\XmlAttribute 58 | * @JMS\SerializedName("CityCode") 59 | * @JMS\Type("int") 60 | * 61 | * @var int 62 | */ 63 | public $CityCode; 64 | } 65 | -------------------------------------------------------------------------------- /src/Common/Status.php: -------------------------------------------------------------------------------- 1 | ") 26 | * 27 | * @var \DateTimeImmutable 28 | */ 29 | protected $Date; 30 | 31 | /** 32 | * @JMS\XmlAttribute 33 | * @JMS\SerializedName("Code") 34 | * @JMS\Type("integer") 35 | * 36 | * @var integer 37 | */ 38 | protected $Code; 39 | 40 | /** 41 | * @JMS\XmlAttribute 42 | * @JMS\SerializedName("Description") 43 | * @JMS\Type("string") 44 | * 45 | * @var string 46 | */ 47 | protected $Description; 48 | 49 | /** 50 | * @JMS\XmlAttribute 51 | * @JMS\SerializedName("CityCode") 52 | * @JMS\Type("integer") 53 | * 54 | * @var integer 55 | */ 56 | protected $CityCode; 57 | 58 | /** 59 | * @JMS\XmlAttribute 60 | * @JMS\SerializedName("CityName") 61 | * @JMS\Type("string") 62 | * 63 | * @var string 64 | */ 65 | protected $CityName; 66 | 67 | /** 68 | * @JMS\XmlList(entry="State", inline=true) 69 | * @JMS\Type("array") 70 | * 71 | * @var State[]|array 72 | */ 73 | protected $states = []; 74 | 75 | public function getDate(): \DateTimeImmutable 76 | { 77 | return $this->Date; 78 | } 79 | 80 | public function getCode(): int 81 | { 82 | return $this->Code; 83 | } 84 | 85 | public function getDescription(): string 86 | { 87 | return $this->Description; 88 | } 89 | 90 | public function getCityCode(): int 91 | { 92 | return $this->CityCode; 93 | } 94 | 95 | public function getCityName(): string 96 | { 97 | return $this->CityName; 98 | } 99 | 100 | /** 101 | * @return State[]|array 102 | */ 103 | public function getStates(): array 104 | { 105 | return $this->states; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Common/WeightLimit.php: -------------------------------------------------------------------------------- 1 | app->singleton(CdekClient::class, function (Application $app) { 32 | $config = $app['config']['services.cdek']; 33 | 34 | return new CdekClient($config['account'], $config['password'], $config['guzzle_options'] ?? []); 35 | }); 36 | } 37 | 38 | public function provides() 39 | { 40 | return [CdekClient::class]; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Requests/CalculationAuthorizedRequest.php: -------------------------------------------------------------------------------- 1 | $this->secure, 32 | 'authLogin' => $this->account, 33 | 'dateExecute' => $this->date->format('Y-m-d'), 34 | ]); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Requests/CalculationRequest.php: -------------------------------------------------------------------------------- 1 | senderCityId = $id; 67 | 68 | return $this; 69 | } 70 | 71 | public function setReceiverCityId($id) 72 | { 73 | $this->receiverCityId = $id; 74 | 75 | return $this; 76 | } 77 | 78 | public function setSenderCityPostCode($code) 79 | { 80 | $this->senderCityPostCode = $code; 81 | 82 | return $this; 83 | } 84 | 85 | public function setReceiverCityPostCode($code) 86 | { 87 | $this->receiverCityPostCode = $code; 88 | 89 | return $this; 90 | } 91 | 92 | public function setTariffId($id) 93 | { 94 | $this->tariffList = null; 95 | 96 | $this->tariffId = $id; 97 | 98 | return $this; 99 | } 100 | 101 | public function addTariffToList($id, $priority) 102 | { 103 | $this->tariffId = null; 104 | 105 | $this->tariffList[] = compact('id', 'priority'); 106 | 107 | return $this; 108 | } 109 | 110 | public function setModeId($id) 111 | { 112 | $this->modeId = $id; 113 | 114 | return $this; 115 | } 116 | 117 | public function addGood($good) 118 | { 119 | $this->goods[] = $good; 120 | 121 | return $this; 122 | } 123 | 124 | public function addAdditionalService(int $serviceId, $param = null) 125 | { 126 | $this->services[] = [ 127 | 'id' => $serviceId, 128 | 'param' => $param, 129 | ]; 130 | 131 | return $this; 132 | } 133 | 134 | public function getBody(): array 135 | { 136 | return array_filter([ 137 | 'version' => '1.0', 138 | 'goods' => $this->goods, 139 | 'modeId' => $this->modeId, 140 | 'tariffId' => $this->tariffId, 141 | 'tariffList' => $this->tariffList, 142 | 'senderCityId' => $this->senderCityId, 143 | 'senderCityPostCode' => $this->senderCityPostCode, 144 | 'services' => $this->services, 145 | 'receiverCityId' => $this->receiverCityId, 146 | 'receiverCityPostCode' => $this->receiverCityPostCode, 147 | ]); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Requests/Concerns/Authorized.php: -------------------------------------------------------------------------------- 1 | ") 24 | * 25 | * @var \DateTimeImmutable 26 | */ 27 | public $date; 28 | 29 | /** 30 | * @JMS\XmlAttribute 31 | * @JMS\SerializedName("Account") 32 | * @JMS\Type("string") 33 | * 34 | * @var string 35 | */ 36 | public $account; 37 | 38 | /** 39 | * @JMS\XmlAttribute 40 | * @JMS\SerializedName("Secure") 41 | * 42 | * @var string 43 | */ 44 | public $secure; 45 | 46 | public function date(\DateTimeInterface $date): ShouldAuthorize 47 | { 48 | $this->date = $date; 49 | 50 | /** @var ShouldAuthorize $this */ 51 | return $this; 52 | } 53 | 54 | public function credentials(string $account, string $secure): ShouldAuthorize 55 | { 56 | $this->account = $account; 57 | $this->secure = $secure; 58 | 59 | /** @var ShouldAuthorize $this */ 60 | return $this; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Requests/Concerns/OrdersAware.php: -------------------------------------------------------------------------------- 1 | ") 23 | * 24 | * @var Order[]|array 25 | */ 26 | protected $orders = []; 27 | 28 | /** 29 | * @return Order[]|array 30 | */ 31 | public function getOrders() 32 | { 33 | return $this->orders; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Requests/Concerns/RequestCore.php: -------------------------------------------------------------------------------- 1 | orders); 57 | } 58 | 59 | public function addOrder(Order $order) 60 | { 61 | $this->orders[$order->getNumber()] = $order; 62 | 63 | return $this; 64 | } 65 | 66 | public function getNumber(): string 67 | { 68 | return $this->number; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Requests/InfoReportRequest.php: -------------------------------------------------------------------------------- 1 | orders[] = $order; 49 | 50 | return $this; 51 | } 52 | 53 | public function setChangePeriod(ChangePeriod $period) 54 | { 55 | $this->ChangePeriod = $period; 56 | 57 | return $this; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Requests/PrintReceiptsRequest.php: -------------------------------------------------------------------------------- 1 | orders[$order->getDispatchNumber()] = $order; 42 | 43 | return $this; 44 | } 45 | 46 | /** 47 | * @JMS\XmlAttribute 48 | * @JMS\SerializedName("OrderCount") 49 | * @JMS\Type("int") 50 | * @JMS\VirtualProperty() 51 | */ 52 | public function getOrderCount() 53 | { 54 | return \count($this->orders); 55 | } 56 | 57 | /** 58 | * @JMS\XmlAttribute 59 | * @JMS\SerializedName("CopyCount") 60 | * @JMS\Type("int") 61 | * @JMS\VirtualProperty() 62 | */ 63 | public function getCopyCount() 64 | { 65 | return 2; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Requests/PvzListRequest.php: -------------------------------------------------------------------------------- 1 | type = $type; 65 | 66 | return $this; 67 | } 68 | 69 | public function setCityId(int $id) 70 | { 71 | $this->cityId = $id; 72 | 73 | return $this; 74 | } 75 | 76 | public function setRegionId(int $regionId) 77 | { 78 | $this->regionId = $regionId; 79 | 80 | return $this; 81 | } 82 | 83 | public function setCountryId(int $countryId) 84 | { 85 | $this->countryId = $countryId; 86 | 87 | return $this; 88 | } 89 | 90 | public function setPostCode(string $code) 91 | { 92 | $this->cityPostCode = $code; 93 | 94 | return $this; 95 | } 96 | 97 | public function setCashless(bool $cashless) 98 | { 99 | $this->cashless = $cashless; 100 | 101 | return $this; 102 | } 103 | 104 | public function setDressingRoom(bool $haveDressingRoom) 105 | { 106 | $this->dressingRoom = $haveDressingRoom; 107 | 108 | return $this; 109 | } 110 | 111 | public function setCodAllowed(bool $codAllowed) 112 | { 113 | $this->codAllowed = $codAllowed; 114 | 115 | return $this; 116 | } 117 | 118 | public function setMaxWeight(int $maxWeight) 119 | { 120 | $this->maxWeight = $maxWeight; 121 | 122 | return $this; 123 | } 124 | 125 | public function getParams(): array 126 | { 127 | return [ 128 | 'type' => $this->type, 129 | 'cityid' => $this->cityId, 130 | 'regionid' => $this->regionId, 131 | 'countryid' => $this->countryId, 132 | 'citypostcode' => $this->cityPostCode, 133 | 'havecashles' => $this->cashless, 134 | 'weightmax' => $this->maxWeight, 135 | 'allowedcod' => $this->codAllowed, 136 | 'isdressingroom' => $this->dressingRoom, 137 | ]; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Requests/StatusReportRequest.php: -------------------------------------------------------------------------------- 1 | ") 65 | * @var array|Order[] 66 | */ 67 | protected $orders = []; 68 | 69 | /** 70 | * @JMS\SerializedName("ChangePeriod") 71 | * @var ChangePeriod|null 72 | */ 73 | protected $ChangePeriod; 74 | 75 | public function addOrder(Order $order) 76 | { 77 | $this->orders[$order->getDispatchNumber()] = $order; 78 | 79 | return $this; 80 | } 81 | 82 | public function setChangePeriod(ChangePeriod $period) 83 | { 84 | $this->ChangePeriod = $period; 85 | 86 | return $this; 87 | } 88 | 89 | public function setShowHistory(bool $showHistory = true) 90 | { 91 | $this->ShowHistory = (int) $showHistory; 92 | 93 | return $this; 94 | } 95 | 96 | public function setShowReturnOrder(bool $showReturnOrder = true) 97 | { 98 | $this->ShowReturnOrder = (int) $showReturnOrder; 99 | 100 | return $this; 101 | } 102 | 103 | public function setShowReturnOrderHistory(bool $showReturnOrderHistory = true) 104 | { 105 | $this->ShowReturnOrderHistory = (int) $showReturnOrderHistory; 106 | 107 | return $this; 108 | } 109 | 110 | /** 111 | * @return Order[]|array 112 | */ 113 | public function getOrders() 114 | { 115 | return $this->orders; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Responses/CalculationResponse.php: -------------------------------------------------------------------------------- 1 | ") 38 | * 39 | * @var array|Error[] 40 | */ 41 | public $errors = []; 42 | 43 | public function hasErrors(): bool 44 | { 45 | return ! empty($this->errors); 46 | } 47 | 48 | public function getErrors(): array 49 | { 50 | return $this->errors; 51 | } 52 | 53 | public function getResult(): Result 54 | { 55 | return $this->result; 56 | } 57 | 58 | public function __call($name, $arguments) 59 | { 60 | if ($this->result && method_exists($this->result, $name)) { 61 | return $this->result->{$name}(...$arguments); 62 | } 63 | 64 | throw new \BadMethodCallException(sprintf('Method [%s] not found in [%s].', $name, __CLASS__)); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/Responses/DeleteResponse.php: -------------------------------------------------------------------------------- 1 | ") 30 | * 31 | * @var array|Order[] 32 | */ 33 | protected $orders = []; 34 | 35 | /** 36 | * @JMS\Exclude 37 | * 38 | * @var array|Message[] 39 | */ 40 | protected $messages; 41 | 42 | /** 43 | * @return Order[]|array 44 | */ 45 | public function getOrders() 46 | { 47 | return $this->orders; 48 | } 49 | 50 | /** 51 | * @JMS\PostDeserialize 52 | */ 53 | public function filterOrders(): void 54 | { 55 | $messages = array_filter($this->orders, function (Order $order) { 56 | return (bool) $order->getMessage(); 57 | }); 58 | 59 | foreach ($messages as $message) { 60 | $this->messages[] = new Message($message->getMessage()); 61 | } 62 | 63 | $this->orders = array_filter($this->orders, function (Order $order) { 64 | return (bool) $order->getDispatchNumber(); 65 | }); 66 | } 67 | 68 | public function getMessages(): array 69 | { 70 | return $this->messages; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/Responses/InfoReportResponse.php: -------------------------------------------------------------------------------- 1 | ") 29 | * 30 | * @var array|Order[] 31 | */ 32 | protected $orders = []; 33 | 34 | /** 35 | * @return Order[]|array 36 | */ 37 | public function getOrders() 38 | { 39 | return $this->orders; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/PrintReceiptsResponse.php: -------------------------------------------------------------------------------- 1 | ") 30 | * 31 | * @var array|Order[] 32 | */ 33 | private $orders = []; 34 | 35 | /** 36 | * @JMS\XmlList(entry = "OrdersPrint", inline = true) 37 | * @JMS\Type("array") 38 | * 39 | * @var array|Order[] 40 | */ 41 | private $ordersPrint = []; 42 | 43 | /** 44 | * @JMS\Exclude 45 | * 46 | * @var PrintReceiptsError[] 47 | */ 48 | protected $errors; 49 | 50 | /** 51 | * @JMS\PostDeserialize 52 | */ 53 | public function filter(): void 54 | { 55 | $this->errors = array_merge($this->orders, $this->ordersPrint); 56 | 57 | unset($this->orders, $this->ordersPrint); 58 | } 59 | 60 | /** 61 | * @return PrintReceiptsError[] 62 | */ 63 | public function getErrors() 64 | { 65 | return $this->errors; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Responses/PvzListResponse.php: -------------------------------------------------------------------------------- 1 | ") 29 | * 30 | * @var Pvz[]; 31 | */ 32 | private $items = []; 33 | 34 | /** 35 | * @return Pvz[] 36 | */ 37 | public function getItems(): array 38 | { 39 | return $this->items; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Responses/StatusReportResponse.php: -------------------------------------------------------------------------------- 1 | ") 30 | * 31 | * @var \DateTimeImmutable 32 | */ 33 | protected $DateFirst; 34 | 35 | /** 36 | * @JMS\XmlAttribute 37 | * @JMS\SerializedName("DateLast") 38 | * @JMS\Type("DateTimeImmutable<'Y-m-d\TH:i:sP'>") 39 | * 40 | * @var \DateTimeImmutable 41 | */ 42 | protected $DateLast; 43 | 44 | /** 45 | * @JMS\XmlList(inline = true, entry = "Order") 46 | * @JMS\Type("array") 47 | * 48 | * @var Order[]|array 49 | */ 50 | protected $orders = []; 51 | 52 | public function getDateFirst(): \DateTimeImmutable 53 | { 54 | return $this->DateFirst; 55 | } 56 | 57 | public function getDateLast(): \DateTimeImmutable 58 | { 59 | return $this->DateLast; 60 | } 61 | 62 | /** 63 | * @return Order[]|array 64 | */ 65 | public function getOrders() 66 | { 67 | return $this->orders; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Responses/Types/AdditionalService.php: -------------------------------------------------------------------------------- 1 | id; 35 | } 36 | 37 | public function getTitle(): string 38 | { 39 | return $this->title; 40 | } 41 | 42 | public function getPrice(): float 43 | { 44 | return $this->price; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Responses/Types/Error.php: -------------------------------------------------------------------------------- 1 | code; 37 | } 38 | 39 | public function getText(): string 40 | { 41 | return $this->text; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Responses/Types/Message.php: -------------------------------------------------------------------------------- 1 | text = $text; 27 | $this->errorCode = $errorCode; 28 | } 29 | 30 | public function getText(): string 31 | { 32 | return $this->text; 33 | } 34 | 35 | public function isError(): bool 36 | { 37 | return (bool) $this->errorCode; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Responses/Types/PrintReceiptsError.php: -------------------------------------------------------------------------------- 1 | code; 41 | } 42 | 43 | public function getText(): string 44 | { 45 | return $this->text; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Responses/Types/Result.php: -------------------------------------------------------------------------------- 1 | ") 47 | * 48 | * @var null|\DateTimeImmutable 49 | */ 50 | protected $deliveryDateMin; 51 | 52 | /** 53 | * @JMS\SerializedName("deliveryDateMax") 54 | * @JMS\Type("DateTimeImmutable<'Y-m-d'>") 55 | * 56 | * @var null|\DateTimeImmutable 57 | */ 58 | protected $deliveryDateMax; 59 | 60 | /** 61 | * @JMS\SerializedName("tariffId") 62 | * @JMS\Type("int") 63 | * 64 | * @var int 65 | */ 66 | protected $tariffId; 67 | 68 | /** 69 | * @JMS\SerializedName("priceByCurrency") 70 | * @JMS\Type("float") 71 | * 72 | * @var null|float 73 | */ 74 | protected $priceByCurrency; 75 | 76 | /** 77 | * @JMS\SerializedName("currency") 78 | * @JMS\Type("string") 79 | * 80 | * @var null|string 81 | */ 82 | protected $currency; 83 | 84 | /** 85 | * @JMS\SerializedName("services") 86 | * @JMS\Type("array") 87 | * 88 | * @var AdditionalService[]|null 89 | */ 90 | protected $services; 91 | 92 | public function getPrice(): ?float 93 | { 94 | return $this->price; 95 | } 96 | 97 | public function getDeliveryPeriodMin(): ?int 98 | { 99 | return $this->deliveryPeriodMin; 100 | } 101 | 102 | public function getDeliveryPeriodMax(): ?int 103 | { 104 | return $this->deliveryPeriodMax; 105 | } 106 | 107 | public function getTariffId(): ?int 108 | { 109 | return $this->tariffId; 110 | } 111 | 112 | public function getPriceByCurrency(): ?float 113 | { 114 | return $this->priceByCurrency; 115 | } 116 | 117 | public function getCurrency(): ?string 118 | { 119 | return $this->currency; 120 | } 121 | 122 | public function getDeliveryDateMin(): ?\DateTimeImmutable 123 | { 124 | return $this->deliveryDateMin; 125 | } 126 | 127 | public function getDeliveryDateMax(): ?\DateTimeImmutable 128 | { 129 | return $this->deliveryDateMax; 130 | } 131 | 132 | /** 133 | * @return AdditionalService[]|null 134 | */ 135 | public function getAdditionalServices() 136 | { 137 | return $this->services; 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /src/Serialization/NullableDateTimeHandler.php: -------------------------------------------------------------------------------- 1 |