InitPaymentRequestTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 60
dl 0
loc 83
rs 10
c 1
b 0
f 0

1 Method

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