1
|
|
|
<?php |
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
|
|
|
|
11
|
|
|
class RecurrentPaymentRequestTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
public function testSend() |
15
|
|
|
{ |
16
|
|
|
$apiClient = $this->getMockBuilder(ApiClient::class) |
17
|
|
|
->disableOriginalConstructor() |
18
|
|
|
->getMock(); |
19
|
|
|
|
20
|
|
|
$apiClient->expects(self::once())->method('post') |
21
|
|
|
->with('payment/recurrent', [ |
22
|
|
|
'merchantId' => '012345', |
23
|
|
|
'origPayId' => 'ef08b6e9f22345c', |
24
|
|
|
'totalAmount' => 99.8, |
25
|
|
|
'currency' => 'CZK', |
26
|
|
|
'orderNo' => '5547123', |
27
|
|
|
'description' => 'foo description', |
28
|
|
|
]) |
29
|
|
|
->willReturn( |
30
|
|
|
new Response(new ResponseCode(ResponseCode::S200_OK), [ |
31
|
|
|
'payId' => '123456789', |
32
|
|
|
'dttm' => '20140425131559', |
33
|
|
|
'resultCode' => 0, |
34
|
|
|
'resultMessage' => 'OK', |
35
|
|
|
'paymentStatus' => 7, |
36
|
|
|
'authCode' => '123456', |
37
|
|
|
]) |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
/** @var ApiClient $apiClient */ |
41
|
|
|
$recurrentPaymentRequest = new RecurrentPaymentRequest( |
42
|
|
|
'012345', |
43
|
|
|
'ef08b6e9f22345c', |
44
|
|
|
'5547123', |
45
|
|
|
99.8, |
46
|
|
|
new Currency(Currency::CZK), |
47
|
|
|
'foo description' |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$paymentResponse = $recurrentPaymentRequest->send($apiClient); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf(PaymentResponse::class, $paymentResponse); |
53
|
|
|
$this->assertSame('123456789', $paymentResponse->getPayId()); |
54
|
|
|
$this->assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentResponse->getResponseDateTime()); |
55
|
|
|
$this->assertEquals(new ResultCode(ResultCode::C0_OK), $paymentResponse->getResultCode()); |
56
|
|
|
$this->assertSame('OK', $paymentResponse->getResultMessage()); |
57
|
|
|
$this->assertEquals(new PaymentStatus(PaymentStatus::S7_AWAITING_SETTLEMENT), $paymentResponse->getPaymentStatus()); |
58
|
|
|
$this->assertSame('123456', $paymentResponse->getAuthCode()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|