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