Completed
Pull Request — master (#16)
by Josef
05:49
created

StartPaymentRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
B send() 0 34 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Oneclick;
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 StartPaymentRequest
14
{
15
16
	/**
17
	 * @var string
18
	 */
19
	private $merchantId;
20
21
	/**
22
	 * @var string
23
	 */
24
	private $payId;
25
26
	public function __construct(
27
		string $merchantId,
28
		string $payId
29
	)
30
	{
31
		Validator::checkPayId($payId);
32
33
		$this->merchantId = $merchantId;
34
		$this->payId = $payId;
35
	}
36
37
	public function send(ApiClient $apiClient): PaymentResponse
38
	{
39
		$requestData = [
40
			'merchantId' => $this->merchantId,
41
			'payId' => $this->payId,
42
		];
43
44
		$response = $apiClient->post(
45
			'payment/oneclick/start',
46
			$requestData,
47
			new SignatureDataFormatter([
48
				'merchantId' => null,
49
				'payId' => null,
50
				'dttm' => null,
51
			]),
52
			new SignatureDataFormatter([
53
				'payId' => null,
54
				'dttm' => null,
55
				'resultCode' => null,
56
				'resultMessage' => null,
57
				'paymentStatus' => null,
58
			])
59
		);
60
61
		$data = $response->getData();
62
63
		return new PaymentResponse(
64
			$data['payId'],
65
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
66
			new ResultCode($data['resultCode']),
67
			$data['resultMessage'],
68
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null
69
		);
70
	}
71
72
}
73