Code Duplication    Length = 72-74 lines in 2 locations

src/Call/ClosePaymentRequest.php 1 location

@@ 10-83 (lines=74) @@
7
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
8
use SlevomatCsobGateway\Validator;
9
10
class ClosePaymentRequest
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
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		int $totalAmount = null
32
	)
33
	{
34
		Validator::checkPayId($payId);
35
36
		$this->merchantId = $merchantId;
37
		$this->payId = $payId;
38
		$this->totalAmount = $totalAmount;
39
	}
40
41
	public function send(ApiClient $apiClient): PaymentResponse
42
	{
43
		$data = [
44
			'merchantId' => $this->merchantId,
45
			'payId' => $this->payId,
46
		];
47
48
		if ($this->totalAmount !== null) {
49
			$data['totalAmount'] = $this->totalAmount;
50
		}
51
52
		$response = $apiClient->put(
53
			'payment/close',
54
			$data,
55
			new SignatureDataFormatter([
56
				'merchantId' => null,
57
				'payId' => null,
58
				'dttm' => null,
59
				'totalAmount' => null,
60
			]),
61
			new SignatureDataFormatter([
62
				'payId' => null,
63
				'dttm' => null,
64
				'resultCode' => null,
65
				'resultMessage' => null,
66
				'paymentStatus' => null,
67
				'authCode' => null,
68
			])
69
		);
70
71
		$data = $response->getData();
72
73
		return new PaymentResponse(
74
			$data['payId'],
75
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
76
			new ResultCode($data['resultCode']),
77
			$data['resultMessage'],
78
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null,
79
			$data['authCode'] ?? null
80
		);
81
	}
82
83
}
84

src/Call/RefundPaymentRequest.php 1 location

@@ 10-81 (lines=72) @@
7
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
8
use SlevomatCsobGateway\Validator;
9
10
class RefundPaymentRequest
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 $amount;
27
28
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		int $amount = null
32
	)
33
	{
34
		Validator::checkPayId($payId);
35
36
		$this->merchantId = $merchantId;
37
		$this->payId = $payId;
38
		$this->amount = $amount;
39
	}
40
41
	public function send(ApiClient $apiClient): PaymentResponse
42
	{
43
		$requestData = [
44
			'merchantId' => $this->merchantId,
45
			'payId' => $this->payId,
46
		];
47
		if ($this->amount !== null) {
48
			$requestData['amount'] = $this->amount;
49
		}
50
		$response = $apiClient->put(
51
			'payment/refund',
52
			$requestData,
53
			new SignatureDataFormatter([
54
				'merchantId' => null,
55
				'payId' => null,
56
				'dttm' => null,
57
				'amount' => null,
58
			]),
59
			new SignatureDataFormatter([
60
				'payId' => null,
61
				'dttm' => null,
62
				'resultCode' => null,
63
				'resultMessage' => null,
64
				'paymentStatus' => null,
65
				'authCode' => null,
66
			])
67
		);
68
69
		$data = $response->getData();
70
71
		return new PaymentResponse(
72
			$data['payId'],
73
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
74
			new ResultCode($data['resultCode']),
75
			$data['resultMessage'],
76
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null,
77
			$data['authCode'] ?? null
78
		);
79
	}
80
81
}
82