|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Daaner\NovaPoshta\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Daaner\NovaPoshta\NovaPoshta; |
|
6
|
|
|
use Daaner\NovaPoshta\Traits\AddressSettlementProperty; |
|
7
|
|
|
use Daaner\NovaPoshta\Traits\Limit; |
|
8
|
|
|
use Daaner\NovaPoshta\Traits\WarehousesFilter; |
|
9
|
|
|
|
|
10
|
|
|
class Address extends NovaPoshta |
|
11
|
|
|
{ |
|
12
|
|
|
use Limit, WarehousesFilter, AddressSettlementProperty; |
|
13
|
|
|
|
|
14
|
|
|
protected $model = 'Address'; |
|
15
|
|
|
protected $calledMethod; |
|
16
|
|
|
protected $methodProperties = []; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Получение списка областей. |
|
20
|
|
|
* Работает без авторизации. |
|
21
|
|
|
* |
|
22
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a20ee6e4-8512-11ec-8ced-005056b2dbe1 Получение списка областей |
|
23
|
|
|
* @since 2022-11-03 |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getAreas(): array |
|
28
|
|
|
{ |
|
29
|
|
|
$this->calledMethod = 'getAreas'; |
|
30
|
|
|
$this->methodProperties = null; |
|
31
|
|
|
|
|
32
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Получение списка городов. |
|
37
|
|
|
* Работает без авторизации. |
|
38
|
|
|
* |
|
39
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a1e6f0a7-8512-11ec-8ced-005056b2dbe1 Получение списка городов |
|
40
|
|
|
* @since 2022-11-03 |
|
41
|
|
|
* |
|
42
|
|
|
* @param string|null $find Строка или Ref поиска |
|
43
|
|
|
* @param bool|null $searchByString Поиск по Ref = false или по строке |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
|
|
public function getCities(?string $find = null, ?bool $searchByString = true): array |
|
47
|
|
|
{ |
|
48
|
|
|
$this->calledMethod = 'getCities'; |
|
49
|
|
|
|
|
50
|
|
|
$this->getLimit(); |
|
51
|
|
|
$this->getPage(); |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Если значения пустые - вставляем насильно. |
|
55
|
|
|
*/ |
|
56
|
|
|
if (! $this->limit) { |
|
57
|
|
|
$this->methodProperties['Limit'] = config('novaposhta.page_limit'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ($find) { |
|
61
|
|
|
if ($searchByString) { |
|
62
|
|
|
$this->methodProperties['FindByString'] = $find; |
|
63
|
|
|
} else { |
|
64
|
|
|
$this->methodProperties['Ref'] = $find; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
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/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a2322f38-8512-11ec-8ced-005056b2dbe1 Получение списка отделений и почтоматов в городах |
|
76
|
|
|
* @since 2022-11-03 |
|
77
|
|
|
* |
|
78
|
|
|
* @param string|null $cityRef Строка или Ref поиска |
|
79
|
|
|
* @param bool|null $searchByString Поиск по Ref = false или по строке |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getWarehouses(?string $cityRef = null, ?bool $searchByString = true): array |
|
83
|
|
|
{ |
|
84
|
|
|
$this->calledMethod = 'getWarehouses'; |
|
85
|
|
|
|
|
86
|
|
|
$this->getLimit(); |
|
87
|
|
|
$this->getPage(); |
|
88
|
|
|
$this->getTypeOfWarehouseRef(); |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Если значения пустые - вставляем насильно. |
|
92
|
|
|
*/ |
|
93
|
|
|
if (! $this->limit) { |
|
94
|
|
|
$this->methodProperties['Limit'] = config('novaposhta.page_limit'); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
if ($cityRef) { |
|
98
|
|
|
if ($searchByString) { |
|
99
|
|
|
$this->methodProperties['CityName'] = $cityRef; |
|
100
|
|
|
} else { |
|
101
|
|
|
$this->methodProperties['CityRef'] = $cityRef; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Получение типов отделений. |
|
110
|
|
|
* Работает без авторизации. |
|
111
|
|
|
* |
|
112
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a2587b53-8512-11ec-8ced-005056b2dbe1 Получение типов отделений |
|
113
|
|
|
* @since 2022-11-03 |
|
114
|
|
|
* |
|
115
|
|
|
* @return array |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getWarehouseTypes(): array |
|
118
|
|
|
{ |
|
119
|
|
|
$this->calledMethod = 'getWarehouseTypes'; |
|
120
|
|
|
$this->methodProperties = null; |
|
121
|
|
|
|
|
122
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Получение списка отделений в населенном пункте. |
|
127
|
|
|
* Работает без авторизации. |
|
128
|
|
|
* |
|
129
|
|
|
* @since 2022-11-03 НЕ ДОКУМЕНТИРОВАНО |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $settlementRef Ref населенного пункта |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
|
public function getWarehouseSettlements(string $settlementRef): array |
|
135
|
|
|
{ |
|
136
|
|
|
$this->calledMethod = 'getWarehouses'; |
|
137
|
|
|
$this->getTypeOfWarehouseRef(); |
|
138
|
|
|
|
|
139
|
|
|
$this->methodProperties['SettlementRef'] = $settlementRef; |
|
140
|
|
|
|
|
141
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Поиск населенных пунктов из справочника Settlements. |
|
146
|
|
|
* Не стандартная выдача ответа!!! |
|
147
|
|
|
* Работает без авторизации. |
|
148
|
|
|
* |
|
149
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a0eb83ab-8512-11ec-8ced-005056b2dbe1 Поиск населенных пунктов |
|
150
|
|
|
* @since 2022-11-03 |
|
151
|
|
|
* |
|
152
|
|
|
* @param string $search Строка поиска |
|
153
|
|
|
* @return array |
|
154
|
|
|
*/ |
|
155
|
|
|
public function searchSettlements(string $search): array |
|
156
|
|
|
{ |
|
157
|
|
|
$this->calledMethod = 'searchSettlements'; |
|
158
|
|
|
$this->getLimit(); |
|
159
|
|
|
|
|
160
|
|
|
$this->methodProperties['CityName'] = $search; |
|
161
|
|
|
|
|
162
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* Поиск улиц в населенных пунктах. |
|
167
|
|
|
* Не стандартная выдача ответа!!! |
|
168
|
|
|
* Работает без авторизации. |
|
169
|
|
|
* |
|
170
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a1329635-8512-11ec-8ced-005056b2dbe1 Поиск улиц в населенных пунктах |
|
171
|
|
|
* @since 2022-11-03 |
|
172
|
|
|
* |
|
173
|
|
|
* @param string $ref Ref |
|
174
|
|
|
* @param string $street Поиск улицы (минимум 2 буквы) |
|
175
|
|
|
* @return array |
|
176
|
|
|
*/ |
|
177
|
|
|
public function searchSettlementStreets(string $ref, string $street): array |
|
178
|
|
|
{ |
|
179
|
|
|
$this->calledMethod = 'searchSettlementStreets'; |
|
180
|
|
|
$this->getLimit(); |
|
181
|
|
|
|
|
182
|
|
|
$this->methodProperties['SettlementRef'] = $ref; |
|
183
|
|
|
$this->methodProperties['StreetName'] = $street; |
|
184
|
|
|
|
|
185
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Получение улиц в городе по CityRef. |
|
190
|
|
|
* Работает без авторизации. |
|
191
|
|
|
* |
|
192
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a27c20d7-8512-11ec-8ced-005056b2dbe1 Получение улиц в городе |
|
193
|
|
|
* @since 2022-11-03 |
|
194
|
|
|
* |
|
195
|
|
|
* @param string $cityRef Ref города |
|
196
|
|
|
* @param string|null $find Строка поиска |
|
197
|
|
|
* @return array |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getStreet(string $cityRef, ?string $find = null): array |
|
200
|
|
|
{ |
|
201
|
|
|
$this->calledMethod = 'getStreet'; |
|
202
|
|
|
$this->getLimit(); |
|
203
|
|
|
$this->getPage(); |
|
204
|
|
|
|
|
205
|
|
|
$this->methodProperties['CityRef'] = $cityRef; |
|
206
|
|
|
if ($find) { |
|
207
|
|
|
$this->methodProperties['FindByString'] = $find; |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Справочник населенных пунктов Украины. |
|
215
|
|
|
* Работает без авторизации. |
|
216
|
|
|
* |
|
217
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a1c42723-8512-11ec-8ced-005056b2dbe1 Справочник населенных пунктов |
|
218
|
|
|
* @since 2022-11-03 |
|
219
|
|
|
* |
|
220
|
|
|
* @param string|null $find Строка поиска |
|
221
|
|
|
* @return array |
|
222
|
|
|
*/ |
|
223
|
|
|
public function getSettlements(?string $find = null): array |
|
224
|
|
|
{ |
|
225
|
|
|
$this->calledMethod = 'getSettlements'; |
|
226
|
|
|
|
|
227
|
|
|
/** |
|
228
|
|
|
* TODO Лимит установлен хардкорно |
|
229
|
|
|
* $this->getLimit();. |
|
230
|
|
|
* |
|
231
|
|
|
* Нужен лимит 150, иначе значение totalCount имеет не верный формат |
|
232
|
|
|
* Устанавливаю насильно, возможно позже исправят |
|
233
|
|
|
*/ |
|
234
|
|
|
$this->methodProperties['Limit'] = 150; |
|
235
|
|
|
|
|
236
|
|
|
$this->getPage(); |
|
237
|
|
|
|
|
238
|
|
|
//add AddressSettlementProperty |
|
239
|
|
|
$this->getAreaRef(); |
|
240
|
|
|
$this->getRegionRef(); |
|
241
|
|
|
$this->getWarehouse(); |
|
242
|
|
|
$this->getRef(); |
|
243
|
|
|
|
|
244
|
|
|
if ($find) { |
|
245
|
|
|
$this->methodProperties['FindByString'] = $find; |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
return $this->getResponse($this->model, $this->calledMethod, $this->methodProperties, false); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
/** |
|
252
|
|
|
* Создать адрес контрагента (отправитель / получатель). |
|
253
|
|
|
* |
|
254
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a155d0d9-8512-11ec-8ced-005056b2dbe1 Создать адрес контрагента |
|
255
|
|
|
* @deprecated НЕ СДЕЛАНО |
|
256
|
|
|
* |
|
257
|
|
|
* TODO Не сделано |
|
258
|
|
|
* |
|
259
|
|
|
* @return false |
|
260
|
|
|
*/ |
|
261
|
|
|
public function save() |
|
262
|
|
|
{ |
|
263
|
|
|
$this->calledMethod = 'save'; |
|
264
|
|
|
|
|
265
|
|
|
return false; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
/** |
|
269
|
|
|
* Редактировать адрес контрагента (отправитель / получатель). |
|
270
|
|
|
* |
|
271
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a19ba934-8512-11ec-8ced-005056b2dbe1 Редактировать адрес контрагента |
|
272
|
|
|
* @deprecated НЕ СДЕЛАНО |
|
273
|
|
|
* |
|
274
|
|
|
* TODO Не сделано |
|
275
|
|
|
* |
|
276
|
|
|
* @return false |
|
277
|
|
|
*/ |
|
278
|
|
|
public function update() |
|
279
|
|
|
{ |
|
280
|
|
|
$this->calledMethod = 'update'; |
|
281
|
|
|
|
|
282
|
|
|
return false; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Удалить адрес контрагента (отправитель / получатель). |
|
287
|
|
|
* |
|
288
|
|
|
* @see https://developers.novaposhta.ua/view/model/a0cf0f5f-8512-11ec-8ced-005056b2dbe1/method/a177069a-8512-11ec-8ced-005056b2dbe1 Удалить адрес контрагента |
|
289
|
|
|
* @deprecated НЕ СДЕЛАНО |
|
290
|
|
|
* |
|
291
|
|
|
* TODO Не сделано |
|
292
|
|
|
* |
|
293
|
|
|
* @return false |
|
294
|
|
|
*/ |
|
295
|
|
|
public function delete() |
|
296
|
|
|
{ |
|
297
|
|
|
$this->calledMethod = 'delete'; |
|
298
|
|
|
|
|
299
|
|
|
return false; |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|