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

StandardFinishRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
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 74
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 38 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
				'dttm' => null,
63
				'oauthToken' => null,
64
				'totalAmount' => null,
65
			]),
66 1
			new SignatureDataFormatter([
67 1
				'payId' => null,
68
				'dttm' => null,
69
				'resultCode' => null,
70
				'resultMessage' => null,
71
				'paymentStatus' => null,
72
			])
73
		);
74
75 1
		$data = $response->getData();
76
77 1
		return new PaymentResponse(
78 1
			$data['payId'],
79 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
80 1
			ResultCode::get($data['resultCode']),
81 1
			$data['resultMessage'],
82 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
83
		);
84
	}
85
86
}
87