-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathFetchChargebacksRequestTest.php
More file actions
284 lines (239 loc) · 9.86 KB
/
FetchChargebacksRequestTest.php
File metadata and controls
284 lines (239 loc) · 9.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
namespace Omnipay\Vindicia\Message;
use Omnipay\Vindicia\TestFramework\Mocker;
use Omnipay\Vindicia\TestFramework\DataFaker;
use Omnipay\Vindicia\TestFramework\SoapTestCase;
class FetchChargebacksRequestTest extends SoapTestCase
{
/**
* @return void
*/
public function setUp(): void
{
$this->faker = new DataFaker();
$this->transactionId = $this->faker->transactionId();
$this->transactionReference = $this->faker->transactionReference();
$this->startTime = $this->faker->timestamp();
$this->endTime = $this->faker->timestamp();
$this->page = $this->faker->intBetween(0, 10);
$this->pageSize = $this->faker->intBetween(10, 10000);
// make sure endTime is after startTime
if ($this->endTime < $this->startTime) {
$temp = $this->endTime;
$this->endTime = $this->startTime;
$this->startTime = $temp;
}
$this->request = new FetchChargebacksRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'transactionId' => $this->transactionId
)
);
$this->chargebackReference = $this->faker->chargebackReference();
$this->currency = $this->faker->currency();
$this->amount = $this->faker->monetaryAmount($this->currency);
$this->timestamp = date('Y-m-d\T12:00:00-04:00');
$this->reasonCode = $this->faker->randomCharacters(DataFaker::ALPHABET_LOWER, $this->faker->intBetween(5, 10));
$this->caseNumber = $this->faker->randomCharacters(DataFaker::ALPHABET_LOWER, $this->faker->intBetween(5, 10));
}
/**
* @return void
*/
public function testTransactionId()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setTransactionId($this->transactionId));
$this->assertSame($this->transactionId, $request->getTransactionId());
}
/**
* @return void
*/
public function testTransactionReference()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setTransactionReference($this->transactionReference));
$this->assertSame($this->transactionReference, $request->getTransactionReference());
}
/**
* @return void
*/
public function testStartTime()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setStartTime($this->startTime));
$this->assertSame($this->startTime, $request->getStartTime());
}
/**
* @return void
*/
public function testEndTime()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setEndTime($this->endTime));
$this->assertSame($this->endTime, $request->getEndTime());
}
/**
* @return void
*/
public function testPageSize()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setPageSize($this->pageSize));
$this->assertSame($this->pageSize, $request->getPageSize());
}
/**
* @return void
*/
public function testPage()
{
$request = Mocker::mock('\Omnipay\Vindicia\Message\FetchChargebacksRequest')->makePartial();
$request->initialize();
$this->assertSame($request, $request->setPage($this->page));
$this->assertSame($this->page, $request->getPage());
}
/**
* @return void
*/
public function testGetData()
{
$data = $this->request->getData();
$this->assertSame($this->transactionId, $data['merchantTransactionId']);
$this->assertSame('fetchByMerchantTransactionId', $data['action']);
}
/**
* @return void
*/
public function testGetDataByReference()
{
$this->request->setTransactionId(null)->setTransactionReference($this->transactionReference);
$data = $this->request->getData();
$this->assertSame($this->transactionReference, $data['vid']);
$this->assertSame('fetchByVid', $data['action']);
}
/**
* @return void
*/
public function testGetDataByTime()
{
$this->request->setStartTime($this->startTime);
$this->request->setEndTime($this->endTime);
$this->request->setTransactionId(null);
$this->request->setPage($this->page);
$this->request->setPageSize($this->pageSize);
$data = $this->request->getData();
$this->assertSame($this->startTime, $data['timestamp']);
$this->assertSame($this->endTime, $data['endTimestamp']);
$this->assertSame($this->page, $data['page']);
$this->assertSame($this->pageSize, $data['pageSize']);
$this->assertSame('fetchDeltaSince', $data['action']);
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage The transactionId parameter or the transactionReference parameter or the startTime and endTime parameters are required.
* @return void
*/
public function testTransactionIdOrReferenceOrTimesRequired()
{
$this->request->setTransactionId(null);
$this->request->getData();
}
/**
* @expectedException \Omnipay\Common\Exception\InvalidRequestException
* @expectedExceptionMessage Cannot fetch by both transaction and start/end time.
* @return void
*/
public function testTransactionIdOrTimesNotBoth()
{
$this->request->setStartTime($this->startTime);
$this->request->setEndTime($this->endTime);
$this->request->getData();
}
/**
* @return void
*/
public function testSendSuccess()
{
$this->setMockSoapResponse('FetchChargebacksSuccess.xml', array(
'CHARGEBACK_REFERENCE' => $this->chargebackReference,
'TRANSACTION_ID' => $this->transactionId,
'CURRENCY' => $this->currency,
'AMOUNT' => $this->amount,
'REASON_CODE' => $this->reasonCode,
'CASE_NUMBER' => $this->caseNumber,
'TIMESTAMP' => $this->timestamp
));
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->isPending());
$this->assertSame('OK', $response->getMessage());
$this->assertTrue(is_array($response->getChargebacks()));
$this->assertSame(2, count($response->getChargebacks()));
$chargebacks = $response->getChargebacks();
$this->assertInstanceOf('\Omnipay\Vindicia\Chargeback', $chargebacks[0]);
$this->assertInstanceOf('\Omnipay\Vindicia\Chargeback', $chargebacks[1]);
$chargeback = $chargebacks[0];
$this->assertSame($this->chargebackReference, $chargeback->getReference());
$this->assertSame($this->transactionId, $chargeback->getTransactionId());
$this->assertSame($this->currency, $chargeback->getCurrency());
$this->assertSame($this->amount, $chargeback->getAmount());
$this->assertSame($this->caseNumber, $chargeback->getCaseNumber());
$this->assertSame($this->reasonCode, $chargeback->getReasonCode());
$this->assertSame(AbstractRequest::TEST_ENDPOINT . '/18.0/Chargeback.wsdl', $this->getLastEndpoint());
}
/**
* @return void
*/
public function testSendByTimeSuccess()
{
$this->setMockSoapResponse('FetchChargebacksByTimeSuccess.xml', array(
'TIMESTAMP' => $this->timestamp
));
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->isPending());
$this->assertSame('OK', $response->getMessage());
$this->assertTrue(is_array($response->getChargebacks()));
$this->assertSame(2, count($response->getChargebacks()));
$chargebacks = $response->getChargebacks();
$this->assertNotNull($chargebacks[0]->getTransactionId());
$this->assertNotNull($chargebacks[1]->getTransactionId());
$this->assertSame(AbstractRequest::TEST_ENDPOINT . '/18.0/Chargeback.wsdl', $this->getLastEndpoint());
}
/**
* @return void
*/
public function testSendFailure()
{
$this->setMockSoapResponse('FetchChargebacksFailure.xml', array(
'TRANSACTION_ID' => $this->transactionId
));
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->isPending());
$this->assertSame('400', $response->getCode());
$this->assertSame('Unable to load chargebacks by merchantTransactionId "' . $this->transactionId . ' ": No match.', $response->getMessage());
$this->assertNull($response->getChargebacks());
}
/**
* @return void
*/
public function testSendByTimeFailure()
{
$this->setMockSoapResponse('FetchChargebacksByTimeFailure.xml');
$response = $this->request->send();
$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertFalse($response->isPending());
$this->assertSame('500', $response->getCode());
$this->assertSame('Process failed (Internal)', $response->getMessage());
$this->assertNull($response->getChargebacks());
}
}