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