BasicCheckoutRequest::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 12
rs 10
ccs 6
cts 6
cp 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Masterpass;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Call\PaymentStatus;
8
use SlevomatCsobGateway\Call\ResultCode;
9
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
10
use SlevomatCsobGateway\Validator;
11
12
class BasicCheckoutRequest
13
{
14
15
	/** @var string */
16
	private $merchantId;
17
18
	/** @var string */
19
	private $payId;
20
21
	/** @var string */
22
	private $callbackUrl;
23
24 2
	public function __construct(
25
		string $merchantId,
26
		string $payId,
27
		string $callbackUrl
28
	)
29
	{
30 2
		Validator::checkPayId($payId);
31 2
		Validator::checkReturnUrl($callbackUrl);
32
33 2
		$this->merchantId = $merchantId;
34 2
		$this->payId = $payId;
35 2
		$this->callbackUrl = $callbackUrl;
36 2
	}
37
38 1
	public function send(ApiClient $apiClient): CheckoutResponse
39
	{
40
		$requestData = [
41 1
			'merchantId' => $this->merchantId,
42 1
			'payId' => $this->payId,
43 1
			'callbackUrl' => $this->callbackUrl,
44
		];
45
46 1
		$response = $apiClient->post(
47 1
			'masterpass/basic/checkout',
48
			$requestData,
49 1
			new SignatureDataFormatter([
50 1
				'merchantId' => null,
51
				'payId' => null,
52
				'dttm' => null,
53
				'callbackUrl' => null,
54
			]),
55 1
			new SignatureDataFormatter([
56 1
				'payId' => null,
57
				'dttm' => null,
58
				'resultCode' => null,
59
				'resultMessage' => null,
60
				'paymentStatus' => null,
61
				'lightboxParams' => [
62
					'requestToken' => null,
63
					'callbackUrl' => null,
64
					'merchantCheckoutId' => null,
65
					'allowedCardTypes' => null,
66
					'suppressShippingAddressEnable' => null,
67
					'loyaltyEnabled' => null,
68
					'version' => null,
69
					'shippingLocationProfile' => null,
70
				],
71
			])
72
		);
73
74 1
		$data = $response->getData();
75
76 1
		return new CheckoutResponse(
77 1
			$data['payId'],
78 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

78
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
79 1
			ResultCode::get($data['resultCode']),
80 1
			$data['resultMessage'],
81 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
82 1
			$data['lightboxParams'] ?? null
83
		);
84
	}
85
86
}
87