ProcessPaymentRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 52
rs 10
ccs 16
cts 18
cp 0.8889
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A send() 0 32 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call;
4
5
use SlevomatCsobGateway\Api\ApiClient;
6
use SlevomatCsobGateway\Api\InvalidPaymentException;
7
use SlevomatCsobGateway\Api\Response;
8
use SlevomatCsobGateway\Api\ResponseCode;
9
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
10
use SlevomatCsobGateway\Validator;
11
12
class ProcessPaymentRequest
13
{
14
15
	/** @var string */
16
	private $merchantId;
17
18
	/** @var string */
19
	private $payId;
20
21 2
	public function __construct(
22
		string $merchantId,
23
		string $payId
24
	)
25
	{
26 2
		Validator::checkPayId($payId);
27
28 2
		$this->merchantId = $merchantId;
29 2
		$this->payId = $payId;
30 2
	}
31
32 1
	public function send(ApiClient $apiClient): ProcessPaymentResponse
33
	{
34 1
		$response = $apiClient->get(
35 1
			'payment/process/{merchantId}/{payId}/{dttm}/{signature}',
36
			[
37 1
				'merchantId' => $this->merchantId,
38 1
				'payId' => $this->payId,
39
			],
40 1
			new SignatureDataFormatter([
41 1
				'merchantId' => null,
42
				'payId' => null,
43
				'dttm' => null,
44
			]),
45 1
			new SignatureDataFormatter([
46 1
				'payId' => null,
47
				'dttm' => null,
48
				'resultCode' => null,
49
				'resultMessage' => null,
50
				'paymentStatus' => null,
51
				'authCode' => null,
52
			]),
53
			function (Response $response): void {
54
				// This handles edge case when provided payId is missing or already expired on gateway
55
				// In this case gateway responds with HTTP 200 and HTML content. Bad API.
56
				// See https://github.com/csob/paymentgateway/issues/135
57
				if ($response->getResponseCode()->equalsValue(ResponseCode::S200_OK)) {
58
					throw new InvalidPaymentException($this, $response, $this->payId);
59
				}
60 1
			}
61
		);
62
63 1
		return new ProcessPaymentResponse($response->getHeaders()['Location']);
64
	}
65
66
}
67