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

OneclickStartPaymentRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 60
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
B send() 0 34 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