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

OneclickStartPaymentRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 1
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