Completed
Pull Request — master (#32)
by Jan
03:24
created

StandardFinishRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 73
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
B send() 0 37 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 1
	public function __construct(
33
		string $merchantId,
34
		string $payId,
35
		string $oauthToken,
36
		int $totalAmount
37
	)
38
	{
39 1
		Validator::checkPayId($payId);
40
41 1
		$this->merchantId = $merchantId;
42 1
		$this->payId = $payId;
43 1
		$this->oauthToken = $oauthToken;
44 1
		$this->totalAmount = $totalAmount;
45 1
	}
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