Completed
Push — master ( 55b55f...e456b8 )
by Tomáš
40:56
created

Balikobot::getBranchesForLocation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 2
nc 2
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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