1 | <?php declare(strict_types = 1); |
||
24 | class ApiClient |
||
25 | { |
||
26 | |||
27 | /** @var ApiClientDriver */ |
||
28 | private $driver; |
||
29 | |||
30 | /** @var CryptoService */ |
||
31 | private $cryptoService; |
||
32 | |||
33 | /** @var LoggerInterface|null */ |
||
34 | private $logger; |
||
35 | |||
36 | /** @var string|null */ |
||
37 | private $apiUrl; |
||
38 | |||
39 | 16 | public function __construct( |
|
40 | ApiClientDriver $driver, |
||
41 | CryptoService $cryptoService, |
||
42 | string $apiUrl |
||
43 | ) |
||
44 | { |
||
45 | 16 | $this->driver = $driver; |
|
46 | 16 | $this->cryptoService = $cryptoService; |
|
47 | 16 | $this->apiUrl = $apiUrl; |
|
48 | 16 | } |
|
49 | |||
50 | 5 | public function setLogger(?LoggerInterface $logger): void |
|
51 | { |
||
52 | 5 | $this->logger = $logger; |
|
53 | 5 | } |
|
54 | |||
55 | /** |
||
56 | * @param string $url |
||
57 | * @param mixed[] $data |
||
58 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
59 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
60 | * @param \Closure|null $responseValidityCallback |
||
61 | * @param ResponseExtensionHandler[] $extensions |
||
62 | * @return Response |
||
63 | * @throws PrivateKeyFileException |
||
64 | * @throws SigningFailedException |
||
65 | * @throws PublicKeyFileException |
||
66 | * @throws VerificationFailedException |
||
67 | * @throws RequestException |
||
68 | * @throws ApiClientDriverException |
||
69 | * @throws InvalidSignatureException |
||
70 | */ |
||
71 | 13 | public function get( |
|
90 | |||
91 | /** |
||
92 | * @param string $url |
||
93 | * @param mixed[] $data |
||
94 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
95 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
96 | * @param ResponseExtensionHandler[] $extensions |
||
97 | * @return Response |
||
98 | * @throws PrivateKeyFileException |
||
99 | * @throws SigningFailedException |
||
100 | * @throws PublicKeyFileException |
||
101 | * @throws VerificationFailedException |
||
102 | * @throws RequestException |
||
103 | * @throws ApiClientDriverException |
||
104 | * @throws InvalidSignatureException |
||
105 | */ |
||
106 | 1 | public function post( |
|
124 | |||
125 | /** |
||
126 | * @param string $url |
||
127 | * @param mixed[] $data |
||
128 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
129 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
130 | * @param ResponseExtensionHandler[] $extensions |
||
131 | * @return Response |
||
132 | * @throws PrivateKeyFileException |
||
133 | * @throws SigningFailedException |
||
134 | * @throws PublicKeyFileException |
||
135 | * @throws VerificationFailedException |
||
136 | * @throws RequestException |
||
137 | * @throws ApiClientDriverException |
||
138 | * @throws InvalidSignatureException |
||
139 | */ |
||
140 | 1 | public function put( |
|
158 | |||
159 | /** |
||
160 | * @param HttpMethod $method |
||
161 | * @param string $url |
||
162 | * @param mixed[] $queries |
||
163 | * @param mixed[]|null $data |
||
164 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
165 | * @param \Closure|null $responseValidityCallback |
||
166 | * @param ResponseExtensionHandler[] $extensions |
||
167 | * @return Response |
||
168 | * @throws PrivateKeyFileException |
||
169 | * @throws SigningFailedException |
||
170 | * @throws PublicKeyFileException |
||
171 | * @throws VerificationFailedException |
||
172 | * @throws RequestException |
||
173 | * @throws ApiClientDriverException |
||
174 | * @throws InvalidSignatureException |
||
175 | */ |
||
176 | 15 | private function request( |
|
263 | |||
264 | /** |
||
265 | * @param mixed[] $data |
||
266 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
267 | * @return Response |
||
268 | * @throws InvalidSignatureException |
||
269 | * @throws PrivateKeyFileException |
||
270 | * @throws SigningFailedException |
||
271 | * @throws PublicKeyFileException |
||
272 | * @throws VerificationFailedException |
||
273 | */ |
||
274 | 1 | public function createResponseByData(array $data, SignatureDataFormatter $responseSignatureDataFormatter): Response |
|
289 | |||
290 | /** |
||
291 | * @param mixed[] $data |
||
292 | * @param SignatureDataFormatter $signatureDataFormatter |
||
293 | * @return mixed[] |
||
294 | * @throws PrivateKeyFileException |
||
295 | * @throws SigningFailedException |
||
296 | */ |
||
297 | 15 | private function prepareData(array $data, SignatureDataFormatter $signatureDataFormatter): array |
|
304 | |||
305 | /** |
||
306 | * @param mixed[] $responseData |
||
307 | * @param SignatureDataFormatter $signatureDataFormatter |
||
308 | * @return mixed[] |
||
309 | * @throws InvalidSignatureException |
||
310 | * @throws PublicKeyFileException |
||
311 | * @throws VerificationFailedException |
||
312 | */ |
||
313 | 8 | private function decodeData(array $responseData, SignatureDataFormatter $signatureDataFormatter): array |
|
328 | |||
329 | /** |
||
330 | * @param \SlevomatCsobGateway\Api\HttpMethod $method |
||
331 | * @param string $url |
||
332 | * @param mixed[] $queries |
||
333 | * @param mixed[]|null $requestData |
||
334 | * @param \SlevomatCsobGateway\Api\Response $response |
||
335 | * @param float $responseTime |
||
336 | */ |
||
337 | 16 | private function logRequest(HttpMethod $method, string $url, array $queries, ?array $requestData, Response $response, float $responseTime): void |
|
370 | |||
371 | } |
||
372 |