|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
|
|
3
|
|
|
namespace SlevomatEET; |
|
4
|
|
|
|
|
5
|
|
|
use SlevomatEET\Cryptography\CryptographyService; |
|
6
|
|
|
use SlevomatEET\Driver\DriverRequestFailedException; |
|
7
|
|
|
use SlevomatEET\Driver\SoapClientDriver; |
|
8
|
|
|
|
|
9
|
|
|
class Client |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** @var \SlevomatEET\Cryptography\CryptographyService */ |
|
13
|
|
|
private $cryptographyService; |
|
14
|
|
|
|
|
15
|
|
|
/** @var \SlevomatEET\Configuration */ |
|
16
|
|
|
private $configuration; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \SlevomatEET\SoapClient|null */ |
|
19
|
|
|
private $soapClient; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \SlevomatEET\Driver\SoapClientDriver */ |
|
22
|
|
|
private $soapClientDriver; |
|
23
|
|
|
|
|
24
|
3 |
|
public function __construct(CryptographyService $cryptographyService, Configuration $configuration, SoapClientDriver $soapClientDriver) |
|
25
|
|
|
{ |
|
26
|
3 |
|
$this->cryptographyService = $cryptographyService; |
|
27
|
3 |
|
$this->configuration = $configuration; |
|
28
|
3 |
|
$this->soapClientDriver = $soapClientDriver; |
|
29
|
3 |
|
} |
|
30
|
|
|
|
|
31
|
3 |
|
public function send(Receipt $receipt): EvidenceResponse |
|
32
|
|
|
{ |
|
33
|
3 |
|
$request = new EvidenceRequest($receipt, $this->configuration, $this->cryptographyService); |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
3 |
|
$response = $this->getSoapClient()->OdeslaniTrzby($request->getRequestData()); |
|
37
|
1 |
|
} catch (DriverRequestFailedException $e) { |
|
38
|
1 |
|
throw new FailedRequestException($request, $e); |
|
39
|
|
|
} catch (\SoapFault $e) { |
|
40
|
|
|
throw new FailedRequestException($request, $e); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
2 |
|
$response = new EvidenceResponse($response, $request); |
|
44
|
2 |
|
if (!$response->isValid()) { |
|
45
|
1 |
|
throw new InvalidResponseReceivedException($response); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
return $response; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
3 |
|
private function getSoapClient(): SoapClient |
|
52
|
|
|
{ |
|
53
|
3 |
|
if ($this->soapClient === null) { |
|
54
|
1 |
|
$this->soapClient = new SoapClient($this->configuration->getEvidenceEnvironment()->getWsdlPath(), $this->cryptographyService, $this->soapClientDriver); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
3 |
|
return $this->soapClient; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|