Completed
Pull Request — master (#32)
by Jan
03:24
created

BasicCheckoutRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 13
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 3
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 View Code Duplication
class BasicCheckoutRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
15
	/**
16
	 * @var string
17
	 */
18
	private $merchantId;
19
20
	/**
21
	 * @var string
22
	 */
23
	private $payId;
24
25
	/** @var string */
26
	private $callbackUrl;
27
28 1
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		string $callbackUrl
32
	)
33
	{
34 1
		Validator::checkPayId($payId);
35 1
		Validator::checkReturnUrl($callbackUrl);
36
37 1
		$this->merchantId = $merchantId;
38 1
		$this->payId = $payId;
39 1
		$this->callbackUrl = $callbackUrl;
40 1
	}
41
42 1
	public function send(ApiClient $apiClient): CheckoutResponse
43
	{
44
		$requestData = [
45 1
			'merchantId' => $this->merchantId,
46 1
			'payId' => $this->payId,
47 1
			'callbackUrl' => $this->callbackUrl,
48
		];
49
50 1
		$response = $apiClient->post(
51 1
			'masterpass/basic/checkout',
52 1
			$requestData,
53 1
			new SignatureDataFormatter([
54 1
				'merchantId' => null,
55
				'payId' => null,
56
				'dttm' => null,
57
				'callbackUrl' => null,
58
			]),
59 1
			new SignatureDataFormatter([
60 1
				'payId' => null,
61
				'dttm' => null,
62
				'resultCode' => null,
63
				'resultMessage' => null,
64
				'paymentStatus' => null,
65
				'lightboxParams' => null,
66
			])
67
		);
68
69 1
		$data = $response->getData();
70
71 1
		return new CheckoutResponse(
72 1
			$data['payId'],
73 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
74 1
			ResultCode::get($data['resultCode']),
75 1
			$data['resultMessage'],
76 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
77 1
			$data['lightboxParams'] ?? null
78
		);
79
	}
80
81
}
82