Completed
Push — master ( 955097...f4414e )
by Jan
08:34
created

PaymentButtonRequestTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 44
dl 0
loc 58
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testSend() 0 55 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Button;
4
5
use DateTimeImmutable;
6
use PHPUnit\Framework\TestCase;
7
use SlevomatCsobGateway\Api\ApiClient;
8
use SlevomatCsobGateway\Api\HttpMethod;
9
use SlevomatCsobGateway\Api\Response;
10
use SlevomatCsobGateway\Api\ResponseCode;
11
use SlevomatCsobGateway\Call\PaymentStatus;
12
use SlevomatCsobGateway\Call\ResultCode;
13
use SlevomatCsobGateway\Currency;
14
use SlevomatCsobGateway\Language;
15
use SlevomatCsobGateway\Price;
16
17
class PaymentButtonRequestTest extends TestCase
18
{
19
20
	public function testSend(): void
21
	{
22
		$apiClient = $this->getMockBuilder(ApiClient::class)
23
			->disableOriginalConstructor()
24
			->getMock();
25
26
		$apiClient->expects(self::once())->method('post')
27
			->with('button/init', [
28
				'merchantId' => '012345',
29
				'orderNo' => '123456789',
30
				'clientIp' => '127.0.0.1',
31
				'totalAmount' => 12000,
32
				'currency' => 'CZK',
33
				'returnUrl' => 'https://www.example.com/return',
34
				'returnMethod' => 'GET',
35
				'brand' => 'csob',
36
				'language' => 'EN',
37
			])
38
			->willReturn(
39
				new Response(ResponseCode::get(ResponseCode::S200_OK), [
40
					'payId' => '123456789',
41
					'dttm' => '20140425131559',
42
					'resultCode' => 0,
43
					'resultMessage' => 'OK',
44
					'paymentStatus' => 1,
45
					'redirect' => [
46
						'method' => 'GET',
47
						'url' => 'https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob',
48
					],
49
				])
50
			);
51
52
		/** @var ApiClient $apiClient */
53
		$paymentRequest = new PaymentButtonRequest(
54
			'012345',
55
			'123456789',
56
			'127.0.0.1',
57
			new Price(12000, Currency::get(Currency::CZK)),
58
			'https://www.example.com/return',
59
			HttpMethod::get(HttpMethod::GET),
60
			PaymentButtonBrand::get(PaymentButtonBrand::CSOB),
61
			null,
62
			Language::get(Language::EN)
63
		);
64
65
		$paymentButtonResponse = $paymentRequest->send($apiClient);
66
67
		self::assertSame('123456789', $paymentButtonResponse->getPayId());
68
		self::assertEquals(DateTimeImmutable::createFromFormat('YmdHis', '20140425131559'), $paymentButtonResponse->getResponseDateTime());
69
		self::assertEquals(ResultCode::get(ResultCode::C0_OK), $paymentButtonResponse->getResultCode());
70
		self::assertSame('OK', $paymentButtonResponse->getResultMessage());
71
		self::assertEquals(PaymentStatus::get(PaymentStatus::S1_CREATED), $paymentButtonResponse->getPaymentStatus());
72
		self::assertSame('https://platebnibrana.csob.cz/pay/vasobchod.cz/2c72d818-9788-45a1-878a-9db2a706edc5/pt-detect/csob', $paymentButtonResponse->getRedirectUrl());
73
		self::assertSame(HttpMethod::get(HttpMethod::GET), $paymentButtonResponse->getRedirectMethod());
74
		self::assertNull($paymentButtonResponse->getRedirectParams());
75
	}
76
77
}
78