1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Inspirum\Balikobot\Services; |
6
|
|
|
|
7
|
|
|
use Inspirum\Balikobot\Contracts\RequesterInterface; |
8
|
|
|
use Inspirum\Balikobot\Definitions\Option; |
9
|
|
|
use Inspirum\Balikobot\Definitions\Shipper; |
10
|
|
|
use Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection; |
11
|
|
|
use Inspirum\Balikobot\Model\Aggregates\PackageCollection; |
12
|
|
|
use Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection; |
13
|
|
|
use Inspirum\Balikobot\Model\Values\Branch; |
14
|
|
|
use Inspirum\Balikobot\Model\Values\Country; |
15
|
|
|
use Inspirum\Balikobot\Model\Values\OrderedPackage; |
16
|
|
|
use Inspirum\Balikobot\Model\Values\OrderedShipment; |
17
|
|
|
use Inspirum\Balikobot\Model\Values\Package; |
18
|
|
|
use Inspirum\Balikobot\Model\Values\PackageStatus; |
19
|
|
|
use Inspirum\Balikobot\Model\Values\PackageTransportCost; |
20
|
|
|
use Inspirum\Balikobot\Model\Values\PostCode; |
21
|
|
|
use function array_keys; |
22
|
|
|
use function count; |
23
|
|
|
use function in_array; |
24
|
|
|
|
25
|
|
|
class Balikobot |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Balikobot API |
29
|
|
|
* |
30
|
|
|
* @var \Inspirum\Balikobot\Services\Client |
31
|
|
|
*/ |
32
|
|
|
private Client $client; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Balikobot constructor |
36
|
|
|
* |
37
|
|
|
* @param \Inspirum\Balikobot\Contracts\RequesterInterface $requester |
38
|
|
|
*/ |
39
|
130 |
|
public function __construct(RequesterInterface $requester) |
40
|
|
|
{ |
41
|
130 |
|
$this->client = new Client($requester); |
42
|
130 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* All supported shipper services |
46
|
|
|
* |
47
|
|
|
* @return array<string> |
48
|
|
|
*/ |
49
|
1 |
|
public function getShippers(): array |
50
|
|
|
{ |
51
|
1 |
|
return Shipper::all(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Add packages |
56
|
|
|
* |
57
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
58
|
|
|
* |
59
|
|
|
* @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
60
|
|
|
* |
61
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
62
|
|
|
*/ |
63
|
11 |
|
public function addPackages(PackageCollection $packages): OrderedPackageCollection |
64
|
|
|
{ |
65
|
11 |
|
$labelsUrl = null; |
66
|
11 |
|
$response = $this->client->addPackages($packages->getShipper(), $packages->toArray(), $labelsUrl); |
67
|
|
|
|
68
|
10 |
|
$orderedPackages = new OrderedPackageCollection(); |
69
|
10 |
|
$orderedPackages->setLabelsUrl($labelsUrl); |
70
|
|
|
|
71
|
10 |
|
foreach ($response as $package) { |
72
|
10 |
|
$orderedPackages->add(OrderedPackage::newInstanceFromData($packages->getShipper(), $package)); |
73
|
|
|
} |
74
|
|
|
|
75
|
10 |
|
return $orderedPackages; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Exports order into Balikobot system |
80
|
|
|
* |
81
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
82
|
|
|
* |
83
|
|
|
* @return void |
84
|
|
|
* |
85
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
86
|
|
|
*/ |
87
|
3 |
|
public function dropPackages(OrderedPackageCollection $packages): void |
88
|
|
|
{ |
89
|
3 |
|
$this->client->dropPackages($packages->getShipper(), $packages->getPackageIds()); |
90
|
2 |
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Exports order into Balikobot system |
94
|
|
|
* |
95
|
|
|
* @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
96
|
|
|
* |
97
|
|
|
* @return void |
98
|
|
|
* |
99
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
100
|
|
|
*/ |
101
|
1 |
|
public function dropPackage(OrderedPackage $package): void |
102
|
|
|
{ |
103
|
1 |
|
$this->client->dropPackage($package->getShipper(), $package->getPackageId()); |
104
|
1 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Order shipment |
108
|
|
|
* |
109
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
110
|
|
|
* |
111
|
|
|
* @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
112
|
|
|
* |
113
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
114
|
|
|
*/ |
115
|
5 |
|
public function orderShipment(OrderedPackageCollection $packages): OrderedShipment |
116
|
|
|
{ |
117
|
5 |
|
$response = $this->client->orderShipment($packages->getShipper(), $packages->getPackageIds()); |
118
|
|
|
|
119
|
4 |
|
return OrderedShipment::newInstanceFromData($packages->getShipper(), $packages->getPackageIds(), $response); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Track package |
124
|
|
|
* |
125
|
|
|
* @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
126
|
|
|
* |
127
|
|
|
* @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
128
|
|
|
* |
129
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
130
|
|
|
*/ |
131
|
3 |
|
public function trackPackage(OrderedPackage $package): array |
132
|
|
|
{ |
133
|
3 |
|
$packages = new OrderedPackageCollection(); |
134
|
3 |
|
$packages->add($package); |
135
|
|
|
|
136
|
3 |
|
return $this->trackPackages($packages)[0]; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Track packages |
141
|
|
|
* |
142
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
143
|
|
|
* |
144
|
|
|
* @return array<array<\Inspirum\Balikobot\Model\Values\PackageStatus>>|\Inspirum\Balikobot\Model\Values\PackageStatus[][] |
145
|
|
|
* |
146
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
147
|
|
|
*/ |
148
|
6 |
|
public function trackPackages(OrderedPackageCollection $packages): array |
149
|
|
|
{ |
150
|
6 |
|
$response = $this->client->trackPackages($packages->getShipper(), $packages->getCarrierIds()); |
151
|
|
|
|
152
|
5 |
|
$statuses = []; |
153
|
|
|
|
154
|
5 |
|
foreach ($response as $responseStatuses) { |
155
|
5 |
|
$statuses[] = $this->createPackageStatusesCollection($responseStatuses); |
156
|
|
|
} |
157
|
|
|
|
158
|
5 |
|
return $statuses; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Track package last status |
163
|
|
|
* |
164
|
|
|
* @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
165
|
|
|
* |
166
|
|
|
* @return \Inspirum\Balikobot\Model\Values\PackageStatus |
167
|
|
|
* |
168
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
169
|
|
|
*/ |
170
|
2 |
|
public function trackPackageLastStatus(OrderedPackage $package): PackageStatus |
171
|
|
|
{ |
172
|
2 |
|
$packages = new OrderedPackageCollection(); |
173
|
2 |
|
$packages->add($package); |
174
|
|
|
|
175
|
2 |
|
return $this->trackPackagesLastStatus($packages)[0]; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Track package last status |
180
|
|
|
* |
181
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
182
|
|
|
* |
183
|
|
|
* @return array<\Inspirum\Balikobot\Model\Values\PackageStatus>|\Inspirum\Balikobot\Model\Values\PackageStatus[] |
184
|
|
|
* |
185
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
186
|
|
|
*/ |
187
|
5 |
|
public function trackPackagesLastStatus(OrderedPackageCollection $packages): array |
188
|
|
|
{ |
189
|
5 |
|
$response = $this->client->trackPackagesLastStatus($packages->getShipper(), $packages->getCarrierIds()); |
190
|
|
|
|
191
|
5 |
|
return $this->createPackageStatusesCollection($response); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Create package statuses collection for package |
196
|
|
|
* |
197
|
|
|
* @param array<array<string,float|string|null>> $response |
198
|
|
|
* |
199
|
|
|
* @return array<\Inspirum\Balikobot\Model\Values\PackageStatus> |
200
|
|
|
*/ |
201
|
10 |
|
private function createPackageStatusesCollection(array $response): array |
202
|
|
|
{ |
203
|
10 |
|
$statuses = []; |
204
|
|
|
|
205
|
10 |
|
foreach ($response as $status) { |
206
|
10 |
|
$statuses[] = PackageStatus::newInstanceFromData($status); |
207
|
|
|
} |
208
|
|
|
|
209
|
10 |
|
return $statuses; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get overview for given shipper |
214
|
|
|
* |
215
|
|
|
* @param string $shipper |
216
|
|
|
* |
217
|
|
|
* @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
218
|
|
|
* |
219
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
220
|
|
|
*/ |
221
|
3 |
|
public function getOverview(string $shipper): OrderedPackageCollection |
222
|
|
|
{ |
223
|
3 |
|
$response = $this->client->getOverview($shipper); |
224
|
|
|
|
225
|
3 |
|
$response = $response['packages']; |
226
|
|
|
|
227
|
3 |
|
$orderedPackages = new OrderedPackageCollection(); |
228
|
|
|
|
229
|
3 |
|
foreach ($response as $package) { |
230
|
2 |
|
$orderedPackage = OrderedPackage::newInstanceFromData($shipper, $package); |
231
|
2 |
|
$orderedPackages->add($orderedPackage); |
232
|
|
|
} |
233
|
|
|
|
234
|
3 |
|
return $orderedPackages; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get labels for orders |
239
|
|
|
* |
240
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
241
|
|
|
* |
242
|
|
|
* @return string |
243
|
|
|
* |
244
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
245
|
|
|
*/ |
246
|
4 |
|
public function getLabels(OrderedPackageCollection $packages): string |
247
|
|
|
{ |
248
|
4 |
|
return $this->client->getLabels($packages->getShipper(), $packages->getPackageIds()); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Gets complete information about a package |
253
|
|
|
* |
254
|
|
|
* @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
255
|
|
|
* |
256
|
|
|
* @return \Inspirum\Balikobot\Model\Values\Package |
257
|
|
|
* |
258
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
259
|
|
|
*/ |
260
|
4 |
|
public function getPackageInfo(OrderedPackage $package): Package |
261
|
|
|
{ |
262
|
4 |
|
$response = $this->client->getPackageInfoByCarrierId($package->getShipper(), $package->getCarrierId()); |
263
|
|
|
|
264
|
|
|
unset( |
265
|
3 |
|
$response['package_id'], |
266
|
3 |
|
$response['eshop_id'], |
267
|
3 |
|
$response['carrier_id'], |
268
|
3 |
|
$response['track_url'], |
269
|
3 |
|
$response['label_url'], |
270
|
3 |
|
$response['carrier_id_swap'], |
271
|
3 |
|
$response['pieces'] |
272
|
|
|
); |
273
|
|
|
|
274
|
3 |
|
$options = $response; |
275
|
3 |
|
$options[Option::EID] = $package->getBatchId(); |
276
|
|
|
|
277
|
3 |
|
return new Package($options); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Gets complete information about a package |
282
|
|
|
* |
283
|
|
|
* @param string $shipper |
284
|
|
|
* @param string $orderId |
285
|
|
|
* |
286
|
|
|
* @return \Inspirum\Balikobot\Model\Values\OrderedShipment |
287
|
|
|
* |
288
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
289
|
|
|
*/ |
290
|
4 |
|
public function getOrder(string $shipper, string $orderId): OrderedShipment |
291
|
|
|
{ |
292
|
4 |
|
$response = $this->client->getOrder($shipper, $orderId); |
293
|
|
|
|
294
|
3 |
|
return OrderedShipment::newInstanceFromData($shipper, $response['package_ids'], $response); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* Returns available services for the given shipper |
299
|
|
|
* |
300
|
|
|
* @param string $shipper |
301
|
|
|
* |
302
|
|
|
* @return array<string,string> |
303
|
|
|
* |
304
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
305
|
|
|
*/ |
306
|
6 |
|
public function getServices(string $shipper): array |
307
|
|
|
{ |
308
|
6 |
|
return $this->client->getServices($shipper); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* Returns available B2A services for the given shipper |
313
|
|
|
* |
314
|
|
|
* @param string $shipper |
315
|
|
|
* |
316
|
|
|
* @return array<string,string> |
317
|
|
|
* |
318
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
319
|
|
|
*/ |
320
|
3 |
|
public function getB2AServices(string $shipper): array |
321
|
|
|
{ |
322
|
3 |
|
return $this->client->getB2AServices($shipper); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* Returns all manipulation units for the given shipper |
327
|
|
|
* |
328
|
|
|
* @param string $shipper |
329
|
|
|
* @param bool $fullData |
330
|
|
|
* |
331
|
|
|
* @return array<string|array<mixed,mixed>> |
332
|
|
|
* |
333
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
334
|
|
|
*/ |
335
|
5 |
|
public function getManipulationUnits(string $shipper, bool $fullData = false): array |
336
|
|
|
{ |
337
|
5 |
|
return $this->client->getManipulationUnits($shipper, $fullData); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Returns available manipulation units for the given shipper |
342
|
|
|
* |
343
|
|
|
* @param string $shipper |
344
|
|
|
* @param bool $fullData |
345
|
|
|
* |
346
|
|
|
* @return array<string|array<mixed,mixed>> |
347
|
|
|
* |
348
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
349
|
|
|
*/ |
350
|
5 |
|
public function getActivatedManipulationUnits(string $shipper, bool $fullData = false): array |
351
|
|
|
{ |
352
|
5 |
|
return $this->client->getActivatedManipulationUnits($shipper, $fullData); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* Get all available branches |
357
|
|
|
* |
358
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
359
|
|
|
* |
360
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
361
|
|
|
*/ |
362
|
1 |
|
public function getBranches(): iterable |
363
|
|
|
{ |
364
|
1 |
|
foreach ($this->getShippers() as $shipper) { |
365
|
1 |
|
yield from $this->getBranchesForShipper($shipper); |
366
|
|
|
} |
367
|
1 |
|
} |
368
|
|
|
|
369
|
|
|
/** |
370
|
|
|
* Get all available branches for countries |
371
|
|
|
* |
372
|
|
|
* @param array<string> $countries |
373
|
|
|
* |
374
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
375
|
|
|
* |
376
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
377
|
|
|
*/ |
378
|
1 |
|
public function getBranchesForCountries(array $countries): iterable |
379
|
|
|
{ |
380
|
1 |
|
foreach ($this->getShippers() as $shipper) { |
381
|
1 |
|
yield from $this->getBranchesForShipperForCountries($shipper, $countries); |
382
|
|
|
} |
383
|
1 |
|
} |
384
|
|
|
|
385
|
|
|
/** |
386
|
|
|
* Get all available branches for given shipper |
387
|
|
|
* |
388
|
|
|
* @param string $shipper |
389
|
|
|
* |
390
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
391
|
|
|
* |
392
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
393
|
|
|
*/ |
394
|
2 |
|
public function getBranchesForShipper(string $shipper): iterable |
395
|
|
|
{ |
396
|
2 |
|
foreach ($this->getServicesForShipper($shipper) as $service) { |
397
|
2 |
|
yield from $this->getBranchesForShipperService($shipper, $service); |
398
|
|
|
} |
399
|
2 |
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Get all available branches for given shipper for countries |
403
|
|
|
* |
404
|
|
|
* @param string $shipper |
405
|
|
|
* @param array<string> $countries |
406
|
|
|
* |
407
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
408
|
|
|
* |
409
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
410
|
|
|
*/ |
411
|
2 |
|
public function getBranchesForShipperForCountries(string $shipper, array $countries): iterable |
412
|
|
|
{ |
413
|
2 |
|
foreach ($this->getServicesForShipper($shipper) as $service) { |
414
|
2 |
|
yield from $this->getBranchesForShipperServiceForCountries($shipper, $service, $countries); |
415
|
|
|
} |
416
|
2 |
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* Get services for shipper |
420
|
|
|
* |
421
|
|
|
* @param string $shipper |
422
|
|
|
* |
423
|
|
|
* @return iterable<string|null> |
424
|
|
|
* |
425
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
426
|
|
|
*/ |
427
|
4 |
|
private function getServicesForShipper(string $shipper): iterable |
428
|
|
|
{ |
429
|
4 |
|
$services = $this->getServices($shipper); |
430
|
|
|
|
431
|
4 |
|
if (count($services) === 0) { |
432
|
1 |
|
return yield from [null]; |
433
|
|
|
} |
434
|
|
|
|
435
|
3 |
|
foreach (array_keys($services) as $service) { |
436
|
3 |
|
yield (string) $service; |
437
|
|
|
} |
438
|
3 |
|
} |
439
|
|
|
|
440
|
|
|
/** |
441
|
|
|
* Get all available branches for given shipper and service type for countries |
442
|
|
|
* |
443
|
|
|
* @param string $shipper |
444
|
|
|
* @param string|null $service |
445
|
|
|
* @param array<string> $countries |
446
|
|
|
* |
447
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
448
|
|
|
* |
449
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
450
|
|
|
*/ |
451
|
4 |
|
public function getBranchesForShipperServiceForCountries( |
452
|
|
|
string $shipper, |
453
|
|
|
?string $service, |
454
|
|
|
array $countries |
455
|
|
|
): iterable { |
456
|
4 |
|
foreach ($this->getAllBranchesForShipperServiceForCountries($shipper, $service, $countries) as $branch) { |
457
|
4 |
|
if (in_array($branch->getCountry(), $countries)) { |
458
|
4 |
|
yield $branch; |
459
|
|
|
} |
460
|
|
|
} |
461
|
4 |
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Get all available branches for given shipper and service type filtered by countries if possible |
465
|
|
|
* |
466
|
|
|
* @param string $shipper |
467
|
|
|
* @param string|null $service |
468
|
|
|
* @param array<string> $countries |
469
|
|
|
* |
470
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
471
|
|
|
* |
472
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
473
|
|
|
*/ |
474
|
4 |
|
private function getAllBranchesForShipperServiceForCountries( |
475
|
|
|
string $shipper, |
476
|
|
|
?string $service, |
477
|
|
|
array $countries |
478
|
|
|
): iterable { |
479
|
4 |
|
if (Shipper::hasBranchCountryFilterSupport($shipper, $service) === false) { |
480
|
2 |
|
return yield from $this->getBranchesForShipperService($shipper, $service); |
481
|
|
|
} |
482
|
|
|
|
483
|
3 |
|
foreach ($countries as $country) { |
484
|
3 |
|
yield from $this->getBranchesForShipperService($shipper, $service, $country); |
485
|
|
|
} |
486
|
3 |
|
} |
487
|
|
|
|
488
|
|
|
/** |
489
|
|
|
* Get all available branches for given shipper and service type |
490
|
|
|
* |
491
|
|
|
* @param string $shipper |
492
|
|
|
* @param string|null $service |
493
|
|
|
* @param string|null $country |
494
|
|
|
* |
495
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
496
|
|
|
* |
497
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
498
|
|
|
*/ |
499
|
7 |
|
public function getBranchesForShipperService(string $shipper, ?string $service, ?string $country = null): iterable |
500
|
|
|
{ |
501
|
7 |
|
$useFullBranchRequest = Shipper::hasFullBranchesSupport($shipper, $service); |
502
|
|
|
|
503
|
7 |
|
foreach ($this->client->getBranches($shipper, $service, $country, fullBranchesRequest: $useFullBranchRequest, gzip: true) as $branch) { |
504
|
3 |
|
yield Branch::newInstanceFromData($shipper, $service, $branch); |
505
|
|
|
} |
506
|
6 |
|
} |
507
|
|
|
|
508
|
|
|
/** |
509
|
|
|
* Get all available branches for given shipper |
510
|
|
|
* |
511
|
|
|
* @param string $shipper |
512
|
|
|
* @param string $country |
513
|
|
|
* @param string $city |
514
|
|
|
* @param string|null $postcode |
515
|
|
|
* @param string|null $street |
516
|
|
|
* @param int|null $maxResults |
517
|
|
|
* @param float|null $radius |
518
|
|
|
* @param string|null $type |
519
|
|
|
* |
520
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\Branch[] |
521
|
|
|
* |
522
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
523
|
|
|
*/ |
524
|
5 |
|
public function getBranchesForLocation( |
525
|
|
|
string $shipper, |
526
|
|
|
string $country, |
527
|
|
|
string $city, |
528
|
|
|
?string $postcode = null, |
529
|
|
|
?string $street = null, |
530
|
|
|
?int $maxResults = null, |
531
|
|
|
?float $radius = null, |
532
|
|
|
?string $type = null, |
533
|
|
|
): iterable { |
534
|
5 |
|
$branches = $this->client->getBranchesForLocation( |
535
|
5 |
|
$shipper, |
536
|
|
|
$country, |
537
|
|
|
$city, |
538
|
|
|
$postcode, |
539
|
|
|
$street, |
540
|
|
|
$maxResults, |
541
|
|
|
$radius, |
542
|
|
|
$type, |
543
|
|
|
); |
544
|
|
|
|
545
|
4 |
|
foreach ($branches as $branch) { |
546
|
2 |
|
yield Branch::newInstanceFromData($shipper, null, $branch); |
547
|
|
|
} |
548
|
3 |
|
} |
549
|
|
|
|
550
|
|
|
/** |
551
|
|
|
* Returns list of countries where service with cash-on-delivery payment type is available in |
552
|
|
|
* |
553
|
|
|
* @param string $shipper |
554
|
|
|
* |
555
|
|
|
* @return array<array<int|string,array<string,array<string,mixed>>>> |
556
|
|
|
* |
557
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
558
|
|
|
*/ |
559
|
3 |
|
public function getCodCountries(string $shipper): array |
560
|
|
|
{ |
561
|
3 |
|
return $this->client->getCodCountries($shipper); |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* Returns list of countries where service is available in |
566
|
|
|
* |
567
|
|
|
* @param string $shipper |
568
|
|
|
* |
569
|
|
|
* @return array<array<int|string,string>> |
570
|
|
|
* |
571
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
572
|
|
|
*/ |
573
|
3 |
|
public function getCountries(string $shipper): array |
574
|
|
|
{ |
575
|
3 |
|
return $this->client->getCountries($shipper); |
576
|
|
|
} |
577
|
|
|
|
578
|
|
|
/** |
579
|
|
|
* Returns available branches for the given shipper and its service |
580
|
|
|
* |
581
|
|
|
* @param string $shipper |
582
|
|
|
* @param string $service |
583
|
|
|
* @param string|null $country |
584
|
|
|
* |
585
|
|
|
* @return \Generator|\Inspirum\Balikobot\Model\Values\PostCode[] |
586
|
|
|
* |
587
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
588
|
|
|
*/ |
589
|
4 |
|
public function getPostCodes(string $shipper, string $service, ?string $country = null): iterable |
590
|
|
|
{ |
591
|
4 |
|
foreach ($this->client->getPostCodes($shipper, $service, $country) as $postcode) { |
592
|
2 |
|
yield PostCode::newInstanceFromData($shipper, $service, $postcode); |
593
|
|
|
} |
594
|
3 |
|
} |
595
|
|
|
|
596
|
|
|
/** |
597
|
|
|
* Check package(s) data |
598
|
|
|
* |
599
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
600
|
|
|
* |
601
|
|
|
* @return void |
602
|
|
|
* |
603
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
604
|
|
|
*/ |
605
|
3 |
|
public function checkPackages(PackageCollection $packages): void |
606
|
|
|
{ |
607
|
3 |
|
$this->client->checkPackages($packages->getShipper(), $packages->toArray()); |
608
|
2 |
|
} |
609
|
|
|
|
610
|
|
|
/** |
611
|
|
|
* Returns available manipulation units for the given shipper |
612
|
|
|
* |
613
|
|
|
* @param string $shipper |
614
|
|
|
* @param bool $fullData |
615
|
|
|
* |
616
|
|
|
* @return array<string|array<mixed,mixed>> |
617
|
|
|
* |
618
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
619
|
|
|
*/ |
620
|
5 |
|
public function getAdrUnits(string $shipper, bool $fullData = false): array |
621
|
|
|
{ |
622
|
5 |
|
return $this->client->getAdrUnits($shipper, $fullData); |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Returns available activated services for the given shipper |
627
|
|
|
* |
628
|
|
|
* @param string $shipper |
629
|
|
|
* |
630
|
|
|
* @return array<string,mixed> |
631
|
|
|
* |
632
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
633
|
|
|
*/ |
634
|
3 |
|
public function getActivatedServices(string $shipper): array |
635
|
|
|
{ |
636
|
3 |
|
return $this->client->getActivatedServices($shipper); |
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
/** |
640
|
|
|
* Order shipments from place B (typically supplier / previous consignee) to place A (shipping point) |
641
|
|
|
* |
642
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
643
|
|
|
* |
644
|
|
|
* @return \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection|\Inspirum\Balikobot\Model\Values\OrderedPackage[] |
645
|
|
|
* |
646
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
647
|
|
|
*/ |
648
|
5 |
|
public function orderB2AShipment(PackageCollection $packages): OrderedPackageCollection |
649
|
|
|
{ |
650
|
5 |
|
$response = $this->client->orderB2AShipment($packages->getShipper(), $packages->toArray()); |
651
|
|
|
|
652
|
4 |
|
$orderedPackages = new OrderedPackageCollection(); |
653
|
|
|
|
654
|
4 |
|
foreach ($response as $i => $package) { |
655
|
4 |
|
$package[Option::EID] = (string) $packages->offsetGet($i)->getEID(); |
656
|
4 |
|
$orderedPackage = OrderedPackage::newInstanceFromData($packages->getShipper(), $package); |
657
|
4 |
|
$orderedPackages->add($orderedPackage); |
658
|
|
|
} |
659
|
|
|
|
660
|
4 |
|
return $orderedPackages; |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* Get PDF link with signed consignment delivery document by the recipient |
665
|
|
|
* |
666
|
|
|
* @param \Inspirum\Balikobot\Model\Values\OrderedPackage $package |
667
|
|
|
* |
668
|
|
|
* @return string |
669
|
|
|
* |
670
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
671
|
|
|
*/ |
672
|
2 |
|
public function getProofOfDelivery(OrderedPackage $package): string |
673
|
|
|
{ |
674
|
2 |
|
$packages = new OrderedPackageCollection(); |
675
|
2 |
|
$packages->add($package); |
676
|
|
|
|
677
|
2 |
|
return $this->getProofOfDeliveries($packages)[0]; |
678
|
|
|
} |
679
|
|
|
|
680
|
|
|
/** |
681
|
|
|
* Get array of PDF links with signed consignment delivery document by the recipient |
682
|
|
|
* |
683
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\OrderedPackageCollection $packages |
684
|
|
|
* |
685
|
|
|
* @return array<string> |
686
|
|
|
* |
687
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
688
|
|
|
*/ |
689
|
6 |
|
public function getProofOfDeliveries(OrderedPackageCollection $packages): array |
690
|
|
|
{ |
691
|
6 |
|
return $this->client->getProofOfDeliveries($packages->getShipper(), $packages->getCarrierIds()); |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
/** |
695
|
|
|
* Obtain the price of carriage at consignment level |
696
|
|
|
* |
697
|
|
|
* @param \Inspirum\Balikobot\Model\Aggregates\PackageCollection $packages |
698
|
|
|
* |
699
|
|
|
* @return \Inspirum\Balikobot\Model\Aggregates\PackageTransportCostCollection|\Inspirum\Balikobot\Model\Values\PackageTransportCost[] |
700
|
|
|
* |
701
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
702
|
|
|
*/ |
703
|
4 |
|
public function getTransportCosts(PackageCollection $packages): PackageTransportCostCollection |
704
|
|
|
{ |
705
|
4 |
|
$response = $this->client->getTransportCosts($packages->getShipper(), $packages->toArray()); |
706
|
|
|
|
707
|
3 |
|
$transportCosts = new PackageTransportCostCollection($packages->getShipper()); |
708
|
|
|
|
709
|
3 |
|
foreach ($response as $package) { |
710
|
3 |
|
$transportCost = PackageTransportCost::newInstanceFromData($packages->getShipper(), $package); |
711
|
3 |
|
$transportCosts->add($transportCost); |
712
|
|
|
} |
713
|
|
|
|
714
|
3 |
|
return $transportCosts; |
715
|
|
|
} |
716
|
|
|
|
717
|
|
|
/** |
718
|
|
|
* Get information on individual countries of the world |
719
|
|
|
* |
720
|
|
|
* @return array<string,\Inspirum\Balikobot\Model\Values\Country>|\Inspirum\Balikobot\Model\Values\Country[] |
721
|
|
|
* |
722
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
723
|
|
|
*/ |
724
|
3 |
|
public function getCountriesData(): array |
725
|
|
|
{ |
726
|
3 |
|
$response = $this->client->getCountriesData(); |
727
|
|
|
|
728
|
3 |
|
$countries = []; |
729
|
|
|
|
730
|
3 |
|
foreach ($response as $code => $country) { |
731
|
2 |
|
$countries[$code] = Country::newInstanceFromData($country); |
732
|
|
|
} |
733
|
|
|
|
734
|
3 |
|
return $countries; |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
/** |
738
|
|
|
* Method for obtaining news in the Balikobot API |
739
|
|
|
* |
740
|
|
|
* @return array<string,mixed> |
741
|
|
|
* |
742
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
743
|
|
|
*/ |
744
|
1 |
|
public function getChangelog(): array |
745
|
|
|
{ |
746
|
1 |
|
return $this->client->getChangelog(); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* Method for obtaining a list of additional services by individual transport services |
751
|
|
|
* |
752
|
|
|
* @param string $shipper |
753
|
|
|
* |
754
|
|
|
* @return array<string,array<string,mixed>> |
755
|
|
|
* |
756
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
757
|
|
|
*/ |
758
|
3 |
|
public function getAddAttributes(string $shipper): array |
759
|
|
|
{ |
760
|
3 |
|
return $this->client->getAddAttributes($shipper); |
761
|
|
|
} |
762
|
|
|
|
763
|
|
|
/** |
764
|
|
|
* Method for obtaining a list of additional services by individual transport services |
765
|
|
|
* |
766
|
|
|
* @param string $shipper |
767
|
|
|
* @param string|null $service |
768
|
|
|
* @param bool $fullData |
769
|
|
|
* |
770
|
|
|
* @return array<string,string|array<string,string|array<mixed,mixed>>> |
771
|
|
|
* |
772
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
773
|
|
|
*/ |
774
|
8 |
|
public function getAddServiceOptions(string $shipper, ?string $service = null, bool $fullData = false): array |
775
|
|
|
{ |
776
|
8 |
|
return $this->client->getAddServiceOptions($shipper, $service, $fullData); |
777
|
|
|
} |
778
|
|
|
|
779
|
|
|
/** |
780
|
|
|
* Method for obtaining info about used API keys |
781
|
|
|
* |
782
|
|
|
* @return array<string,mixed> |
783
|
|
|
* |
784
|
|
|
* @throws \Inspirum\Balikobot\Contracts\ExceptionInterface |
785
|
|
|
*/ |
786
|
1 |
|
public function getAccountInfo(): array |
787
|
|
|
{ |
788
|
1 |
|
return $this->client->getAccountInfo(); |
789
|
|
|
} |
790
|
|
|
} |
791
|
|
|
|