|
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
|
|
|
/** |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
private $merchantId; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
private $payId; |
|
24
|
|
|
|
|
25
|
2 |
|
public function __construct( |
|
26
|
|
|
string $merchantId, |
|
27
|
|
|
string $payId |
|
28
|
|
|
) |
|
29
|
|
|
{ |
|
30
|
2 |
|
Validator::checkPayId($payId); |
|
31
|
|
|
|
|
32
|
2 |
|
$this->merchantId = $merchantId; |
|
33
|
2 |
|
$this->payId = $payId; |
|
34
|
2 |
|
} |
|
35
|
|
|
|
|
36
|
1 |
|
public function send(ApiClient $apiClient): ProcessPaymentResponse |
|
37
|
|
|
{ |
|
38
|
1 |
|
$response = $apiClient->get( |
|
39
|
1 |
|
'payment/process/{merchantId}/{payId}/{dttm}/{signature}', |
|
40
|
|
|
[ |
|
41
|
1 |
|
'merchantId' => $this->merchantId, |
|
42
|
1 |
|
'payId' => $this->payId, |
|
43
|
|
|
], |
|
44
|
1 |
|
new SignatureDataFormatter([ |
|
45
|
1 |
|
'merchantId' => null, |
|
46
|
|
|
'payId' => null, |
|
47
|
|
|
'dttm' => null, |
|
48
|
|
|
]), |
|
49
|
1 |
|
new SignatureDataFormatter([ |
|
50
|
1 |
|
'payId' => null, |
|
51
|
|
|
'dttm' => null, |
|
52
|
|
|
'resultCode' => null, |
|
53
|
|
|
'resultMessage' => null, |
|
54
|
|
|
'paymentStatus' => null, |
|
55
|
|
|
'authCode' => null, |
|
56
|
|
|
]), |
|
57
|
1 |
|
function (Response $response) { |
|
58
|
|
|
// This handles edge case when provided payId is missing or already expired on gateway |
|
59
|
|
|
// In this case gateway responds with HTTP 200 and HTML content. Bad API. |
|
60
|
|
|
// See https://github.com/csob/paymentgateway/issues/135 |
|
61
|
|
|
if ($response->getResponseCode()->equalsValue(ResponseCode::S200_OK)) { |
|
62
|
|
|
throw new InvalidPaymentException($this, $response, $this->payId); |
|
63
|
|
|
} |
|
64
|
1 |
|
} |
|
65
|
|
|
); |
|
66
|
|
|
|
|
67
|
1 |
|
return new ProcessPaymentResponse($response->getHeaders()['Location']); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|