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
|
2 |
|
public function __construct( |
32
|
|
|
string $merchantId, |
33
|
|
|
string $payId, |
34
|
|
|
string $callbackUrl, |
35
|
|
|
?string $shippingLocationProfile = null |
36
|
|
|
) |
37
|
|
|
{ |
38
|
2 |
|
Validator::checkPayId($payId); |
39
|
2 |
|
Validator::checkReturnUrl($callbackUrl); |
40
|
|
|
|
41
|
2 |
|
$this->merchantId = $merchantId; |
42
|
2 |
|
$this->payId = $payId; |
43
|
2 |
|
$this->callbackUrl = $callbackUrl; |
44
|
2 |
|
$this->shippingLocationProfile = $shippingLocationProfile; |
45
|
2 |
|
} |
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' => [ |
76
|
|
|
'requestToken' => null, |
77
|
|
|
'callbackUrl' => null, |
78
|
|
|
'merchantCheckoutId' => null, |
79
|
|
|
'allowedCardTypes' => null, |
80
|
|
|
'suppressShippingAddressEnable' => null, |
81
|
|
|
'loyaltyEnabled' => null, |
82
|
|
|
'version' => null, |
83
|
|
|
'shippingLocationProfile' => null, |
84
|
|
|
], |
85
|
|
|
]) |
86
|
|
|
); |
87
|
|
|
|
88
|
1 |
|
$data = $response->getData(); |
89
|
|
|
|
90
|
1 |
|
return new CheckoutResponse( |
91
|
1 |
|
$data['payId'], |
92
|
1 |
|
DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
93
|
1 |
|
ResultCode::get($data['resultCode']), |
94
|
1 |
|
$data['resultMessage'], |
95
|
1 |
|
isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
96
|
1 |
|
$data['lightboxParams'] ?? null |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|