Completed
Pull Request — master (#32)
by Jan
08:59 queued 01:43
created

StandardFinishRequest::send()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 37
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 19
cts 19
cp 1
rs 8.8571
cc 2
eloc 27
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 StandardFinishRequest
14
{
15
16
	/**
17
	 * @var string
18
	 */
19
	private $merchantId;
20
21
	/**
22
	 * @var string
23
	 */
24
	private $payId;
25
26
	/** @var string */
27
	private $oauthToken;
28
29
	/** @var int */
30
	private $totalAmount;
31
32 2
	public function __construct(
33
		string $merchantId,
34
		string $payId,
35
		string $oauthToken,
36
		int $totalAmount
37
	)
38
	{
39 2
		Validator::checkPayId($payId);
40
41 2
		$this->merchantId = $merchantId;
42 2
		$this->payId = $payId;
43 2
		$this->oauthToken = $oauthToken;
44 2
		$this->totalAmount = $totalAmount;
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
			'oauthToken' => $this->oauthToken,
53 1
			'totalAmount' => $this->totalAmount,
54
		];
55
56 1
		$response = $apiClient->post(
57 1
			'masterpass/standard/finish',
58 1
			$requestData,
59 1
			new SignatureDataFormatter([
60 1
				'merchantId' => null,
61
				'payId' => null,
62
				'oauthToken' => null,
63
				'totalAmount' => null,
64
			]),
65 1
			new SignatureDataFormatter([
66 1
				'payId' => null,
67
				'dttm' => null,
68
				'resultCode' => null,
69
				'resultMessage' => null,
70
				'paymentStatus' => null,
71
			])
72
		);
73
74 1
		$data = $response->getData();
75
76 1
		return new PaymentResponse(
77 1
			$data['payId'],
78 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
79 1
			ResultCode::get($data['resultCode']),
80 1
			$data['resultMessage'],
81 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
82
		);
83
	}
84
85
}
86