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