Completed
Push — master ( 7d5f81...069e15 )
by Jan
02:05
created

BasicFinishRequest::send()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 41
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 41
ccs 18
cts 18
cp 1
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 30
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 2
	public function __construct(
35
		string $merchantId,
36
		string $payId,
37
		array $callbackParams
38
	)
39
	{
40 2
		Validator::checkPayId($payId);
41
42 2
		$this->merchantId = $merchantId;
43 2
		$this->payId = $payId;
44 2
		$this->callbackParams = $callbackParams;
45 2
	}
46
47 1
	public function send(ApiClient $apiClient): PaymentResponse
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
				'dttm' => null,
62
				'callbackParams' => [
63
					'mpstatus' => null,
64
					'oauthToken' => null,
65
					'checkoutResourceUrl' => null,
66
					'oauthVerifier' => null,
67
				],
68
			]),
69 1
			new SignatureDataFormatter([
70 1
				'payId' => null,
71
				'dttm' => null,
72
				'resultCode' => null,
73
				'resultMessage' => null,
74
				'paymentStatus' => null,
75
			])
76
		);
77
78 1
		$data = $response->getData();
79
80 1
		return new PaymentResponse(
81 1
			$data['payId'],
82 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
83 1
			ResultCode::get($data['resultCode']),
84 1
			$data['resultMessage'],
85 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
86
		);
87
	}
88
89
}
90