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