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
|
|
|
* @param string $orderId |
40
|
|
|
* @param \DateTimeInterface|null $sendingDate |
41
|
|
|
* @param string|null $printType |
42
|
|
|
* |
43
|
|
|
* @return UploadedFile |
44
|
|
|
*/ |
45
|
|
|
public function orderF7Form(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
46
|
|
|
{ |
47
|
|
|
$request = $this->buildRequest([ |
48
|
|
|
'print-type' => $printType, |
49
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
50
|
|
|
]); |
51
|
|
|
|
52
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f7pdf", $request); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Форма Ф112ЭК для заказа. |
57
|
|
|
* |
58
|
|
|
* @param string $orderId |
59
|
|
|
* @param \DateTimeInterface|null $sendingDate |
60
|
|
|
* |
61
|
|
|
* @return UploadedFile |
62
|
|
|
*/ |
63
|
|
|
public function orderF112Form(string $orderId, ?\DateTimeInterface $sendingDate = null): UploadedFile |
64
|
|
|
{ |
65
|
|
|
$request = $this->buildRequest([ |
66
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
67
|
|
|
]); |
68
|
|
|
|
69
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f112pdf", $request); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function orderFormsBundleBacklog(string $orderId, ?\DateTimeInterface $sendingDate = null): UploadedFile |
73
|
|
|
{ |
74
|
|
|
$request = $this->buildRequest([ |
75
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
return $this->client->get("/1.0/forms/backlog/{$orderId}/forms", $request); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function orderFormBundle(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
82
|
|
|
{ |
83
|
|
|
$request = $this->buildRequest([ |
84
|
|
|
'print-type' => $printType, |
85
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
86
|
|
|
]); |
87
|
|
|
|
88
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/forms", $request); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Пакет документов для партии. |
93
|
|
|
* |
94
|
|
|
* @param string $batchName |
95
|
|
|
* @param string|null $printType |
96
|
|
|
* @param string|null $printTypeForm |
97
|
|
|
* |
98
|
|
|
* @return UploadedFile |
99
|
|
|
*/ |
100
|
|
|
public function batchFormBundle(string $batchName, ?string $printType = null, ?string $printTypeForm = null): UploadedFile |
101
|
|
|
{ |
102
|
|
|
$request = $this->buildRequest([ |
103
|
|
|
'print-type' => $printType, |
104
|
|
|
'print-type-form' => $printTypeForm, |
105
|
|
|
]); |
106
|
|
|
|
107
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/zip-all", $request); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Форма Ф103 для партии. |
112
|
|
|
* |
113
|
|
|
* @param string $batchName |
114
|
|
|
* |
115
|
|
|
* @return UploadedFile |
116
|
|
|
*/ |
117
|
|
|
public function batchF103Form(string $batchName): UploadedFile |
118
|
|
|
{ |
119
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/f103pdf"); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Форма акта осмотра содержимого партии. |
124
|
|
|
* |
125
|
|
|
* @param string $batchName |
126
|
|
|
* |
127
|
|
|
* @return UploadedFile |
128
|
|
|
*/ |
129
|
|
|
public function batchCheckingForm(string $batchName): UploadedFile |
130
|
|
|
{ |
131
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/completeness-checking-form"); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Подготовка и отправка электронной формы Ф103 для партии. |
136
|
|
|
* |
137
|
|
|
* @param string $batchName |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function batchCheckIn(string $batchName): bool |
142
|
|
|
{ |
143
|
|
|
return (bool) $this->client->get("/1.0/batch/{$batchName}/checkin"); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
private function formatSendingDate(?\DateTimeInterface $sendingDate): ?string |
147
|
|
|
{ |
148
|
|
|
return $sendingDate ? $sendingDate->format('Y-m-d') : null; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
private function buildRequest(array $query): Arrayable |
152
|
|
|
{ |
153
|
|
|
return new class($query) implements Arrayable { |
154
|
|
|
private $query; |
155
|
|
|
|
156
|
|
|
public function __construct(array $query) |
157
|
|
|
{ |
158
|
|
|
$this->query = $query; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function toArray(): array |
162
|
|
|
{ |
163
|
|
|
return $this->query; |
164
|
|
|
} |
165
|
|
|
}; |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|