|
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\PaymentStatus; |
|
8
|
|
|
use SlevomatCsobGateway\Call\ResultCode; |
|
9
|
|
|
use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
|
10
|
|
|
use SlevomatCsobGateway\Validator; |
|
11
|
|
|
|
|
12
|
|
|
class StandardCheckoutRequest |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $merchantId; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $payId; |
|
24
|
|
|
|
|
25
|
|
|
/** @var string */ |
|
26
|
|
|
private $callbackUrl; |
|
27
|
|
|
|
|
28
|
|
|
/** @var null|string */ |
|
29
|
|
|
private $shippingLocationProfile; |
|
30
|
|
|
|
|
31
|
1 |
|
public function __construct( |
|
32
|
|
|
string $merchantId, |
|
33
|
|
|
string $payId, |
|
34
|
|
|
string $callbackUrl, |
|
35
|
|
|
?string $shippingLocationProfile = null |
|
36
|
|
|
) |
|
37
|
|
|
{ |
|
38
|
1 |
|
Validator::checkPayId($payId); |
|
39
|
1 |
|
Validator::checkReturnUrl($callbackUrl); |
|
40
|
|
|
|
|
41
|
1 |
|
$this->merchantId = $merchantId; |
|
42
|
1 |
|
$this->payId = $payId; |
|
43
|
1 |
|
$this->callbackUrl = $callbackUrl; |
|
44
|
1 |
|
$this->shippingLocationProfile = $shippingLocationProfile; |
|
45
|
1 |
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
public function send(ApiClient $apiClient): CheckoutResponse |
|
48
|
|
|
{ |
|
49
|
|
|
$requestData = [ |
|
50
|
1 |
|
'merchantId' => $this->merchantId, |
|
51
|
1 |
|
'payId' => $this->payId, |
|
52
|
1 |
|
'callbackUrl' => $this->callbackUrl, |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
1 |
|
if ($this->shippingLocationProfile !== null) { |
|
56
|
1 |
|
$requestData['shippingLocationProfile'] = $this->shippingLocationProfile; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
$response = $apiClient->post( |
|
60
|
1 |
|
'masterpass/standard/checkout', |
|
61
|
1 |
|
$requestData, |
|
62
|
1 |
|
new SignatureDataFormatter([ |
|
63
|
1 |
|
'merchantId' => null, |
|
64
|
|
|
'payId' => null, |
|
65
|
|
|
'dttm' => null, |
|
66
|
|
|
'callbackUrl' => null, |
|
67
|
|
|
'shippingLocationProfile' => null, |
|
68
|
|
|
]), |
|
69
|
1 |
|
new SignatureDataFormatter([ |
|
70
|
1 |
|
'payId' => null, |
|
71
|
|
|
'dttm' => null, |
|
72
|
|
|
'resultCode' => null, |
|
73
|
|
|
'resultMessage' => null, |
|
74
|
|
|
'paymentStatus' => null, |
|
75
|
|
|
'lightboxParams' => null, |
|
76
|
|
|
]) |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
1 |
|
$data = $response->getData(); |
|
80
|
|
|
|
|
81
|
1 |
|
return new CheckoutResponse( |
|
82
|
1 |
|
$data['payId'], |
|
83
|
1 |
|
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
84
|
1 |
|
ResultCode::get($data['resultCode']), |
|
85
|
1 |
|
$data['resultMessage'], |
|
86
|
1 |
|
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
87
|
1 |
|
$data['lightboxParams'] ?? null |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|