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