1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace SlevomatCsobGateway; |
4
|
|
|
|
5
|
|
|
use SlevomatCsobGateway\Api\HttpMethod; |
6
|
|
|
use SlevomatCsobGateway\Call\ClosePaymentRequest; |
7
|
|
|
use SlevomatCsobGateway\Call\CustomerInfoRequest; |
8
|
|
|
use SlevomatCsobGateway\Call\EchoRequest; |
9
|
|
|
use SlevomatCsobGateway\Call\InitPaymentRequest; |
10
|
|
|
use SlevomatCsobGateway\Call\Masterpass\BasicCheckoutRequest; |
11
|
|
|
use SlevomatCsobGateway\Call\Masterpass\BasicFinishRequest; |
12
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardCheckoutRequest; |
13
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardExtractRequest; |
14
|
|
|
use SlevomatCsobGateway\Call\Masterpass\StandardFinishRequest; |
15
|
|
|
use SlevomatCsobGateway\Call\OneclickInitPaymentRequest; |
16
|
|
|
use SlevomatCsobGateway\Call\OneclickStartPaymentRequest; |
17
|
|
|
use SlevomatCsobGateway\Call\PaymentButtonBrand; |
18
|
|
|
use SlevomatCsobGateway\Call\PaymentButtonRequest; |
19
|
|
|
use SlevomatCsobGateway\Call\PaymentStatusRequest; |
20
|
|
|
use SlevomatCsobGateway\Call\PayMethod; |
21
|
|
|
use SlevomatCsobGateway\Call\PayOperation; |
22
|
|
|
use SlevomatCsobGateway\Call\PostEchoRequest; |
23
|
|
|
use SlevomatCsobGateway\Call\ProcessPaymentRequest; |
24
|
|
|
use SlevomatCsobGateway\Call\ReceivePaymentRequest; |
25
|
|
|
use SlevomatCsobGateway\Call\RefundPaymentRequest; |
26
|
|
|
use SlevomatCsobGateway\Call\ReversePaymentRequest; |
27
|
|
|
|
28
|
|
|
class RequestFactoryTest extends \PHPUnit\Framework\TestCase |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var RequestFactory |
33
|
|
|
*/ |
34
|
|
|
private $requestFactory; |
35
|
|
|
|
36
|
|
|
protected function setUp(): void |
37
|
|
|
{ |
38
|
|
|
$this->requestFactory = new RequestFactory('012345'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testCreateInitPayment(): void |
42
|
|
|
{ |
43
|
|
|
$cart = new Cart( |
44
|
|
|
Currency::get(Currency::CZK) |
45
|
|
|
); |
46
|
|
|
$cart->addItem('Nákup na vasobchodcz', 1, 1789600, 'Lenovo ThinkPad Edge E540'); |
47
|
|
|
$cart->addItem('Poštovné', 1, 0, 'Doprava PPL'); |
48
|
|
|
|
49
|
|
|
$request = $this->requestFactory->createInitPayment( |
50
|
|
|
'5547', |
51
|
|
|
PayOperation::get(PayOperation::PAYMENT), |
52
|
|
|
PayMethod::get(PayMethod::CARD), |
53
|
|
|
true, |
54
|
|
|
'https://vasobchod.cz/gateway-return', |
55
|
|
|
HttpMethod::get(HttpMethod::POST), |
56
|
|
|
$cart, |
57
|
|
|
'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)', |
58
|
|
|
'some-base64-encoded-merchant-data', |
59
|
|
|
'123', |
60
|
|
|
Language::get(Language::CZ), |
61
|
|
|
1800, |
62
|
|
|
1, |
63
|
|
|
1 |
64
|
|
|
); |
65
|
|
|
|
66
|
|
|
$this->assertInstanceOf(InitPaymentRequest::class, $request); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testCreateProcessPayment(): void |
70
|
|
|
{ |
71
|
|
|
$request = $this->requestFactory->createProcessPayment('123456789'); |
72
|
|
|
|
73
|
|
|
$this->assertInstanceOf(ProcessPaymentRequest::class, $request); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testCreatePaymentStatus(): void |
77
|
|
|
{ |
78
|
|
|
$request = $this->requestFactory->createPaymentStatus('123456789'); |
79
|
|
|
|
80
|
|
|
$this->assertInstanceOf(PaymentStatusRequest::class, $request); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testCreateReversePayment(): void |
84
|
|
|
{ |
85
|
|
|
$request = $this->requestFactory->createReversePayment('123456789'); |
86
|
|
|
|
87
|
|
|
$this->assertInstanceOf(ReversePaymentRequest::class, $request); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function testCreateClosePayment(): void |
91
|
|
|
{ |
92
|
|
|
$request = $this->requestFactory->createClosePayment('123456789'); |
93
|
|
|
|
94
|
|
|
$this->assertInstanceOf(ClosePaymentRequest::class, $request); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testCreateRefundPayment(): void |
98
|
|
|
{ |
99
|
|
|
$request = $this->requestFactory->createRefundPayment('123456789'); |
100
|
|
|
|
101
|
|
|
$this->assertInstanceOf(RefundPaymentRequest::class, $request); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function testCreateEchoRequest(): void |
105
|
|
|
{ |
106
|
|
|
$request = $this->requestFactory->createEchoRequest(); |
107
|
|
|
|
108
|
|
|
$this->assertInstanceOf(EchoRequest::class, $request); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testCreatePostEchoRequest(): void |
112
|
|
|
{ |
113
|
|
|
$request = $this->requestFactory->createPostEchoRequest(); |
114
|
|
|
|
115
|
|
|
$this->assertInstanceOf(PostEchoRequest::class, $request); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testCreateCustomerInfo(): void |
119
|
|
|
{ |
120
|
|
|
$request = $this->requestFactory->createCustomerInfo('[email protected]'); |
121
|
|
|
|
122
|
|
|
$this->assertInstanceOf(CustomerInfoRequest::class, $request); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testCreateReceivePayment(): void |
126
|
|
|
{ |
127
|
|
|
$request = $this->requestFactory->createReceivePaymentRequest(); |
128
|
|
|
|
129
|
|
|
$this->assertInstanceOf(ReceivePaymentRequest::class, $request); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function testCreateOneclickInitPayment(): void |
133
|
|
|
{ |
134
|
|
|
$request = $this->requestFactory->createOneclickInitPayment( |
135
|
|
|
'ef08b6e9f22345c', |
136
|
|
|
'5547123', |
137
|
|
|
new Price(1789600, Currency::get(Currency::CZK)), |
138
|
|
|
'Nákup na vasobchod.cz (Lenovo ThinkPad Edge E540, Doprava PPL)' |
139
|
|
|
); |
140
|
|
|
|
141
|
|
|
$this->assertInstanceOf(OneclickInitPaymentRequest::class, $request); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function testCreateOneclickStartPayment(): void |
145
|
|
|
{ |
146
|
|
|
$request = $this->requestFactory->createOneclickStartPayment('ef08b6e9f22345c'); |
147
|
|
|
|
148
|
|
|
$this->assertInstanceOf(OneclickStartPaymentRequest::class, $request); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function testCreateMasterpassBasicCheckoutRequest(): void |
152
|
|
|
{ |
153
|
|
|
$request = $this->requestFactory->createMasterpassBasicCheckoutRequest('ef08b6e9f22345c', 'https://www.example.com/callback'); |
154
|
|
|
|
155
|
|
|
$this->assertInstanceOf(BasicCheckoutRequest::class, $request); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
View Code Duplication |
public function testCreateMasterpassBasicFinishRequest(): void |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$callbackParams = [ |
161
|
|
|
'mpstatus' => 'success', |
162
|
|
|
'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
163
|
|
|
'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
164
|
|
|
'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
165
|
|
|
]; |
166
|
|
|
$request = $this->requestFactory->createMasterpassBasicFinishRequest('ef08b6e9f22345c', $callbackParams); |
167
|
|
|
|
168
|
|
|
$this->assertInstanceOf(BasicFinishRequest::class, $request); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function testCreateMasterpassStandardCheckoutRequest(): void |
172
|
|
|
{ |
173
|
|
|
$request = $this->requestFactory->createMasterpassStandardCheckoutRequest('ef08b6e9f22345c', 'https://www.example.com/callback', 'SP123'); |
174
|
|
|
|
175
|
|
|
$this->assertInstanceOf(StandardCheckoutRequest::class, $request); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
View Code Duplication |
public function testCreateMasterpassStandardExtractRequest(): void |
|
|
|
|
179
|
|
|
{ |
180
|
|
|
$callbackParams = [ |
181
|
|
|
'mpstatus' => 'success', |
182
|
|
|
'oauthToken' => '6a79bf9e320a0460d08aee7ad154f7dab4e19503', |
183
|
|
|
'checkoutResourceUrl' => 'https://sandbox.api.mastercard.com/masterpass/v6/checkout/616764812', |
184
|
|
|
'oauthVerifier' => 'fc8f41bb76ed7d43ea6d714cb8fdefa606611a7d', |
185
|
|
|
]; |
186
|
|
|
$request = $this->requestFactory->createMasterpassStandardExtractRequest('ef08b6e9f22345c', $callbackParams); |
187
|
|
|
|
188
|
|
|
$this->assertInstanceOf(StandardExtractRequest::class, $request); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function testCreateMasterpassStandardFinishRequest(): void |
192
|
|
|
{ |
193
|
|
|
$request = $this->requestFactory->createMasterpassStandardFinishRequest('ef08b6e9f22345c', '123456789', 15000); |
194
|
|
|
|
195
|
|
|
$this->assertInstanceOf(StandardFinishRequest::class, $request); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function testCreatePaymentButtonRequest(): void |
199
|
|
|
{ |
200
|
|
|
$request = $this->requestFactory->createPaymentButtonRequest('ef08b6e9f22345c', PaymentButtonBrand::get(PaymentButtonBrand::ERA)); |
201
|
|
|
|
202
|
|
|
$this->assertInstanceOf(PaymentButtonRequest::class, $request); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.