|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Appwilio\RussianPostSDK\Dispatching\Endpoints\Documents; |
|
6
|
|
|
|
|
7
|
|
|
use GuzzleHttp\Psr7\UploadedFile; |
|
8
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Http\ApiClient; |
|
9
|
|
|
use Appwilio\RussianPostSDK\Dispatching\Contracts\Arrayable; |
|
10
|
|
|
|
|
11
|
|
|
final class Documents |
|
12
|
|
|
{ |
|
13
|
|
|
public const PRINT_TYPE_PAPER = 'PAPER'; |
|
14
|
|
|
public const PRINT_TYPE_THERMO = 'THERMO'; |
|
15
|
|
|
|
|
16
|
|
|
public const PRINT_FORM_ONE_SIDE = 'ONE_SIDED'; |
|
17
|
|
|
public const PRINT_FORM_TWO_SIDE = 'TWO_SIDED'; |
|
18
|
|
|
|
|
19
|
|
|
/** @var ApiClient */ |
|
20
|
|
|
private $client; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(ApiClient $client) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->client = $client; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Форма Ф7п для заказа. |
|
29
|
|
|
* |
|
30
|
|
|
* @param string $orderId |
|
31
|
|
|
* @param \DateTimeInterface|null $sendingDate |
|
32
|
|
|
* @param string|null $printType |
|
33
|
|
|
* |
|
34
|
|
|
* @return UploadedFile |
|
35
|
|
|
*/ |
|
36
|
|
|
public function orderF7Form(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
|
37
|
|
|
{ |
|
38
|
|
|
$request = $this->buildRequest([ |
|
39
|
|
|
'print-type' => $printType, |
|
40
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
|
41
|
|
|
]); |
|
42
|
|
|
|
|
43
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f7pdf", $request); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Форма Ф112ЭК для заказа. |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $orderId |
|
50
|
|
|
* @param \DateTimeInterface|null $sendingDate |
|
51
|
|
|
* |
|
52
|
|
|
* @return UploadedFile |
|
53
|
|
|
*/ |
|
54
|
|
|
public function orderF112Form(string $orderId, ?\DateTimeInterface $sendingDate = null): UploadedFile |
|
55
|
|
|
{ |
|
56
|
|
|
$request = $this->buildRequest([ |
|
57
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/f112pdf", $request); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function orderFormsBundleBacklog(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/backlog/{$orderId}/forms", $request); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function orderFormBundle(string $orderId, ?\DateTimeInterface $sendingDate = null, ?string $printType = null): UploadedFile |
|
73
|
|
|
{ |
|
74
|
|
|
$request = $this->buildRequest([ |
|
75
|
|
|
'print-type' => $printType, |
|
76
|
|
|
'sending-date' => $this->formatSendingDate($sendingDate), |
|
77
|
|
|
]); |
|
78
|
|
|
|
|
79
|
|
|
return $this->client->get("/1.0/forms/{$orderId}/forms", $request); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Пакет документов для партии. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $batchName |
|
86
|
|
|
* @param string|null $printType |
|
87
|
|
|
* @param string|null $printTypeForm |
|
88
|
|
|
* |
|
89
|
|
|
* @return UploadedFile |
|
90
|
|
|
*/ |
|
91
|
|
|
public function batchFormBundle(string $batchName, ?string $printType = null, ?string $printTypeForm = null): UploadedFile |
|
92
|
|
|
{ |
|
93
|
|
|
$request = $this->buildRequest([ |
|
94
|
|
|
'print-type' => $printType, |
|
95
|
|
|
'print-type-form' => $printTypeForm, |
|
96
|
|
|
]); |
|
97
|
|
|
|
|
98
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/zip-all", $request); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Форма Ф103 для партии. |
|
103
|
|
|
* |
|
104
|
|
|
* @param string $batchName |
|
105
|
|
|
* |
|
106
|
|
|
* @return UploadedFile |
|
107
|
|
|
*/ |
|
108
|
|
|
public function batchF103Form(string $batchName): UploadedFile |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/f103pdf"); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Форма акта осмотра содержимого партии. |
|
115
|
|
|
* |
|
116
|
|
|
* @param string $batchName |
|
117
|
|
|
* |
|
118
|
|
|
* @return UploadedFile |
|
119
|
|
|
*/ |
|
120
|
|
|
public function batchCheckingForm(string $batchName): UploadedFile |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->client->get("/1.0/forms/{$batchName}/completeness-checking-form"); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Подготовка и отправка электронной формы Ф103 для партии. |
|
127
|
|
|
* |
|
128
|
|
|
* @param string $batchName |
|
129
|
|
|
* |
|
130
|
|
|
* @return bool |
|
131
|
|
|
*/ |
|
132
|
|
|
public function batchCheckIn(string $batchName): bool |
|
133
|
|
|
{ |
|
134
|
|
|
return (bool) $this->client->get("/1.0/batch/{$batchName}/checkin"); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
private function formatSendingDate(?\DateTimeInterface $sendingDate): ?string |
|
138
|
|
|
{ |
|
139
|
|
|
return $sendingDate ? $sendingDate->format('Y-m-d') : null; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
private function buildRequest(array $query): Arrayable |
|
143
|
|
|
{ |
|
144
|
|
|
return new class($query) implements Arrayable { |
|
145
|
|
|
private $query; |
|
146
|
|
|
|
|
147
|
|
|
public function __construct(array $query) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->query = $query; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
public function toArray(): array |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->query; |
|
155
|
|
|
} |
|
156
|
|
|
}; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|