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
|
1 |
|
public function __construct( |
28
|
|
|
string $merchantId, |
29
|
|
|
string $payId, |
30
|
|
|
PaymentButtonBrand $brand |
31
|
|
|
) |
32
|
|
|
{ |
33
|
1 |
|
Validator::checkPayId($payId); |
34
|
|
|
|
35
|
1 |
|
$this->merchantId = $merchantId; |
36
|
1 |
|
$this->payId = $payId; |
37
|
1 |
|
$this->brand = $brand; |
38
|
1 |
|
} |
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' => null, |
64
|
|
|
]) |
65
|
|
|
); |
66
|
|
|
|
67
|
1 |
|
$data = $response->getData(); |
68
|
|
|
|
69
|
1 |
|
$redirectUrl = null; |
70
|
1 |
|
$redirectMethod = null; |
71
|
1 |
|
$redirectParams = []; |
72
|
1 |
|
if (isset($data['redirect'])) { |
73
|
1 |
|
$redirectUrl = $data['redirect']['url']; |
74
|
1 |
|
$redirectMethod = HttpMethod::get($data['redirect']['method']); |
75
|
1 |
|
$redirectParams = $data['redirect']['params'] ?? null; |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
return new PaymentButtonResponse( |
79
|
1 |
|
$data['payId'], |
80
|
1 |
|
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
81
|
1 |
|
ResultCode::get($data['resultCode']), |
82
|
1 |
|
$data['resultMessage'], |
83
|
1 |
|
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
84
|
1 |
|
$redirectMethod, |
85
|
1 |
|
$redirectUrl, |
86
|
1 |
|
$redirectParams |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
} |
91
|
|
|
|