Completed
Push — master ( bc3f33...99b627 )
by Josef
03:38
created

ClosePaymentRequest::send()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 41
Code Lines 29

Duplication

Lines 41
Ratio 100 %

Code Coverage

Tests 18
CRAP Score 3.0013

Importance

Changes 0
Metric Value
dl 41
loc 41
ccs 18
cts 19
cp 0.9474
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 29
nc 2
nop 1
crap 3.0013
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
8
use SlevomatCsobGateway\Validator;
9
10 View Code Duplication
class ClosePaymentRequest
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...
11
{
12
13
	/**
14
	 * @var string
15
	 */
16
	private $merchantId;
17
18
	/**
19
	 * @var string
20
	 */
21
	private $payId;
22
23
	/**
24
	 * @var int|null
25
	 */
26
	private $totalAmount;
27
28 2
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		int $totalAmount = null
32
	)
33
	{
34 2
		Validator::checkPayId($payId);
35
36 2
		$this->merchantId = $merchantId;
37 2
		$this->payId = $payId;
38 2
		$this->totalAmount = $totalAmount;
39 2
	}
40
41 1
	public function send(ApiClient $apiClient): PaymentResponse
42
	{
43
		$data = [
44 1
			'merchantId' => $this->merchantId,
45 1
			'payId' => $this->payId,
46
		];
47
48 1
		if ($this->totalAmount !== null) {
49
			$data['totalAmount'] = $this->totalAmount;
50
		}
51
52 1
		$response = $apiClient->put(
53 1
			'payment/close',
54
			$data,
55 1
			new SignatureDataFormatter([
56 1
				'merchantId' => null,
57
				'payId' => null,
58
				'dttm' => null,
59
				'totalAmount' => null,
60
			]),
61 1
			new SignatureDataFormatter([
62 1
				'payId' => null,
63
				'dttm' => null,
64
				'resultCode' => null,
65
				'resultMessage' => null,
66
				'paymentStatus' => null,
67
				'authCode' => null,
68
			])
69
		);
70
71 1
		$data = $response->getData();
72
73 1
		return new PaymentResponse(
74 1
			$data['payId'],
75 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
76 1
			new ResultCode($data['resultCode']),
77 1
			$data['resultMessage'],
78 1
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null,
79 1
			$data['authCode'] ?? null
80
		);
81
	}
82
83
}
84