Completed
Push — master ( 54bcb1...083d0b )
by Jan
03:06
created

ReceivePaymentRequest::send()   C

Complexity

Conditions 7
Paths 4

Size

Total Lines 32
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 22
c 2
b 0
f 0
nc 4
nop 2
dl 0
loc 32
rs 6.7272
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
9
class ReceivePaymentRequest
10
{
11
12
	public function send(ApiClient $apiClient, array $data): PaymentResponse
13
	{
14
		if (array_key_exists('resultCode', $data) && is_numeric($data['resultCode'])) {
15
			$data['resultCode'] = (int) $data['resultCode'];
16
		}
17
18
		if (array_key_exists('paymentStatus', $data) && is_numeric($data['paymentStatus'])) {
19
			$data['paymentStatus'] = (int) $data['paymentStatus'];
20
		}
21
22
		$response = $apiClient->createResponseByData($data, new SignatureDataFormatter([
23
			'payId' => null,
24
			'dttm' => null,
25
			'resultCode' => null,
26
			'resultMessage' => null,
27
			'paymentStatus' => null,
28
			'authCode' => null,
29
			'merchantData' => null,
30
		]));
31
32
		$data = $response->getData();
33
34
		return new PaymentResponse(
35
			$data['payId'],
36
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
37
			new ResultCode($data['resultCode']),
38
			$data['resultMessage'],
39
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null,
40
			$data['authCode'] ?? null,
41
			isset($data['merchantData']) ? base64_decode($data['merchantData']) : null
42
		);
43
	}
44
45
}
46