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 function array_key_exists; |
||
| 9 | use function base64_decode; |
||
| 10 | use function is_numeric; |
||
| 11 | |||
| 12 | class ReceivePaymentRequest |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param ApiClient $apiClient |
||
| 17 | * @param mixed[] $data |
||
| 18 | * @return PaymentResponse |
||
| 19 | */ |
||
| 20 | 2 | public function send(ApiClient $apiClient, array $data): PaymentResponse |
|
| 21 | { |
||
| 22 | 2 | if (array_key_exists('resultCode', $data) && is_numeric($data['resultCode'])) { |
|
| 23 | 2 | $data['resultCode'] = (int) $data['resultCode']; |
|
| 24 | } |
||
| 25 | |||
| 26 | 2 | if (array_key_exists('paymentStatus', $data) && is_numeric($data['paymentStatus'])) { |
|
| 27 | 2 | $data['paymentStatus'] = (int) $data['paymentStatus']; |
|
| 28 | } |
||
| 29 | |||
| 30 | 2 | $response = $apiClient->createResponseByData($data, new SignatureDataFormatter([ |
|
| 31 | 2 | 'payId' => null, |
|
| 32 | 'dttm' => null, |
||
| 33 | 'resultCode' => null, |
||
| 34 | 'resultMessage' => null, |
||
| 35 | 'paymentStatus' => null, |
||
| 36 | 'authCode' => null, |
||
| 37 | 'merchantData' => null, |
||
| 38 | ])); |
||
| 39 | |||
| 40 | 2 | $data = $response->getData(); |
|
| 41 | |||
| 42 | 2 | return new PaymentResponse( |
|
| 43 | 2 | $data['payId'], |
|
| 44 | 2 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 45 | 2 | ResultCode::get($data['resultCode']), |
|
| 46 | 2 | $data['resultMessage'], |
|
| 47 | 2 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
| 48 | 2 | $data['authCode'] ?? null, |
|
| 49 | 2 | isset($data['merchantData']) ? (string) base64_decode($data['merchantData'], true) : null |
|
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | } |
||
| 54 |