1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway\Call; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use SlevomatCsobGateway\Api\ApiClient; |
7
|
|
|
use SlevomatCsobGateway\Api\Response; |
8
|
|
|
use SlevomatCsobGateway\Api\ResponseCode; |
9
|
|
|
use SlevomatCsobGateway\Currency; |
10
|
|
|
use SlevomatCsobGateway\Price; |
11
|
|
|
|
12
|
|
|
class OneclickInitPaymentRequestTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public function testSend() |
16
|
|
|
{ |
17
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
18
|
|
|
->disableOriginalConstructor() |
19
|
|
|
->getMock(); |
20
|
|
|
|
21
|
|
|
$apiClient->expects(self::once())->method('post') |
22
|
|
|
->with('payment/oneclick/init', [ |
23
|
|
|
'merchantId' => '012345', |
24
|
|
|
'origPayId' => 'ef08b6e9f22345c', |
25
|
|
|
'orderNo' => '5547', |
26
|
|
|
'totalAmount' => 1789600, |
27
|
|
|
'currency' => 'CZK', |
28
|
|
|
'description' => 'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
29
|
|
|
]) |
30
|
|
|
->willReturn( |
31
|
|
|
new Response(new ResponseCode(ResponseCode::S200_OK), [ |
32
|
|
|
'payId' => '123456789', |
33
|
|
|
'dttm' => '20140425131559', |
34
|
|
|
'resultCode' => 0, |
35
|
|
|
'resultMessage' => 'OK', |
36
|
|
|
'paymentStatus' => 1, |
37
|
|
|
]) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$initPaymentRequest = new OneclickInitPaymentRequest( |
41
|
|
|
'012345', |
42
|
|
|
'ef08b6e9f22345c', |
43
|
|
|
'5547', |
44
|
|
|
new Price(1789600, new Currency(Currency::CZK)), |
45
|
|
|
'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)' |
46
|
|
|
); |
47
|
|
|
|
48
|
|
|
/** @var ApiClient $apiClient */ |
49
|
|
|
$paymentResponse = $initPaymentRequest->send($apiClient); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
52
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
53
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
54
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
55
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
56
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S1_CREATED), $paymentResponse->getPaymentStatus()); |
57
|
|
|
$this->assertNull($paymentResponse->getAuthCode()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
} |
61
|
|
|
|