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