1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of RussianPost SDK package. |
5
|
|
|
* |
6
|
|
|
* © Appwilio (http://appwilio.com), JhaoDa (https://github.com/jhaoda) |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Documents; |
15
|
|
|
|
16
|
|
|
use GuzzleHttp\Psr7\UploadedFile; |
17
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Http\ApiClient; |
18
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
19
|
|
|
|
20
|
|
|
final class Documents |
21
|
|
|
{ |
22
|
|
|
public const PRINT_TYPE_PAPER = 'PAPER'; |
23
|
|
|
public const PRINT_TYPE_THERMO = 'THERMO'; |
24
|
|
|
|
25
|
|
|
public const PRINT_FORM_ONE_SIDE = 'ONE_SIDED'; |
26
|
|
|
public const PRINT_FORM_TWO_SIDE = 'TWO_SIDED'; |
27
|
|
|
|
28
|
|
|
/** @var ApiClient */ |
29
|
|
|
private $client; |
30
|
|
|
|
31
|
|
|
public function __construct(ApiClient $client) |
32
|
|
|
{ |
33
|
|
|
$this->client = $client; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Форма Ф7п для заказа. |
38
|
|
|
* |
39
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-create_f7_f22 |
40
|
|
|
* |
41
|
|
|
* @param string $orderId |
42
|
|
|
* @param \DateTimeInterface|null $sendingDate |
43
|
|
|
* @param string|null $printType |
44
|
|
|
* |
45
|
|
|
* @return UploadedFile |
46
|
|
|
*/ |
47
|
|
|
public function orderF7Form(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
48
|
|
|
{ |
49
|
|
|
$request = $this->buildRequest([ |
50
|
|
|
'print-type' => $printType, |
51
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f7pdf", $request); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Форма Ф112ЭК для заказа. |
59
|
|
|
* |
60
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-create_f112 |
61
|
|
|
* |
62
|
|
|
* @param string $orderId |
63
|
|
|
* |
64
|
|
|
* @return UploadedFile |
65
|
|
|
*/ |
66
|
|
|
public function orderF112Form(string $orderId): UploadedFile |
67
|
|
|
{ |
68
|
|
|
$request = $this->buildRequest(); |
69
|
|
|
|
70
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f112pdf", $request); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Формы для заказа (до формирования партии). |
75
|
|
|
* |
76
|
|
|
* https://otpravka.pochta.ru/specification#/documents-create_forms_backlog |
77
|
|
|
* |
78
|
|
|
* @param string $orderId |
79
|
|
|
* @param \DateTimeInterface|null $sendingDate |
80
|
|
|
* |
81
|
|
|
* @return UploadedFile |
82
|
|
|
*/ |
83
|
|
|
public function orderFormsBundleBacklog(string $orderId, ?\DateTimeInterface $sendingDate = null): UploadedFile |
84
|
|
|
{ |
85
|
|
|
$request = $this->buildRequest([ |
86
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
87
|
|
|
]); |
88
|
|
|
|
89
|
|
|
return $this->client->get("/1.0/forms/backlog/{$orderId}/forms", $request); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Формы для заказа (после формирования партии). |
94
|
|
|
* |
95
|
|
|
* @sse https://otpravka.pochta.ru/specification#/documents-create_forms |
96
|
|
|
* |
97
|
|
|
* @param string $orderId |
98
|
|
|
* @param \DateTimeInterface|null $sendingDate |
99
|
|
|
* @param string|null $printType |
100
|
|
|
* |
101
|
|
|
* @return UploadedFile |
102
|
|
|
*/ |
103
|
|
|
public function orderFormBundle(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
104
|
|
|
{ |
105
|
|
|
$request = $this->buildRequest([ |
106
|
|
|
'print-type' => $printType, |
107
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
108
|
|
|
]); |
109
|
|
|
|
110
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/forms", $request); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Пакет документов для партии. |
115
|
|
|
* |
116
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-create_all_docs |
117
|
|
|
* |
118
|
|
|
* @param string $batchName |
119
|
|
|
* @param string|null $printType |
120
|
|
|
* @param string|null $printTypeForm |
121
|
|
|
* |
122
|
|
|
* @return UploadedFile |
123
|
|
|
*/ |
124
|
|
|
public function batchFormBundle(string $batchName, ?string $printType = null, ?string $printTypeForm = null): UploadedFile |
125
|
|
|
{ |
126
|
|
|
$request = $this->buildRequest([ |
127
|
|
|
'print-type' => $printType, |
128
|
|
|
'print-type-form' => $printTypeForm, |
129
|
|
|
]); |
130
|
|
|
|
131
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/zip-all", $request); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Форма Ф103 для партии. |
136
|
|
|
* |
137
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-create_f103 |
138
|
|
|
* |
139
|
|
|
* @param string $batchName |
140
|
|
|
* |
141
|
|
|
* @return UploadedFile |
142
|
|
|
*/ |
143
|
|
|
public function batchF103Form(string $batchName): UploadedFile |
144
|
|
|
{ |
145
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/f103pdf"); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Форма акта осмотра содержимого партии. |
150
|
|
|
* |
151
|
|
|
* Данный акт будет создан только в том случае, если подключена услуга проверки комплектности. |
152
|
|
|
* |
153
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-create_comp_check_form |
154
|
|
|
* |
155
|
|
|
* @param string $batchName |
156
|
|
|
* |
157
|
|
|
* @return UploadedFile |
158
|
|
|
*/ |
159
|
|
|
public function batchCheckingForm(string $batchName): UploadedFile |
160
|
|
|
{ |
161
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/completeness-checking-form"); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Подготовка и отправка электронной формы Ф103 для партии. |
166
|
|
|
* |
167
|
|
|
* @see https://otpravka.pochta.ru/specification#/documents-checkin |
168
|
|
|
* |
169
|
|
|
* @param string $batchName |
170
|
|
|
* |
171
|
|
|
* @return bool |
172
|
|
|
*/ |
173
|
|
|
public function batchCheckIn(string $batchName): bool |
174
|
|
|
{ |
175
|
|
|
return (bool) $this->client->get("/1.0/batch/{$batchName}/checkin"); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
private function formatSendingDate(?\DateTimeInterface $sendingDate): ?string |
179
|
|
|
{ |
180
|
|
|
return $sendingDate ? $sendingDate->format('Y-m-d') : null; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
private function buildRequest(array $query = []): Arrayable |
184
|
|
|
{ |
185
|
|
|
return new class($query) implements Arrayable { |
186
|
|
|
private $query; |
187
|
|
|
|
188
|
|
|
public function __construct(array $query) |
189
|
|
|
{ |
190
|
|
|
$this->query = $query; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function toArray(): array |
194
|
|
|
{ |
195
|
|
|
return $this->query; |
196
|
|
|
} |
197
|
|
|
}; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|