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

BasicFinishRequest::send()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 35
Code Lines 25

Duplication

Lines 35
Ratio 100 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 35
loc 35
ccs 18
cts 18
cp 1
rs 8.8571
cc 2
eloc 25
nc 1
nop 1
crap 2
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\PaymentResponse;
8
use SlevomatCsobGateway\Call\PaymentStatus;
9
use SlevomatCsobGateway\Call\ResultCode;
10
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
11
use SlevomatCsobGateway\Validator;
12
13
class BasicFinishRequest
14
{
15
16
	/**
17
	 * @var string
18
	 */
19
	private $merchantId;
20
21
	/**
22
	 * @var string
23
	 */
24
	private $payId;
25
26
	/** @var mixed[] */
27
	private $callbackParams;
28
29
	/**
30
	 * @param string $merchantId
31
	 * @param string $payId
32
	 * @param mixed[] $callbackParams
33
	 */
34 1
	public function __construct(
35
		string $merchantId,
36
		string $payId,
37
		array $callbackParams
38
	)
39
	{
40 1
		Validator::checkPayId($payId);
41
42 1
		$this->merchantId = $merchantId;
43 1
		$this->payId = $payId;
44 1
		$this->callbackParams = $callbackParams;
45 1
	}
46
47 1 View Code Duplication
	public function send(ApiClient $apiClient): PaymentResponse
0 ignored issues
show
Duplication introduced by
This method 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...
48
	{
49
		$requestData = [
50 1
			'merchantId' => $this->merchantId,
51 1
			'payId' => $this->payId,
52 1
			'callbackParams' => $this->callbackParams,
53
		];
54
55 1
		$response = $apiClient->post(
56 1
			'masterpass/basic/finish',
57 1
			$requestData,
58 1
			new SignatureDataFormatter([
59 1
				'merchantId' => null,
60
				'payId' => 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
			])
70
		);
71
72 1
		$data = $response->getData();
73
74 1
		return new PaymentResponse(
75 1
			$data['payId'],
76 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
77 1
			ResultCode::get($data['resultCode']),
78 1
			$data['resultMessage'],
79 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
80
		);
81
	}
82
83
}
84