slevomat /
csob-gateway
| 1 | <?php declare(strict_types = 1); |
||
| 2 | |||
| 3 | namespace SlevomatCsobGateway\Call; |
||
| 4 | |||
| 5 | use DateTimeImmutable; |
||
| 6 | use SlevomatCsobGateway\Api\ApiClient; |
||
| 7 | use SlevomatCsobGateway\Crypto\SignatureDataFormatter; |
||
| 8 | use SlevomatCsobGateway\Validator; |
||
| 9 | |||
| 10 | class PaymentStatusRequest |
||
| 11 | { |
||
| 12 | |||
| 13 | /** @var string */ |
||
| 14 | private $merchantId; |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | private $payId; |
||
| 18 | |||
| 19 | /** @var ResponseExtensionHandler[] */ |
||
| 20 | private $extensions = []; |
||
| 21 | |||
| 22 | 2 | public function __construct( |
|
| 23 | string $merchantId, |
||
| 24 | string $payId |
||
| 25 | ) |
||
| 26 | { |
||
| 27 | 2 | Validator::checkPayId($payId); |
|
| 28 | |||
| 29 | 2 | $this->merchantId = $merchantId; |
|
| 30 | 2 | $this->payId = $payId; |
|
| 31 | 2 | } |
|
| 32 | |||
| 33 | 1 | public function send(ApiClient $apiClient): PaymentResponse |
|
| 34 | { |
||
| 35 | 1 | $response = $apiClient->get( |
|
| 36 | 1 | 'payment/status/{merchantId}/{payId}/{dttm}/{signature}', |
|
| 37 | [ |
||
| 38 | 1 | 'merchantId' => $this->merchantId, |
|
| 39 | 1 | 'payId' => $this->payId, |
|
| 40 | ], |
||
| 41 | 1 | new SignatureDataFormatter([ |
|
| 42 | 1 | 'merchantId' => null, |
|
| 43 | 'payId' => null, |
||
| 44 | 'dttm' => null, |
||
| 45 | ]), |
||
| 46 | 1 | new SignatureDataFormatter([ |
|
| 47 | 1 | 'payId' => null, |
|
| 48 | 'dttm' => null, |
||
| 49 | 'resultCode' => null, |
||
| 50 | 'resultMessage' => null, |
||
| 51 | 'paymentStatus' => null, |
||
| 52 | 'authCode' => null, |
||
| 53 | ]), |
||
| 54 | 1 | null, |
|
| 55 | 1 | $this->extensions |
|
| 56 | ); |
||
| 57 | |||
| 58 | 1 | $data = $response->getData(); |
|
| 59 | |||
| 60 | 1 | return new PaymentResponse( |
|
| 61 | 1 | $data['payId'], |
|
| 62 | 1 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 63 | 1 | ResultCode::get($data['resultCode']), |
|
| 64 | 1 | $data['resultMessage'], |
|
| 65 | 1 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
| 66 | 1 | $data['authCode'] ?? null, |
|
| 67 | 1 | null, |
|
| 68 | 1 | $response->getExtensions() |
|
| 69 | ); |
||
| 70 | } |
||
| 71 | |||
| 72 | public function registerExtension(string $name, ResponseExtensionHandler $extensionHandler): void |
||
| 73 | { |
||
| 74 | $this->extensions[$name] = $extensionHandler; |
||
| 75 | } |
||
| 76 | |||
| 77 | } |
||
| 78 |