Documents   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Test Coverage

Coverage 7.69%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 12
eloc 29
c 4
b 0
f 0
dl 0
loc 178
ccs 3
cts 39
cp 0.0769
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A batchFormBundle() 0 8 1
A orderFormsBundleBacklog() 0 7 1
A batchF103Form() 0 3 1
A batchCheckIn() 0 3 1
A batchCheckingForm() 0 3 1
A easyReturnForm() 0 7 1
A orderF112Form() 0 8 1
A orderF7Form() 0 8 1
A __construct() 0 3 1
A formatSendingDate() 0 3 2
A orderFormBundle() 0 8 1
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\Core\GenericRequest;
18
use Appwilio\RussianPostSDK\Dispatching\Enum\PrintType;
19
use Appwilio\RussianPostSDK\Dispatching\Http\ApiClient;
20
use Appwilio\RussianPostSDK\Dispatching\Enum\PrintFormType;
21
22
final class Documents
23
{
24
    /** @var ApiClient */
25
    private $client;
26
27 1
    public function __construct(ApiClient $client)
28
    {
29 1
        $this->client = $client;
30 1
    }
31
32
    /**
33
     * Форма Ф7п для заказа.
34
     *
35
     * @see https://otpravka.pochta.ru/specification#/documents-create_f7_f22
36
     *
37
     * @param  string                   $orderId
38
     * @param  \DateTimeInterface|null  $sendingDate
39
     * @param  PrintType|null           $printType
40
     *
41
     * @return UploadedFile
42
     */
43
    public function orderF7Form(string $orderId, ?\DateTimeInterface $sendingDate = null, ?PrintType $printType = null): UploadedFile
44
    {
45
        $request = GenericRequest::create([
46
            'print-type'   => $printType,
47
            'sending-date' => $this->formatSendingDate($sendingDate),
48
        ]);
49
50
        return $this->client->get("/1.0/forms/{$orderId}/f7pdf", $request);
51
    }
52
53
    /**
54
     * Форма Ф112ЭК для заказа.
55
     *
56
     * @see https://otpravka.pochta.ru/specification#/documents-create_f112
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 = GenericRequest::create([
66
            'id'           => $orderId,
67
            'sending-date' => $this->formatSendingDate($sendingDate),
68
        ]);
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 = GenericRequest::create([
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  PrintType|null           $printType
100
     *
101
     * @return UploadedFile
102
     */
103
    public function orderFormBundle(string $orderId, ?\DateTimeInterface $sendingDate = null, ?PrintType $printType = null): UploadedFile
104
    {
105
        $request = GenericRequest::create([
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  PrintType|null      $printType
120
     * @param  PrintFormType|null  $printTypeForm
121
     *
122
     * @return UploadedFile
123
     */
124
    public function batchFormBundle(string $batchName, ?PrintType $printType = null, ?PrintFormType $printTypeForm = null): UploadedFile
125
    {
126
        $request = GenericRequest::create([
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
    /**
179
     * Возвратный ярлык на одной странице.
180
     *
181
     * @see https://otpravka.pochta.ru/specification#/documents-easy_return_pdf
182
     *
183
     * @param  string          $barcode
184
     * @param  PrintType|null  $printType
185
     *
186
     * @return UploadedFile
187
     */
188
    public function easyReturnForm(string $barcode, ?PrintType $printType = null): UploadedFile
189
    {
190
        $request = GenericRequest::create([
191
            'print-type' => $printType,
192
        ]);
193
194
        return $this->client->get("/1.0/forms/{$barcode}/easy-return-pdf", $request);
195
    }
196
197
    private function formatSendingDate(?\DateTimeInterface $sendingDate): ?string
198
    {
199
        return $sendingDate ? $sendingDate->format('Y-m-d') : null;
200
    }
201
}
202