Passed
Pull Request — master (#39)
by Jan
08:36
created

StartOneClickPaymentRequest::send()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 32
rs 9.552
c 0
b 0
f 0
cc 2
nc 1
nop 1
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
	public function __construct(
23
		string $merchantId,
24
		string $payId
25
	)
26
	{
27
		Validator::checkPayId($payId);
28
29
		$this->merchantId = $merchantId;
30
		$this->payId = $payId;
31
	}
32
33
	public function send(ApiClient $apiClient): PaymentResponse
34
	{
35
		$requestData = [
36
			'merchantId' => $this->merchantId,
37
			'payId' => $this->payId,
38
		];
39
40
		$response = $apiClient->post(
41
			'oneclick/start',
42
			$requestData,
43
			new SignatureDataFormatter([
44
				'merchantId' => null,
45
				'payId' => null,
46
				'dttm' => null,
47
			]),
48
			new SignatureDataFormatter([
49
				'payId' => null,
50
				'dttm' => null,
51
				'resultCode' => null,
52
				'resultMessage' => null,
53
				'paymentStatus' => null,
54
			])
55
		);
56
57
		$data = $response->getData();
58
59
		return new PaymentResponse(
60
			$data['payId'],
61
			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
			ResultCode::get($data['resultCode']),
63
			$data['resultMessage'],
64
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
65
		);
66
	}
67
68
}
69