Completed
Push — master ( 955097...f4414e )
by Jan
08:34
created

RefundPaymentRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 96%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 36
c 1
b 0
f 0
dl 0
loc 62
rs 10
ccs 24
cts 25
cp 0.96
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A send() 0 37 3
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
class RefundPaymentRequest
11
{
12
13
	/** @var string */
14
	private $merchantId;
15
16
	/** @var string */
17
	private $payId;
18
19
	/** @var int|null */
20
	private $amount;
21
22 2
	public function __construct(
23
		string $merchantId,
24
		string $payId,
25
		?int $amount = null
26
	)
27
	{
28 2
		Validator::checkPayId($payId);
29
30 2
		$this->merchantId = $merchantId;
31 2
		$this->payId = $payId;
32 2
		$this->amount = $amount;
33 2
	}
34
35 1
	public function send(ApiClient $apiClient): PaymentResponse
36
	{
37
		$requestData = [
38 1
			'merchantId' => $this->merchantId,
39 1
			'payId' => $this->payId,
40
		];
41 1
		if ($this->amount !== null) {
42
			$requestData['amount'] = $this->amount;
43
		}
44 1
		$response = $apiClient->put(
45 1
			'payment/refund',
46
			$requestData,
47 1
			new SignatureDataFormatter([
48 1
				'merchantId' => null,
49
				'payId' => null,
50
				'dttm' => null,
51
				'amount' => null,
52
			]),
53 1
			new SignatureDataFormatter([
54 1
				'payId' => null,
55
				'dttm' => null,
56
				'resultCode' => null,
57
				'resultMessage' => null,
58
				'paymentStatus' => null,
59
				'authCode' => null,
60
			])
61
		);
62
63 1
		$data = $response->getData();
64
65 1
		return new PaymentResponse(
66 1
			$data['payId'],
67 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

67
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
68 1
			ResultCode::get($data['resultCode']),
69 1
			$data['resultMessage'],
70 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
71 1
			$data['authCode'] ?? null
72
		);
73
	}
74
75
}
76