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

StandardExtractRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 118
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 118
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B send() 0 82 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\PaymentStatus;
8
use SlevomatCsobGateway\Call\ResultCode;
9
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
10
use SlevomatCsobGateway\Validator;
11
12
class StandardExtractRequest
13
{
14
15
	/**
16
	 * @var string
17
	 */
18
	private $merchantId;
19
20
	/**
21
	 * @var string
22
	 */
23
	private $payId;
24
25
	/** @var mixed[] */
26
	private $callbackParams;
27
28
	/**
29
	 * @param string $merchantId
30
	 * @param string $payId
31
	 * @param mixed[] $callbackParams
32
	 */
33 2
	public function __construct(
34
		string $merchantId,
35
		string $payId,
36
		array $callbackParams
37
	)
38
	{
39 2
		Validator::checkPayId($payId);
40
41 2
		$this->merchantId = $merchantId;
42 2
		$this->payId = $payId;
43 2
		$this->callbackParams = $callbackParams;
44 2
	}
45
46 1
	public function send(ApiClient $apiClient): ExtractResponse
47
	{
48
		$requestData = [
49 1
			'merchantId' => $this->merchantId,
50 1
			'payId' => $this->payId,
51 1
			'callbackParams' => $this->callbackParams,
52
		];
53
54 1
		$response = $apiClient->post(
55 1
			'masterpass/standard/extract',
56 1
			$requestData,
57 1
			new SignatureDataFormatter([
58 1
				'merchantId' => null,
59
				'payId' => null,
60
				'dttm' => null,
61
				'callbackParams' => [
62
					'mpstatus' => null,
63
					'oauthToken' => null,
64
					'checkoutResourceUrl' => null,
65
					'oauthVerifier' => null,
66
				],
67
			]),
68 1
			new SignatureDataFormatter([
69 1
				'payId' => null,
70
				'dttm' => null,
71
				'resultCode' => null,
72
				'resultMessage' => null,
73
				'paymentStatus' => null,
74
				'checkoutParams' => [
75
					'card' => [
76
						'maskedCln' => null,
77
						'expiration' => null,
78
						'billingAddress' => [
79
							'city' => null,
80
							'country' => null,
81
							'countrySubdivision' => null,
82
							'line1' => null,
83
							'line2' => null,
84
							'line3' => null,
85
							'postalCode' => null,
86
						],
87
					],
88
					'shippingAddress' => [
89
						'recipientName' => null,
90
						'recipientPhoneNumber' => null,
91
						'city' => null,
92
						'country' => null,
93
						'countrySubdivision' => null,
94
						'line1' => null,
95
						'line2' => null,
96
						'line3' => null,
97
						'postalCode' => null,
98
					],
99
					'contact' => [
100
						'firstName' => null,
101
						'middleName' => null,
102
						'lastName' => null,
103
						'country' => null,
104
						'emailAddress' => null,
105
						'phoneNumber' => null,
106
					],
107
					'rewardProgram' => [
108
						'rewardNumber' => null,
109
						'rewardId' => null,
110
						'rewardName' => null,
111
						'expiration' => null,
112
					],
113
				],
114
			])
115
		);
116
117 1
		$data = $response->getData();
118
119 1
		return new ExtractResponse(
120 1
			$data['payId'],
121 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
122 1
			ResultCode::get($data['resultCode']),
123 1
			$data['resultMessage'],
124 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
125 1
			$data['checkoutParams'] ?? null
126
		);
127
	}
128
129
}
130