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\PaymentResponse; |
||
| 8 | use SlevomatCsobGateway\Call\PaymentStatus; |
||
| 9 | use SlevomatCsobGateway\Call\ResultCode; |
||
| 10 | use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
||
| 11 | use SlevomatCsobGateway\Validator; |
||
| 12 | |||
| 13 | class BasicFinishRequest |
||
| 14 | { |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | private $merchantId; |
||
| 18 | |||
| 19 | /** @var string */ |
||
| 20 | private $payId; |
||
| 21 | |||
| 22 | /** @var mixed[] */ |
||
| 23 | private $callbackParams; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $merchantId |
||
| 27 | * @param string $payId |
||
| 28 | * @param mixed[] $callbackParams |
||
| 29 | */ |
||
| 30 | 2 | public function __construct( |
|
| 31 | string $merchantId, |
||
| 32 | string $payId, |
||
| 33 | array $callbackParams |
||
| 34 | ) |
||
| 35 | { |
||
| 36 | 2 | Validator::checkPayId($payId); |
|
| 37 | |||
| 38 | 2 | $this->merchantId = $merchantId; |
|
| 39 | 2 | $this->payId = $payId; |
|
| 40 | 2 | $this->callbackParams = $callbackParams; |
|
| 41 | 2 | } |
|
| 42 | |||
| 43 | 1 | public function send(ApiClient $apiClient): PaymentResponse |
|
| 44 | { |
||
| 45 | $requestData = [ |
||
| 46 | 1 | 'merchantId' => $this->merchantId, |
|
| 47 | 1 | 'payId' => $this->payId, |
|
| 48 | 1 | 'callbackParams' => $this->callbackParams, |
|
| 49 | ]; |
||
| 50 | |||
| 51 | 1 | $response = $apiClient->post( |
|
| 52 | 1 | 'masterpass/basic/finish', |
|
| 53 | $requestData, |
||
| 54 | 1 | new SignatureDataFormatter([ |
|
| 55 | 1 | 'merchantId' => null, |
|
| 56 | 'payId' => null, |
||
| 57 | 'dttm' => null, |
||
| 58 | 'callbackParams' => [ |
||
| 59 | 'mpstatus' => null, |
||
| 60 | 'oauthToken' => null, |
||
| 61 | 'checkoutResourceUrl' => null, |
||
| 62 | 'oauthVerifier' => null, |
||
| 63 | ], |
||
| 64 | ]), |
||
| 65 | 1 | new SignatureDataFormatter([ |
|
| 66 | 1 | 'payId' => null, |
|
| 67 | 'dttm' => null, |
||
| 68 | 'resultCode' => null, |
||
| 69 | 'resultMessage' => null, |
||
| 70 | 'paymentStatus' => null, |
||
| 71 | ]) |
||
| 72 | ); |
||
| 73 | |||
| 74 | 1 | $data = $response->getData(); |
|
| 75 | |||
| 76 | 1 | return new PaymentResponse( |
|
| 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 | ); |
||
| 83 | } |
||
| 84 | |||
| 85 | } |
||
| 86 |