|
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 readonly Client $client, |
|
32
|
|
|
private readonly CarrierFactory $carrierFactory, |
|
33
|
|
|
private readonly ServiceFactory $serviceFactory, |
|
34
|
|
|
private readonly ManipulationUnitFactory $unitFactory, |
|
35
|
|
|
private readonly CountryFactory $countryFactory, |
|
36
|
|
|
private readonly ZipCodeFactory $zipCodeFactory, |
|
37
|
|
|
private readonly AdrUnitFactory $adrUnitFactory, |
|
38
|
|
|
private readonly AttributeFactory $attributeFactory, |
|
39
|
|
|
) { |
|
40
|
34 |
|
} |
|
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
|
2 |
|
public function getZipCodes(string $carrier, string $service, ?string $country = null): ZipCodeIterator |
|
113
|
|
|
{ |
|
114
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ZIP_CODES, path: sprintf('%s/%s', $service, $country)); |
|
115
|
|
|
|
|
116
|
2 |
|
return $this->zipCodeFactory->createIterator($carrier, $service, $country, $response); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
2 |
|
public function getAdrUnits(string $carrier): AdrUnitCollection |
|
120
|
|
|
{ |
|
121
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::FULL_ADR_UNITS); |
|
122
|
|
|
|
|
123
|
2 |
|
return $this->adrUnitFactory->createCollection($carrier, $response); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
3 |
|
public function getAddAttributes(string $carrier): AttributeCollection |
|
127
|
|
|
{ |
|
128
|
3 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_ATTRIBUTES); |
|
129
|
|
|
|
|
130
|
3 |
|
return $this->attributeFactory->createCollection($carrier, $response); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
2 |
|
public function getAddServiceOptions(string $carrier): ServiceCollection |
|
134
|
|
|
{ |
|
135
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_SERVICE_OPTIONS); |
|
136
|
|
|
|
|
137
|
2 |
|
return $this->serviceFactory->createCollection($carrier, $response); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
2 |
|
public function getAddServiceOptionsForService(string $carrier, string $service): Service |
|
141
|
|
|
{ |
|
142
|
2 |
|
$response = $this->client->call(Version::V2V1, $carrier, Method::ADD_SERVICE_OPTIONS, path: $service); |
|
143
|
|
|
|
|
144
|
2 |
|
return $this->serviceFactory->create($carrier, $response); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|