Issues (27)

src/Call/Masterpass/StandardFinishRequest.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 StandardFinishRequest
14
{
15
16
	/** @var string */
17
	private $merchantId;
18
19
	/** @var string */
20
	private $payId;
21
22
	/** @var string */
23
	private $oauthToken;
24
25
	/** @var int */
26
	private $totalAmount;
27
28 2
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		string $oauthToken,
32
		int $totalAmount
33
	)
34
	{
35 2
		Validator::checkPayId($payId);
36
37 2
		$this->merchantId = $merchantId;
38 2
		$this->payId = $payId;
39 2
		$this->oauthToken = $oauthToken;
40 2
		$this->totalAmount = $totalAmount;
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
			'oauthToken' => $this->oauthToken,
49 1
			'totalAmount' => $this->totalAmount,
50
		];
51
52 1
		$response = $apiClient->post(
53 1
			'masterpass/standard/finish',
54
			$requestData,
55 1
			new SignatureDataFormatter([
56 1
				'merchantId' => null,
57
				'payId' => null,
58
				'dttm' => null,
59
				'oauthToken' => null,
60
				'totalAmount' => null,
61
			]),
62 1
			new SignatureDataFormatter([
63 1
				'payId' => null,
64
				'dttm' => null,
65
				'resultCode' => null,
66
				'resultMessage' => null,
67
				'paymentStatus' => null,
68
			])
69
		);
70
71 1
		$data = $response->getData();
72
73 1
		return new PaymentResponse(
74 1
			$data['payId'],
75 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

75
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
76 1
			ResultCode::get($data['resultCode']),
77 1
			$data['resultMessage'],
78 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
79
		);
80
	}
81
82
}
83