1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace VasilDakov\Econt; |
6
|
|
|
|
7
|
|
|
use Fig\Http\Message\RequestMethodInterface; |
8
|
|
|
use Psr\Http\Client\ClientExceptionInterface; |
9
|
|
|
use Psr\Http\Client\ClientInterface; |
10
|
|
|
use Psr\Http\Message\RequestFactoryInterface; |
11
|
|
|
use Psr\Http\Message\RequestInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
2 |
|
* Class Econt |
15
|
|
|
* |
16
|
2 |
|
* @author Vasil Dakov <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class Econt implements EcontInterface |
19
|
|
|
{ |
20
|
|
|
public const API_URL = 'https://demo.econt.com'; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
private readonly Configuration $configuration, |
24
|
|
|
private readonly ClientInterface $client, |
25
|
|
|
private readonly RequestFactoryInterface $factory |
26
|
|
|
) { |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @throws ClientExceptionInterface |
31
|
|
|
*/ |
32
|
|
|
public function getClientProfiles(): string |
33
|
|
|
{ |
34
|
|
|
$request = $this->createRequest( |
35
|
|
|
RequestMethodInterface::METHOD_POST, |
36
|
|
|
self::API_URL . '/ee/services/Profile/ProfileService.getClientProfiles.json', |
37
|
|
|
[] |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$response = $this->client->sendRequest($request); |
41
|
|
|
|
42
|
|
|
return $response->getBody()->getContents(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @throws ClientExceptionInterface |
47
|
|
|
*/ |
48
|
|
|
public function getCountries(): string |
49
|
|
|
{ |
50
|
|
|
$request = $this->createRequest( |
51
|
|
|
RequestMethodInterface::METHOD_POST, |
52
|
|
|
self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCountries.json', |
53
|
|
|
[] |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$response = $this->client->sendRequest($request); |
57
|
|
|
|
58
|
|
|
return $response->getBody()->getContents(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @throws ClientExceptionInterface |
63
|
|
|
*/ |
64
|
|
|
public function getCities(array $data): string |
65
|
|
|
{ |
66
|
|
|
$request = $this->createRequest( |
67
|
|
|
RequestMethodInterface::METHOD_POST, |
68
|
|
|
self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getCities.json', |
69
|
|
|
[ |
70
|
|
|
Constants::COUNTRY_CODE => $data['countryCode'] |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$response = $this->client->sendRequest($request); |
75
|
|
|
|
76
|
|
|
return $response->getBody()->getContents(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getOffices(array $data): string |
80
|
|
|
{ |
81
|
|
|
$request = $this->createRequest( |
82
|
|
|
RequestMethodInterface::METHOD_POST, |
83
|
|
|
self::API_URL . '/ee/services/Nomenclatures/NomenclaturesService.getOffices.json', |
84
|
|
|
[ |
85
|
|
|
Constants::COUNTRY_CODE => $data['countryCode'], |
86
|
|
|
Constants::CITY_ID => $data['cityId'], |
87
|
|
|
] |
88
|
|
|
); |
89
|
|
|
|
90
|
|
|
$response = $this->client->sendRequest($request); |
91
|
|
|
|
92
|
|
|
return $response->getBody()->getContents(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function getShipmentStatuses(array $data): string |
97
|
|
|
{ |
98
|
|
|
$request = $this->createRequest( |
99
|
|
|
RequestMethodInterface::METHOD_POST, |
100
|
|
|
self::API_URL . '/ee/services/Shipments/ShipmentService.getShipmentStatuses.json', |
101
|
|
|
$data |
102
|
|
|
); |
103
|
|
|
|
104
|
|
|
$response = $this->client->sendRequest($request); |
105
|
|
|
|
106
|
|
|
return $response->getBody()->getContents(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $method |
112
|
|
|
* @param string $uri |
113
|
|
|
* @param array $data |
114
|
|
|
* @return RequestInterface |
115
|
|
|
*/ |
116
|
|
|
private function createRequest(string $method, string $uri, array $data): RequestInterface |
117
|
|
|
{ |
118
|
|
|
$request = $this->factory->createRequest($method, $uri); |
119
|
|
|
|
120
|
|
|
$request = $request->withAddedHeader('Content-Type', 'application/json'); |
121
|
|
|
$request = $request->withAddedHeader( |
122
|
|
|
'Authorization', |
123
|
|
|
'Basic ' . base64_encode( |
124
|
|
|
$this->configuration->username . ":" . $this->configuration->password |
125
|
|
|
) |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$request->getBody()->write(json_encode($data)); |
129
|
|
|
|
130
|
|
|
return $request; |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function getStreets(array $data): string |
134
|
|
|
{ |
135
|
|
|
return ''; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function getQuarters(array $data): string |
139
|
|
|
{ |
140
|
|
|
return ''; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function createLabel(array $data): string |
144
|
|
|
{ |
145
|
|
|
return ''; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function createLabels(array $data): string |
149
|
|
|
{ |
150
|
|
|
return ''; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function deleteLabels(array $data): string |
154
|
|
|
{ |
155
|
|
|
return ''; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|