Completed
Push — master ( b59c0c...c68fa7 )
by Josef
08:24
created

OneclickStartPaymentRequest::send()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 34
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 34
ccs 16
cts 16
cp 1
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 24
nc 1
nop 1
crap 2
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 OneclickStartPaymentRequest
11
{
12
13
	/**
14
	 * @var string
15
	 */
16
	private $merchantId;
17
18
	/**
19
	 * @var string
20
	 */
21
	private $payId;
22
23 2
	public function __construct(
24
		string $merchantId,
25
		string $payId
26
	)
27
	{
28 2
		Validator::checkPayId($payId);
29
30 2
		$this->merchantId = $merchantId;
31 2
		$this->payId = $payId;
32 2
	}
33
34 1
	public function send(ApiClient $apiClient): PaymentResponse
35
	{
36
		$requestData = [
37 1
			'merchantId' => $this->merchantId,
38 1
			'payId' => $this->payId,
39
		];
40
41 1
		$response = $apiClient->post(
42 1
			'payment/oneclick/start',
43
			$requestData,
44 1
			new SignatureDataFormatter([
45 1
				'merchantId' => null,
46
				'payId' => null,
47
				'dttm' => null,
48
			]),
49 1
			new SignatureDataFormatter([
50 1
				'payId' => null,
51
				'dttm' => null,
52
				'resultCode' => null,
53
				'resultMessage' => null,
54
				'paymentStatus' => null,
55
			])
56
		);
57
58 1
		$data = $response->getData();
59
60 1
		return new PaymentResponse(
61 1
			$data['payId'],
62 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
63 1
			new ResultCode($data['resultCode']),
64 1
			$data['resultMessage'],
65 1
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null
66
		);
67
	}
68
69
}
70