Passed
Push — master ( f22ecf...a98eef )
by Andrey
03:27
created

AdditionalService::saveAddTerm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Daaner\NovaPoshta\Models;
4
5
use Daaner\NovaPoshta\NovaPoshta;
6
use Daaner\NovaPoshta\Traits\AdditionalServiceProperty;
7
use Daaner\NovaPoshta\Traits\DateTimes;
8
use Daaner\NovaPoshta\Traits\InternetDocumentProperty;
9
use Daaner\NovaPoshta\Traits\Limit;
10
11
class AdditionalService extends NovaPoshta
12
{
13
    protected $model = 'AdditionalService';
14
    protected $calledMethod;
15
    protected $methodProperties = null;
16
17
    use InternetDocumentProperty, AdditionalServiceProperty, Limit, DateTimes;
18
19
    /**
20
     * Проверка возможности создания заявки на возврат.
21
     *
22
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a778f519-8512-11ec-8ced-005056b2dbe1 Возможность возврата
23
     * @since 2022-11-06
24
     *
25
     * @param  string  $ttn  Номер ТТН
26
     * @return array
27
     */
28
    public function CheckPossibilityCreateReturn(string $ttn): array
29
    {
30
        $this->calledMethod = 'CheckPossibilityCreateReturn';
31
32
        $this->methodProperties['Number'] = $ttn;
33
34
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
35
    }
36
37
    /**
38
     * Проверка возможности создания заявки на переадресацию отправки.
39
     *
40
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a8d29fc2-8512-11ec-8ced-005056b2dbe1 Возможность переадресации
41
     * @since 2022-11-06
42
     *
43
     * @param  string  $ttn  Номер ТТН
44
     * @return array
45
     */
46
    public function checkPossibilityForRedirecting(string $ttn): array
47
    {
48
        $this->calledMethod = 'checkPossibilityForRedirecting';
49
50
        $this->methodProperties['Number'] = $ttn;
51
52
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
53
    }
54
55
    /**
56
     * Получение списка причин возврата.
57
     * Работает без авторизации.
58
     *
59
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7a6bacb-8512-11ec-8ced-005056b2dbe1 Список причин возврата
60
     * @since 2022-11-06
61
     *
62
     * @return array
63
     */
64
    public function getReturnReasons(): array
65
    {
66
        $this->calledMethod = 'getReturnReasons';
67
68
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false);
69
    }
70
71
    /**
72
     * Получение списка подтипов причины возврата.
73
     * Работает без авторизации.
74
     *
75
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7cb69ee-8512-11ec-8ced-005056b2dbe1 Список подтипов причины возврата
76
     * @since 2022-11-06
77
     *
78
     * @param  string|null  $ref  Ref причины
79
     * @return array
80
     */
81
    public function getReturnReasonsSubtypes(?string $ref = null): array
82
    {
83
        $this->calledMethod = 'getReturnReasonsSubtypes';
84
85
        $this->methodProperties['ReasonRef'] = $ref ?: config('novaposhta.ref_return_reasons');
86
87
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false);
88
    }
89
90
    /**
91
     * Получение списка заявок на возврат.
92
     *
93
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7cb69ee-8512-11ec-8ced-005056b2dbe1 Список заявок на возврат
94
     * @since 2022-11-06
95
     *
96
     * @return array
97
     */
98
    public function getReturnOrdersList(): array
99
    {
100
        $this->calledMethod = 'getReturnOrdersList';
101
102
        $this->getLimit();
103
        $this->getPage();
104
        $this->getDateBeginEnd();
105
106
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
107
    }
108
109
    /**
110
     * Получение списка заявок на переадресацию отправлений.
111
     *
112
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a8faa2e6-8512-11ec-8ced-005056b2dbe1 Список заявок на переадресацию
113
     * @since 2022-11-06
114
     *
115
     * @return array
116
     */
117
    public function getRedirectionOrdersList(): array
118
    {
119
        $this->calledMethod = 'getRedirectionOrdersList';
120
121
        $this->methodProperties = null;
122
123
        $this->getLimit();
124
        $this->getPage();
125
126
        $this->getNumber();
127
        $this->getDateBeginEnd();
128
129
        if ($this->Ref) {
130
            $this->methodProperties['Ref'] = $this->Ref;
131
        }
132
133
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
134
    }
135
136
    /**
137
     * Создание заявки на возврат.
138
     *
139
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a7fb4a3a-8512-11ec-8ced-005056b2dbe1 Возврат на адрес отправителя
140
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/5a64f960-e7fa-11ec-a60f-48df37b921db Возврат на новый адрес отделения
141
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/175baec3-8f0d-11ec-8ced-005056b2dbe1 Возврат на новый адрес по адресной доставке
142
     * @since 2022-11-06
143
     *
144
     * @param  string  $ttn  Номер ТТН
145
     * @param  string|null  $ownerDocumentType  Тип документа
146
     * @return array
147
     */
148
    public function save(string $ttn, ?string $ownerDocumentType = 'orderCargoReturn'): array
149
    {
150
        $this->calledMethod = 'save';
151
152
        $this->methodProperties['IntDocNumber'] = $ttn;
153
154
        $this->getPaymentMethod();
155
        $this->getNote();
156
157
        $this->methodProperties['OrderType'] = $ownerDocumentType;
158
159
        /**
160
         * ========================
161
         * Тип оформления
162
         * ========================.
163
         */
164
        // Обычный возврат
165
        if ($ownerDocumentType == 'orderCargoReturn') {
166
            // При возврате нужно указать причину и подтип причины
167
            $this->getReason();
168
            $this->getSubtypeReason();
169
170
            /**
171
             * Возврат/переадресация на адрес отправления.
172
             */
173
            $this->getReturnAddressRef();
174
175
            if (! $this->Note) {
176
                $this->methodProperties['Note'] = config('novaposhta.redirecting_note');
177
            }
178
        }
179
180
        // Переадресация
181
        if ($ownerDocumentType == 'orderRedirecting') {
182
            $this->getPayerType();
183
            $this->getCustomer();
184
            $this->getServiceType();
185
            $this->getRecipientData();
186
187
            if (! $this->Note) {
188
                $this->methodProperties['Note'] = config('novaposhta.return_note');
189
            }
190
        }
191
192
        // Продление хранения
193
        if ($ownerDocumentType == 'orderTermExtension') {
194
            $this->getPayerType();
195
            $this->getStorageFinalDate();
196
        }
197
198
        // Доп поля, если переадресация / возврат
199
        if ($ownerDocumentType == 'orderCargoReturn' || $ownerDocumentType == 'orderRedirecting') {
200
            /**
201
             * Возврат/переадресация на новый адрес отделения.
202
             */
203
            $this->getRecipientWarehouse();
204
205
            /**
206
             * Возврат/переадресация на новый адрес по адресной доставке.
207
             */
208
            $this->getRecipientSettlement();
209
        }
210
211
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
212
    }
213
214
    /**
215
     * Создание заявки на переадресацию.
216
     *
217
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/98acb0f6-8f0b-11ec-8ced-005056b2dbe1 Создание заявки на переадресацию
218
     * @since 2022-11-06
219
     *
220
     * @param  string  $ttn  Номер ТТН
221
     * @return array
222
     */
223
    public function saveRedirecting(string $ttn): array
224
    {
225
        return $this->save($ttn, 'orderRedirecting');
226
    }
227
228
    /**
229
     * Продление хранения посылки.
230
     *
231
     * @since 2022-11-07
232
     *
233
     * @param  string  $ttn  Номер ТТН
234
     * @return array
235
     */
236
    public function saveAddTerm(string $ttn): array
237
    {
238
        return $this->save($ttn, 'orderTermExtension');
239
    }
240
241
    /**
242
     * Удаление заявки на возврат, заявку об изменении данных или заявку переадресации.
243
     *
244
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a85bb34b-8512-11ec-8ced-005056b2dbe1 Удаление заявки
245
     * @since 2022-11-06
246
     *
247
     * @param  string  $Ref  Ref заявки
248
     * @return array
249
     */
250
    public function delete(string $Ref): array
251
    {
252
        $this->calledMethod = 'delete';
253
254
        $this->methodProperties['Ref'] = $Ref;
255
256
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
257
    }
258
259
    /**
260
     * Проверка продления хранения ТТН.
261
     *
262
     * @since 2022-11-06
263
     *
264
     * @param  string  $ttn  Номер ТТН
265
     * @return array
266
     */
267
    public function CheckPossibilityTermExtension(string $ttn): array
268
    {
269
        $this->calledMethod = 'CheckPossibilityTermExtension';
270
271
        $this->methodProperties['IntDocNumber'] = $ttn;
272
273
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
274
    }
275
276
    /**
277
     * Проверка на изменения в ТТН.
278
     *
279
     * @see https://developers.novaposhta.ua/view/model/a7682c1a-8512-11ec-8ced-005056b2dbe1/method/a886b776-8512-11ec-8ced-005056b2dbe1 Проверка на изменения в накладной
280
     * @since 2022-11-06
281
     *
282
     * @param  string  $ttn  Номер ТТН
283
     * @return array
284
     */
285
    public function CheckPossibilityChangeEW(string $ttn): array
286
    {
287
        $this->calledMethod = 'CheckPossibilityChangeEW';
288
289
        $this->methodProperties['IntDocNumber'] = $ttn;
290
291
        return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, true);
292
    }
293
}
294