1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Inspirum\Balikobot\Service; |
6
|
|
|
|
7
|
|
|
use Inspirum\Balikobot\Client\Client; |
8
|
|
|
use Inspirum\Balikobot\Definitions\Method; |
9
|
|
|
use Inspirum\Balikobot\Definitions\Version; |
10
|
|
|
use Inspirum\Balikobot\Model\AdrUnit\AdrUnitCollection; |
11
|
|
|
use Inspirum\Balikobot\Model\AdrUnit\AdrUnitFactory; |
12
|
|
|
use Inspirum\Balikobot\Model\Attribute\AttributeCollection; |
13
|
|
|
use Inspirum\Balikobot\Model\Attribute\AttributeFactory; |
14
|
|
|
use Inspirum\Balikobot\Model\Carrier\Carrier; |
15
|
|
|
use Inspirum\Balikobot\Model\Carrier\CarrierCollection; |
16
|
|
|
use Inspirum\Balikobot\Model\Carrier\CarrierFactory; |
17
|
|
|
use Inspirum\Balikobot\Model\Country\CountryCollection; |
18
|
|
|
use Inspirum\Balikobot\Model\Country\CountryFactory; |
19
|
|
|
use Inspirum\Balikobot\Model\ManipulationUnit\ManipulationUnitCollection; |
20
|
|
|
use Inspirum\Balikobot\Model\ManipulationUnit\ManipulationUnitFactory; |
21
|
|
|
use Inspirum\Balikobot\Model\Service\Service; |
22
|
|
|
use Inspirum\Balikobot\Model\Service\ServiceCollection; |
23
|
|
|
use Inspirum\Balikobot\Model\Service\ServiceFactory; |
24
|
|
|
use Inspirum\Balikobot\Model\ZipCode\ZipCodeFactory; |
25
|
|
|
use Inspirum\Balikobot\Model\ZipCode\ZipCodeIterator; |
26
|
|
|
use function sprintf; |
27
|
|
|
|
28
|
|
|
final class DefaultSettingService implements SettingService |
29
|
|
|
{ |
30
|
34 |
|
public function __construct( |
31
|
|
|
private Client $client, |
32
|
|
|
private CarrierFactory $carrierFactory, |
33
|
|
|
private ServiceFactory $serviceFactory, |
34
|
|
|
private ManipulationUnitFactory $unitFactory, |
35
|
|
|
private CountryFactory $countryFactory, |
36
|
|
|
private ZipCodeFactory $zipCodeFactory, |
37
|
|
|
private AdrUnitFactory $adrUnitFactory, |
38
|
|
|
private AttributeFactory $attributeFactory, |
39
|
|
|
) { |
40
|
|
|
} |
41
|
|
|
|
42
|
4 |
|
public function getCarriers(): CarrierCollection |
43
|
|
|
{ |
44
|
4 |
|
$response = $this->client->call(Version::V2V1, null, Method::INFO_CARRIERS); |
45
|
|
|
|
46
|
4 |
|
return $this->carrierFactory->createCollection($response); |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
public function getCarrier(string $carrier): Carrier |
50
|
|
|
{ |
51
|
3 |
|
$response = $this->client->call(Version::V2V1, null, Method::INFO_CARRIERS, path: $carrier); |
52
|
|
|
|
53
|
3 |
|
return $this->carrierFactory->create($carrier, $response); |
54
|
|
|
} |
55
|
|
|
|
56
|
3 |
|
public function getServices(string $carrier): ServiceCollection |
57
|
|
|
{ |
58
|
3 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::SERVICES); |
59
|
|
|
|
60
|
3 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
61
|
|
|
} |
62
|
|
|
|
63
|
2 |
|
public function getActivatedServices(string $carrier): ServiceCollection |
64
|
|
|
{ |
65
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ACTIVATED_SERVICES); |
66
|
|
|
|
67
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
68
|
|
|
} |
69
|
|
|
|
70
|
2 |
|
public function getB2AServices(string $carrier): ServiceCollection |
71
|
|
|
{ |
72
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::B2A_SERVICES); |
73
|
|
|
|
74
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
75
|
|
|
} |
76
|
|
|
|
77
|
2 |
|
public function getManipulationUnits(string $carrier): ManipulationUnitCollection |
78
|
|
|
{ |
79
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::MANIPULATION_UNITS); |
80
|
|
|
|
81
|
2 |
|
return $this->unitFactory->createCollection($carrier, $response); |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
public function getActivatedManipulationUnits(string $carrier): ManipulationUnitCollection |
85
|
|
|
{ |
86
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ACTIVATED_MANIPULATION_UNITS); |
87
|
|
|
|
88
|
2 |
|
return $this->unitFactory->createCollection($carrier, $response); |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function getCodCountries(string $carrier): ServiceCollection |
92
|
|
|
{ |
93
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::CASH_ON_DELIVERY_COUNTRIES); |
94
|
|
|
|
95
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
96
|
|
|
} |
97
|
|
|
|
98
|
2 |
|
public function getCountries(string $carrier): ServiceCollection |
99
|
|
|
{ |
100
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::COUNTRIES); |
101
|
|
|
|
102
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
103
|
|
|
} |
104
|
|
|
|
105
|
2 |
|
public function getCountriesData(): CountryCollection |
106
|
|
|
{ |
107
|
2 |
|
$response = $this->client->call(Version::V2V1, null, Method::GET_COUNTRIES_DATA); |
108
|
|
|
|
109
|
2 |
|
return $this->countryFactory->createCollection($response); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** @inheritDoc */ |
113
|
2 |
|
public function getZipCodes(string $carrier, string $service, ?string $country = null): ZipCodeIterator |
114
|
|
|
{ |
115
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ZIP_CODES, path: sprintf('%s/%s', $service, $country)); |
116
|
|
|
|
117
|
2 |
|
return $this->zipCodeFactory->createIterator($carrier, $service, $country, $response); |
118
|
|
|
} |
119
|
|
|
|
120
|
2 |
|
public function getAdrUnits(string $carrier): AdrUnitCollection |
121
|
|
|
{ |
122
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::FULL_ADR_UNITS); |
123
|
|
|
|
124
|
2 |
|
return $this->adrUnitFactory->createCollection($carrier, $response); |
125
|
|
|
} |
126
|
|
|
|
127
|
3 |
|
public function getAddAttributes(string $carrier): AttributeCollection |
128
|
|
|
{ |
129
|
3 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_ATTRIBUTES); |
130
|
|
|
|
131
|
3 |
|
return $this->attributeFactory->createCollection($carrier, $response); |
132
|
|
|
} |
133
|
|
|
|
134
|
2 |
|
public function getAddServiceOptions(string $carrier): ServiceCollection |
135
|
|
|
{ |
136
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_SERVICE_OPTIONS); |
137
|
|
|
|
138
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
139
|
|
|
} |
140
|
|
|
|
141
|
2 |
|
public function getAddServiceOptionsForService(string $carrier, string $service): Service |
142
|
|
|
{ |
143
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_SERVICE_OPTIONS, path: $service); |
144
|
|
|
|
145
|
2 |
|
return $this->serviceFactory->create($carrier, $response); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|