|
1
|
|
|
<?php |
|
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
|
|
|
use SlevomatCsobGateway\Cart; |
|
11
|
|
|
use SlevomatCsobGateway\Currency; |
|
12
|
|
|
use SlevomatCsobGateway\Language; |
|
13
|
|
|
|
|
14
|
|
|
class InitPaymentRequestTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
public function testSend() |
|
18
|
|
|
{ |
|
19
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
|
20
|
|
|
->disableOriginalConstructor() |
|
21
|
|
|
->getMock(); |
|
22
|
|
|
|
|
23
|
|
|
$apiClient->expects(self::once())->method('post') |
|
24
|
|
|
->with('payment/init', [ |
|
25
|
|
|
'merchantId' => '012345', |
|
26
|
|
|
'orderNo' => '5547', |
|
27
|
|
|
'payOperation' => 'payment', |
|
28
|
|
|
'payMethod' => 'card', |
|
29
|
|
|
'totalAmount' => 1789600.0, |
|
30
|
|
|
'currency' => 'CZK', |
|
31
|
|
|
'closePayment' => true, |
|
32
|
|
|
'returnUrl' => 'https://vasobchod.cz/gateway-return', |
|
33
|
|
|
'returnMethod' => 'POST', |
|
34
|
|
|
'cart' => [ |
|
35
|
|
|
[ |
|
36
|
|
|
'name' => 'Nákup na vasobchodcz', |
|
37
|
|
|
'quantity' => 1, |
|
38
|
|
|
'amount' => 1789600, |
|
39
|
|
|
'description' => 'Lenovo ThinkPad Edge E540', |
|
40
|
|
|
], |
|
41
|
|
|
[ |
|
42
|
|
|
'name' => 'Poštovné', |
|
43
|
|
|
'quantity' => 1, |
|
44
|
|
|
'amount' => 0, |
|
45
|
|
|
'description' => 'Doprava PPL', |
|
46
|
|
|
], |
|
47
|
|
|
], |
|
48
|
|
|
'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
|
49
|
|
|
'merchantData' => base64_encode('some-base64-encoded-merchant-data'), |
|
50
|
|
|
'customerId' => '123', |
|
51
|
|
|
'language' => 'CZ', |
|
52
|
|
|
]) |
|
53
|
|
|
->willReturn( |
|
54
|
|
|
new Response(new ResponseCode(ResponseCode::S200_OK), [ |
|
55
|
|
|
'payId' => '123456789', |
|
56
|
|
|
'dttm' => '20140425131559', |
|
57
|
|
|
'resultCode' => 0, |
|
58
|
|
|
'resultMessage' => 'OK', |
|
59
|
|
|
'paymentStatus' => 1, |
|
60
|
|
|
]) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
/** @var ApiClient $apiClient */ |
|
64
|
|
|
$cart = new Cart( |
|
65
|
|
|
new Currency(Currency::CZK) |
|
66
|
|
|
); |
|
67
|
|
|
$cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540'); |
|
68
|
|
|
$cart->addItem('Poštovné', 1, 0, 'Doprava PPL'); |
|
69
|
|
|
|
|
70
|
|
|
$initPaymentRequest = new InitPaymentRequest( |
|
71
|
|
|
'012345', |
|
72
|
|
|
'5547', |
|
73
|
|
|
new PayOperation(PayOperation::PAYMENT), |
|
74
|
|
|
new PayMethod(PayMethod::CARD), |
|
75
|
|
|
true, |
|
76
|
|
|
'https://vasobchod.cz/gateway-return', |
|
77
|
|
|
new HttpMethod(HttpMethod::POST), |
|
78
|
|
|
$cart, |
|
79
|
|
|
'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
|
80
|
|
|
'some-base64-encoded-merchant-data', |
|
81
|
|
|
'123', |
|
82
|
|
|
new Language(Language::CZ) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$paymentResponse = $initPaymentRequest->send($apiClient); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
|
88
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
|
89
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
|
90
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
|
91
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
|
92
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus()); |
|
93
|
|
|
$this->assertNull($paymentResponse->getAuthCode()); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|