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

StandardExtractRequest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 12
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 8
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 StandardExtractRequest
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 mixed[] */
26
	private $callbackParams;
27
28
	/**
29
	 * @param string $merchantId
30
	 * @param string $payId
31
	 * @param mixed[] $callbackParams
32
	 */
33 1
	public function __construct(
34
		string $merchantId,
35
		string $payId,
36
		array $callbackParams
37
	)
38
	{
39 1
		Validator::checkPayId($payId);
40
41 1
		$this->merchantId = $merchantId;
42 1
		$this->payId = $payId;
43 1
		$this->callbackParams = $callbackParams;
44 1
	}
45
46 1
	public function send(ApiClient $apiClient): ExtractResponse
47
	{
48
		$requestData = [
49 1
			'merchantId' => $this->merchantId,
50 1
			'payId' => $this->payId,
51 1
			'callbackParams' => $this->callbackParams,
52
		];
53
54 1
		$response = $apiClient->post(
55 1
			'masterpass/standard/extract',
56 1
			$requestData,
57 1
			new SignatureDataFormatter([
58 1
				'merchantId' => null,
59
				'payId' => null,
60
				'dttm' => null,
61
				'callbackParams' => null,
62
			]),
63 1
			new SignatureDataFormatter([
64 1
				'payId' => null,
65
				'dttm' => null,
66
				'resultCode' => null,
67
				'resultMessage' => null,
68
				'paymentStatus' => null,
69
				'checkoutParams' => null,
70
			])
71
		);
72
73 1
		$data = $response->getData();
74
75 1
		return new ExtractResponse(
76 1
			$data['payId'],
77 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
78 1
			ResultCode::get($data['resultCode']),
79 1
			$data['resultMessage'],
80 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
81 1
			$data['checkoutParams'] ?? null
82
		);
83
	}
84
85
}
86