1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call\Masterpass; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
7
|
|
|
use SlevomatCsobGateway\Api\Response; |
8
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
9
|
|
|
use SlevomatCsobGateway\Call\PaymentStatus; |
10
|
|
|
use SlevomatCsobGateway\Call\ResultCode; |
11
|
|
|
|
12
|
|
|
class BasicCheckoutRequestTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function testSend(): void |
16
|
|
|
{ |
17
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
18
|
|
|
->disableOriginalConstructor() |
19
|
|
|
->getMock(); |
20
|
|
|
|
21
|
|
|
$apiClient->expects(self::once())->method('post') |
22
|
|
|
->with('masterpass/basic/checkout', [ |
23
|
|
|
'merchantId' => '012345', |
24
|
|
|
'payId' => '123456789', |
25
|
|
|
'callbackUrl' => 'https://www.vasobchod.cz/masterpass/callback', |
26
|
|
|
]) |
27
|
|
|
->willReturn( |
28
|
|
|
new Response(ResponseCode::get(ResponseCode::S200_OK), [ |
29
|
|
|
'payId' => '123456789', |
30
|
|
|
'dttm' => '20140425131559', |
31
|
|
|
'resultCode' => 0, |
32
|
|
|
'resultMessage' => 'OK', |
33
|
|
|
'paymentStatus' => 1, |
34
|
|
|
'lightboxParams' => [ |
35
|
|
|
'requestToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
36
|
|
|
'callbackUrl' => 'https://www.vasobchod.cz/masterpass/callback', |
37
|
|
|
'merchantCheckoutId' => 'a4a6w4vzajswviqy5oeu11irc2e3yb51ws', |
38
|
|
|
'allowedCardTypes' => 'master,visa', |
39
|
|
|
'suppressShippingAddressEnable' => 'true', |
40
|
|
|
'loyaltyEnabled' => 'false', |
41
|
|
|
'version' => 'v6', |
42
|
|
|
'shippingLocationProfile' => 'SP-0001', |
43
|
|
|
], |
44
|
|
|
]) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** @var ApiClient $apiClient */ |
48
|
|
|
$paymentRequest = new BasicCheckoutRequest( |
49
|
|
|
'012345', |
50
|
|
|
'123456789', |
51
|
|
|
'https://www.vasobchod.cz/masterpass/callback' |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$checkoutResponse = $paymentRequest->send($apiClient); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf(CheckoutResponse::class, $checkoutResponse); |
57
|
|
|
$this->assertSame('123456789', $checkoutResponse->getPayId()); |
58
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $checkoutResponse->getResponseDateTime()); |
59
|
|
|
$this->assertEquals(ResultCode::get(ResultCode::C0_OK), $checkoutResponse->getResultCode()); |
60
|
|
|
$this->assertSame('OK', $checkoutResponse->getResultMessage()); |
61
|
|
|
$this->assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $checkoutResponse->getPaymentStatus()); |
62
|
|
|
$this->assertNotNull($checkoutResponse->getLightboxParams()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|