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 ReversePaymentRequest |
||
| 11 | { |
||
| 12 | |||
| 13 | /** @var string */ |
||
| 14 | private $merchantId; |
||
| 15 | |||
| 16 | /** @var string */ |
||
| 17 | private $payId; |
||
| 18 | |||
| 19 | 2 | public function __construct( |
|
| 20 | string $merchantId, |
||
| 21 | string $payId |
||
| 22 | ) |
||
| 23 | { |
||
| 24 | 2 | Validator::checkPayId($payId); |
|
| 25 | |||
| 26 | 2 | $this->merchantId = $merchantId; |
|
| 27 | 2 | $this->payId = $payId; |
|
| 28 | 2 | } |
|
| 29 | |||
| 30 | 1 | public function send(ApiClient $apiClient): PaymentResponse |
|
| 31 | { |
||
| 32 | 1 | $response = $apiClient->put( |
|
| 33 | 1 | 'payment/reverse', |
|
| 34 | [ |
||
| 35 | 1 | 'merchantId' => $this->merchantId, |
|
| 36 | 1 | 'payId' => $this->payId, |
|
| 37 | ], |
||
| 38 | 1 | new SignatureDataFormatter([ |
|
| 39 | 1 | 'merchantId' => null, |
|
| 40 | 'payId' => null, |
||
| 41 | 'dttm' => null, |
||
| 42 | ]), |
||
| 43 | 1 | new SignatureDataFormatter([ |
|
| 44 | 1 | 'payId' => null, |
|
| 45 | 'dttm' => null, |
||
| 46 | 'resultCode' => null, |
||
| 47 | 'resultMessage' => null, |
||
| 48 | 'paymentStatus' => null, |
||
| 49 | 'authCode' => null, |
||
| 50 | ]) |
||
| 51 | ); |
||
| 52 | |||
| 53 | 1 | $data = $response->getData(); |
|
| 54 | |||
| 55 | 1 | return new PaymentResponse( |
|
| 56 | 1 | $data['payId'], |
|
| 57 | 1 | DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']), |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 58 | 1 | ResultCode::get($data['resultCode']), |
|
| 59 | 1 | $data['resultMessage'], |
|
| 60 | 1 | isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null, |
|
| 61 | 1 | $data['authCode'] ?? null |
|
| 62 | ); |
||
| 63 | } |
||
| 64 | |||
| 65 | } |
||
| 66 |