1 | <?php declare(strict_types = 1); |
||
15 | class ApiClient |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var ApiClientDriver |
||
20 | */ |
||
21 | private $driver; |
||
22 | |||
23 | /** |
||
24 | * @var CryptoService |
||
25 | */ |
||
26 | private $cryptoService; |
||
27 | |||
28 | /** |
||
29 | * @var LoggerInterface|null |
||
30 | */ |
||
31 | private $logger; |
||
32 | |||
33 | /** |
||
34 | * @var string|null |
||
35 | */ |
||
36 | private $apiUrl; |
||
37 | |||
38 | 16 | public function __construct( |
|
39 | ApiClientDriver $driver, |
||
40 | CryptoService $cryptoService, |
||
41 | string $apiUrl |
||
42 | ) |
||
43 | { |
||
44 | 16 | $this->driver = $driver; |
|
45 | 16 | $this->cryptoService = $cryptoService; |
|
46 | 16 | $this->apiUrl = $apiUrl; |
|
47 | 16 | } |
|
48 | |||
49 | 5 | public function setLogger(?LoggerInterface $logger): void |
|
53 | |||
54 | /** |
||
55 | * @param string $url |
||
56 | * @param mixed[] $data |
||
57 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
58 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
59 | * @param \Closure|null $responseValidityCallback |
||
60 | * @param ResponseExtensionHandler[] $extensions |
||
61 | * @return Response |
||
62 | * |
||
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 | * |
||
99 | * @throws PrivateKeyFileException |
||
100 | * @throws SigningFailedException |
||
101 | * @throws PublicKeyFileException |
||
102 | * @throws VerificationFailedException |
||
103 | * @throws RequestException |
||
104 | * @throws ApiClientDriverException |
||
105 | * @throws InvalidSignatureException |
||
106 | */ |
||
107 | 1 | public function post( |
|
125 | |||
126 | /** |
||
127 | * @param string $url |
||
128 | * @param mixed[] $data |
||
129 | * @param SignatureDataFormatter $requestSignatureDataFormatter |
||
130 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
131 | * @param ResponseExtensionHandler[] $extensions |
||
132 | * @return Response |
||
133 | * |
||
134 | * @throws PrivateKeyFileException |
||
135 | * @throws SigningFailedException |
||
136 | * @throws PublicKeyFileException |
||
137 | * @throws VerificationFailedException |
||
138 | * @throws RequestException |
||
139 | * @throws ApiClientDriverException |
||
140 | * @throws InvalidSignatureException |
||
141 | */ |
||
142 | 1 | public function put( |
|
160 | |||
161 | /** |
||
162 | * @param HttpMethod $method |
||
163 | * @param string $url |
||
164 | * @param mixed[] $queries |
||
165 | * @param mixed[]|null $data |
||
166 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
167 | * @param \Closure|null $responseValidityCallback |
||
168 | * @param ResponseExtensionHandler[] $extensions |
||
169 | * @return Response |
||
170 | * |
||
171 | * @throws PrivateKeyFileException |
||
172 | * @throws SigningFailedException |
||
173 | * @throws PublicKeyFileException |
||
174 | * @throws VerificationFailedException |
||
175 | * @throws RequestException |
||
176 | * @throws ApiClientDriverException |
||
177 | * @throws InvalidSignatureException |
||
178 | */ |
||
179 | 15 | private function request( |
|
267 | |||
268 | /** |
||
269 | * @param mixed[] $data |
||
270 | * @param SignatureDataFormatter $responseSignatureDataFormatter |
||
271 | * @return Response |
||
272 | * |
||
273 | * @throws InvalidSignatureException |
||
274 | * @throws PrivateKeyFileException |
||
275 | * @throws SigningFailedException |
||
276 | * @throws PublicKeyFileException |
||
277 | * @throws VerificationFailedException |
||
278 | */ |
||
279 | 1 | public function createResponseByData(array $data, SignatureDataFormatter $responseSignatureDataFormatter): Response |
|
294 | |||
295 | /** |
||
296 | * @param mixed[] $data |
||
297 | * @param SignatureDataFormatter $signatureDataFormatter |
||
298 | * @return mixed[] |
||
299 | * |
||
300 | * @throws PrivateKeyFileException |
||
301 | * @throws SigningFailedException |
||
302 | */ |
||
303 | 15 | private function prepareData(array $data, SignatureDataFormatter $signatureDataFormatter): array |
|
310 | |||
311 | /** |
||
312 | * @param mixed[] $responseData |
||
313 | * @param SignatureDataFormatter $signatureDataFormatter |
||
314 | * @return mixed[] |
||
315 | * |
||
316 | * @throws InvalidSignatureException |
||
317 | * @throws PublicKeyFileException |
||
318 | * @throws VerificationFailedException |
||
319 | */ |
||
320 | 8 | private function decodeData(array $responseData, SignatureDataFormatter $signatureDataFormatter): array |
|
335 | |||
336 | /** |
||
337 | * @param \SlevomatCsobGateway\Api\HttpMethod $method |
||
338 | * @param string $url |
||
339 | * @param mixed[] $queries |
||
340 | * @param mixed[]|null $requestData |
||
341 | * @param \SlevomatCsobGateway\Api\Response $response |
||
342 | * @param float $responseTime |
||
343 | */ |
||
344 | 16 | private function logRequest(HttpMethod $method, string $url, array $queries, ?array $requestData, Response $response, float $responseTime): void |
|
377 | |||
378 | } |
||
379 |