1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
7
|
|
|
use SlevomatCsobGateway\Api\HttpMethod; |
8
|
|
|
use SlevomatCsobGateway\Api\Response; |
9
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
10
|
|
|
|
11
|
|
|
class PaymentButtonRequestTest extends \PHPUnit\Framework\TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function testSend(): void |
15
|
|
|
{ |
16
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
17
|
|
|
->disableOriginalConstructor() |
18
|
|
|
->getMock(); |
19
|
|
|
|
20
|
|
|
$apiClient->expects(self::once())->method('post') |
21
|
|
|
->with('payment/button', [ |
22
|
|
|
'merchantId' => '012345', |
23
|
|
|
'payId' => '123456789', |
24
|
|
|
'brand' => 'csob', |
25
|
|
|
]) |
26
|
|
|
->willReturn( |
27
|
|
|
new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
28
|
|
|
'payId' => '123456789', |
29
|
|
|
'dttm' => '20140425131559', |
30
|
|
|
'resultCode' => 0, |
31
|
|
|
'resultMessage' => 'OK', |
32
|
|
|
'paymentStatus' => 1, |
33
|
|
|
'redirect' => [ |
34
|
|
|
'method' => 'GET', |
35
|
|
|
'url' => 'https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', |
36
|
|
|
], |
37
|
|
|
]) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
/** @var ApiClient $apiClient */ |
41
|
|
|
$paymentRequest = new PaymentButtonRequest( |
42
|
|
|
'012345', |
43
|
|
|
'123456789', |
44
|
|
|
PaymentButtonBrand::get(PaymentButtonBrand::CSOB) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$paymentButtonResponse = $paymentRequest->send($apiClient); |
48
|
|
|
|
49
|
|
|
$this->assertInstanceOf(PaymentButtonResponse::class, $paymentButtonResponse); |
50
|
|
|
$this->assertSame('123456789', $paymentButtonResponse->getPayId()); |
51
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentButtonResponse->getResponseDateTime()); |
52
|
|
|
$this->assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentButtonResponse->getResultCode()); |
53
|
|
|
$this->assertSame('OK', $paymentButtonResponse->getResultMessage()); |
54
|
|
|
$this->assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentButtonResponse->getPaymentStatus()); |
55
|
|
|
$this->assertSame('https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', $paymentButtonResponse->getRedirectUrl()); |
56
|
|
|
$this->assertSame(HttpMethod::get(HttpMethod::GET), $paymentButtonResponse->getRedirectMethod()); |
57
|
|
|
$this->assertNull($paymentButtonResponse->getRedirectParams()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|