Passed
Push — master ( 537d5b...b60ede )
by Andrey
03:11
created

AdditionalService::saveChangeCash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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