1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call\Masterpass; |
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 BasicFinishRequest |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private $merchantId; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private $payId; |
25
|
|
|
|
26
|
|
|
/** @var mixed[] */ |
27
|
|
|
private $callbackParams; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $merchantId |
31
|
|
|
* @param string $payId |
32
|
|
|
* @param mixed[] $callbackParams |
33
|
|
|
*/ |
34
|
2 |
|
public function __construct( |
35
|
|
|
string $merchantId, |
36
|
|
|
string $payId, |
37
|
|
|
array $callbackParams |
38
|
|
|
) |
39
|
|
|
{ |
40
|
2 |
|
Validator::checkPayId($payId); |
41
|
|
|
|
42
|
2 |
|
$this->merchantId = $merchantId; |
43
|
2 |
|
$this->payId = $payId; |
44
|
2 |
|
$this->callbackParams = $callbackParams; |
45
|
2 |
|
} |
46
|
|
|
|
47
|
1 |
|
public function send(ApiClient $apiClient): PaymentResponse |
48
|
|
|
{ |
49
|
|
|
$requestData = [ |
50
|
1 |
|
'merchantId' => $this->merchantId, |
51
|
1 |
|
'payId' => $this->payId, |
52
|
1 |
|
'callbackParams' => $this->callbackParams, |
53
|
|
|
]; |
54
|
|
|
|
55
|
1 |
|
$response = $apiClient->post( |
56
|
1 |
|
'masterpass/basic/finish', |
57
|
1 |
|
$requestData, |
58
|
1 |
|
new SignatureDataFormatter([ |
59
|
1 |
|
'merchantId' => null, |
60
|
|
|
'payId' => null, |
61
|
|
|
'dttm' => null, |
62
|
|
|
'callbackParams' => [ |
63
|
|
|
'mpstatus' => null, |
64
|
|
|
'oauthToken' => null, |
65
|
|
|
'checkoutResourceUrl' => null, |
66
|
|
|
'oauthVerifier' => null, |
67
|
|
|
], |
68
|
|
|
]), |
69
|
1 |
|
new SignatureDataFormatter([ |
70
|
1 |
|
'payId' => null, |
71
|
|
|
'dttm' => null, |
72
|
|
|
'resultCode' => null, |
73
|
|
|
'resultMessage' => null, |
74
|
|
|
'paymentStatus' => null, |
75
|
|
|
]) |
76
|
|
|
); |
77
|
|
|
|
78
|
1 |
|
$data = $response->getData(); |
79
|
|
|
|
80
|
1 |
|
return new PaymentResponse( |
81
|
1 |
|
$data['payId'], |
82
|
1 |
|
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
83
|
1 |
|
ResultCode::get($data['resultCode']), |
84
|
1 |
|
$data['resultMessage'], |
85
|
1 |
|
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|