Completed
Push — master ( 955097...f4414e )
by Jan
08:34
created

StartOneClickPaymentRequest::send()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 9.552
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\OneClick;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Call\PaymentResponse;
8
use SlevomatCsobGateway\Call\PaymentStatus;
9
use SlevomatCsobGateway\Call\ResultCode;
10
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
11
use SlevomatCsobGateway\Validator;
12
13
class StartOneClickPaymentRequest
14
{
15
16
	/** @var string */
17
	private $merchantId;
18
19
	/** @var string */
20
	private $payId;
21
22 2
	public function __construct(
23
		string $merchantId,
24
		string $payId
25
	)
26
	{
27 2
		Validator::checkPayId($payId);
28
29 2
		$this->merchantId = $merchantId;
30 2
		$this->payId = $payId;
31 2
	}
32
33 1
	public function send(ApiClient $apiClient): PaymentResponse
34
	{
35
		$requestData = [
36 1
			'merchantId' => $this->merchantId,
37 1
			'payId' => $this->payId,
38
		];
39
40 1
		$response = $apiClient->post(
41 1
			'oneclick/start',
42
			$requestData,
43 1
			new SignatureDataFormatter([
44 1
				'merchantId' => null,
45
				'payId' => null,
46
				'dttm' => null,
47
			]),
48 1
			new SignatureDataFormatter([
49 1
				'payId' => null,
50
				'dttm' => null,
51
				'resultCode' => null,
52
				'resultMessage' => null,
53
				'paymentStatus' => null,
54
			])
55
		);
56
57 1
		$data = $response->getData();
58
59 1
		return new PaymentResponse(
60 1
			$data['payId'],
61 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
0 ignored issues
show
Bug introduced by
It seems like DateTimeImmutable::creat...YmdHis', $data['dttm']) can also be of type false; however, parameter $responseDateTime of SlevomatCsobGateway\Call...Response::__construct() does only seem to accept DateTimeImmutable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
62 1
			ResultCode::get($data['resultCode']),
63 1
			$data['resultMessage'],
64 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
65
		);
66
	}
67
68
}
69