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
|
|
|
|