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