Issues (27)

src/Call/Masterpass/BasicFinishRequest.php (1 issue)

Labels
Severity
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 BasicFinishRequest
14
{
15
16
	/** @var string */
17
	private $merchantId;
18
19
	/** @var string */
20
	private $payId;
21
22
	/** @var mixed[] */
23
	private $callbackParams;
24
25
	/**
26
	 * @param string $merchantId
27
	 * @param string $payId
28
	 * @param mixed[] $callbackParams
29
	 */
30 2
	public function __construct(
31
		string $merchantId,
32
		string $payId,
33
		array $callbackParams
34
	)
35
	{
36 2
		Validator::checkPayId($payId);
37
38 2
		$this->merchantId = $merchantId;
39 2
		$this->payId = $payId;
40 2
		$this->callbackParams = $callbackParams;
41 2
	}
42
43 1
	public function send(ApiClient $apiClient): PaymentResponse
44
	{
45
		$requestData = [
46 1
			'merchantId' => $this->merchantId,
47 1
			'payId' => $this->payId,
48 1
			'callbackParams' => $this->callbackParams,
49
		];
50
51 1
		$response = $apiClient->post(
52 1
			'masterpass/basic/finish',
53
			$requestData,
54 1
			new SignatureDataFormatter([
55 1
				'merchantId' => null,
56
				'payId' => null,
57
				'dttm' => null,
58
				'callbackParams' => [
59
					'mpstatus' => null,
60
					'oauthToken' => null,
61
					'checkoutResourceUrl' => null,
62
					'oauthVerifier' => null,
63
				],
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']),
0 ignored issues
show
It seems like DateTimeImmutable::creat...YmdHis', $data['dttm']) can also be of type false; however, parameter $responseDateTime of SlevomatCsobGateway\Call...Response::__construct() does only seem to accept DateTimeImmutable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
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