1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
7
|
|
|
use SlevomatCsobGateway\Api\HttpMethod; |
8
|
|
|
use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
9
|
|
|
use SlevomatCsobGateway\Validator; |
10
|
|
|
|
11
|
|
|
class PaymentButtonRequest |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
private $merchantId; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
private $payId; |
23
|
|
|
|
24
|
|
|
/** @var \SlevomatCsobGateway\Call\PaymentButtonBrand */ |
25
|
|
|
private $brand; |
26
|
|
|
|
27
|
2 |
|
public function __construct( |
28
|
|
|
string $merchantId, |
29
|
|
|
string $payId, |
30
|
|
|
PaymentButtonBrand $brand |
31
|
|
|
) |
32
|
|
|
{ |
33
|
2 |
|
Validator::checkPayId($payId); |
34
|
|
|
|
35
|
2 |
|
$this->merchantId = $merchantId; |
36
|
2 |
|
$this->payId = $payId; |
37
|
2 |
|
$this->brand = $brand; |
38
|
2 |
|
} |
39
|
|
|
|
40
|
1 |
|
public function send(ApiClient $apiClient): PaymentButtonResponse |
41
|
|
|
{ |
42
|
|
|
$requestData = [ |
43
|
1 |
|
'merchantId' => $this->merchantId, |
44
|
1 |
|
'payId' => $this->payId, |
45
|
1 |
|
'brand' => $this->brand->getValue(), |
46
|
|
|
]; |
47
|
|
|
|
48
|
1 |
|
$response = $apiClient->post( |
49
|
1 |
|
'payment/button', |
50
|
1 |
|
$requestData, |
51
|
1 |
|
new SignatureDataFormatter([ |
52
|
1 |
|
'merchantId' => null, |
53
|
|
|
'payId' => null, |
54
|
|
|
'brand' => null, |
55
|
|
|
'dttm' => null, |
56
|
|
|
]), |
57
|
1 |
|
new SignatureDataFormatter([ |
58
|
1 |
|
'payId' => null, |
59
|
|
|
'dttm' => null, |
60
|
|
|
'resultCode' => null, |
61
|
|
|
'resultMessage' => null, |
62
|
|
|
'paymentStatus' => null, |
63
|
|
|
'redirect' => [ |
64
|
|
|
'method' => null, |
65
|
|
|
'url' => null, |
66
|
|
|
'params' => null, |
67
|
|
|
], |
68
|
|
|
]) |
69
|
|
|
); |
70
|
|
|
|
71
|
1 |
|
$data = $response->getData(); |
72
|
|
|
|
73
|
1 |
|
$redirectUrl = null; |
74
|
1 |
|
$redirectMethod = null; |
75
|
1 |
|
$redirectParams = []; |
76
|
1 |
|
if (isset($data['redirect'])) { |
77
|
1 |
|
$redirectUrl = $data['redirect']['url']; |
78
|
1 |
|
$redirectMethod = HttpMethod::get($data['redirect']['method']); |
79
|
1 |
|
$redirectParams = $data['redirect']['params'] ?? null; |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
return new PaymentButtonResponse( |
83
|
1 |
|
$data['payId'], |
84
|
1 |
|
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
85
|
1 |
|
ResultCode::get($data['resultCode']), |
86
|
1 |
|
$data['resultMessage'], |
87
|
1 |
|
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
88
|
1 |
|
$redirectMethod, |
89
|
1 |
|
$redirectUrl, |
90
|
1 |
|
$redirectParams |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|