1 | <?php declare(strict_types = 1); |
||
2 | |||
3 | namespace SlevomatCsobGateway\Call; |
||
4 | |||
5 | use DateTimeImmutable; |
||
6 | use SlevomatCsobGateway\Api\ApiClient; |
||
7 | use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
||
8 | use SlevomatCsobGateway\Validator; |
||
9 | |||
10 | class ClosePaymentRequest |
||
11 | { |
||
12 | |||
13 | /** @var string */ |
||
14 | private $merchantId; |
||
15 | |||
16 | /** @var string */ |
||
17 | private $payId; |
||
18 | |||
19 | /** @var int|null */ |
||
20 | private $totalAmount; |
||
21 | |||
22 | 2 | public function __construct( |
|
23 | string $merchantId, |
||
24 | string $payId, |
||
25 | ?int $totalAmount = null |
||
26 | ) |
||
27 | { |
||
28 | 2 | Validator::checkPayId($payId); |
|
29 | |||
30 | 2 | $this->merchantId = $merchantId; |
|
31 | 2 | $this->payId = $payId; |
|
32 | 2 | $this->totalAmount = $totalAmount; |
|
33 | 2 | } |
|
34 | |||
35 | 1 | public function send(ApiClient $apiClient): PaymentResponse |
|
36 | { |
||
37 | $data = [ |
||
38 | 1 | 'merchantId' => $this->merchantId, |
|
39 | 1 | 'payId' => $this->payId, |
|
40 | ]; |
||
41 | |||
42 | 1 | if ($this->totalAmount !== null) { |
|
43 | 1 | $data['totalAmount'] = $this->totalAmount; |
|
44 | } |
||
45 | |||
46 | 1 | $response = $apiClient->put( |
|
47 | 1 | 'payment/close', |
|
48 | $data, |
||
49 | 1 | new SignatureDataFormatter([ |
|
50 | 1 | 'merchantId' => null, |
|
51 | 'payId' => null, |
||
52 | 'dttm' => null, |
||
53 | 'totalAmount' => null, |
||
54 | ]), |
||
55 | 1 | new SignatureDataFormatter([ |
|
56 | 1 | 'payId' => null, |
|
57 | 'dttm' => null, |
||
58 | 'resultCode' => null, |
||
59 | 'resultMessage' => null, |
||
60 | 'paymentStatus' => null, |
||
61 | 'authCode' => null, |
||
62 | ]) |
||
63 | ); |
||
64 | |||
65 | 1 | $data = $response->getData(); |
|
66 | |||
67 | 1 | return new PaymentResponse( |
|
68 | 1 | $data['payId'], |
|
69 | 1 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
70 | 1 | ResultCode::get($data['resultCode']), |
|
71 | 1 | $data['resultMessage'], |
|
72 | 1 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
73 | 1 | $data['authCode'] ?? null |
|
74 | ); |
||
75 | } |
||
76 | |||
77 | } |
||
78 |