1
|
|
|
<?php |
2
|
|
|
namespace Loevgaard\AltaPay\Entity; |
3
|
|
|
|
4
|
|
|
use Loevgaard\AltaPay\Exception\XmlException; |
5
|
|
|
use Loevgaard\AltaPay\Hydrator\HydratableInterface; |
6
|
|
|
|
7
|
|
|
class Transaction implements HydratableInterface |
8
|
|
|
{ |
9
|
|
|
use PaymentNatureServiceTrait; |
10
|
|
|
use PaymentInfosTrait; |
11
|
|
|
use CustomerInfoTrait; |
12
|
|
|
use ReconciliationIdentifiersTrait; |
13
|
|
|
use CreditCardExpiryTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var int |
17
|
|
|
*/ |
18
|
|
|
private $transactionId; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $paymentId; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $authType; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $cardStatus; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $creditCardToken; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $creditCardMaskedPan; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $threeDSecureResult; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var string |
52
|
|
|
*/ |
53
|
|
|
private $liableForChargeback; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
private $CVVCheckResult; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var string |
62
|
|
|
*/ |
63
|
|
|
private $blacklistToken; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var string |
67
|
|
|
*/ |
68
|
|
|
private $shopOrderId; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
private $shop; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
private $terminal; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
private $transactionStatus; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
private $reasonCode; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var int |
92
|
|
|
*/ |
93
|
|
|
private $merchantCurrency; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var string |
97
|
|
|
*/ |
98
|
|
|
private $merchantCurrencyAlpha; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @var int |
102
|
|
|
*/ |
103
|
|
|
private $cardHolderCurrency; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var string |
107
|
|
|
*/ |
108
|
|
|
private $cardHolderCurrencyAlpha; |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @var float |
112
|
|
|
*/ |
113
|
|
|
private $reservedAmount; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var float |
117
|
|
|
*/ |
118
|
|
|
private $capturedAmount; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var float |
122
|
|
|
*/ |
123
|
|
|
private $refundedAmount; |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @var float |
127
|
|
|
*/ |
128
|
|
|
private $creditedAmount; |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @var float |
132
|
|
|
*/ |
133
|
|
|
private $recurringDefaultAmount; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @var float |
137
|
|
|
*/ |
138
|
|
|
private $surchargeAmount; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @var \DateTimeImmutable |
142
|
|
|
*/ |
143
|
|
|
private $createdDate; |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @var \DateTimeImmutable |
147
|
|
|
*/ |
148
|
|
|
private $updatedDate; |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @var string |
152
|
|
|
*/ |
153
|
|
|
private $paymentNature; |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @var string |
157
|
|
|
*/ |
158
|
|
|
private $paymentSchemeName; |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @var string |
162
|
|
|
*/ |
163
|
|
|
private $addressVerification; |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @var string |
167
|
|
|
*/ |
168
|
|
|
private $addressVerificationDescription; |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @var float |
172
|
|
|
*/ |
173
|
|
|
private $fraudRiskScore; |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @var string |
177
|
|
|
*/ |
178
|
|
|
private $fraudExplanation; |
179
|
|
|
|
180
|
9 |
|
public function hydrateXml(\SimpleXMLElement $xml) |
181
|
|
|
{ |
182
|
9 |
|
$this->transactionId = (int)$xml->TransactionId; |
183
|
9 |
|
$this->paymentId = (string)$xml->PaymentId; |
184
|
9 |
|
$this->authType = isset($xml->AuthType) ? (string)$xml->AuthType : null; |
185
|
9 |
|
$this->cardStatus = (string)$xml->CardStatus; |
186
|
9 |
|
$this->creditCardToken = (string)$xml->CreditCardToken; |
187
|
9 |
|
$this->creditCardMaskedPan = (string)$xml->CreditCardMaskedPan; |
188
|
9 |
|
$this->threeDSecureResult = (string)$xml->ThreeDSecureResult; |
189
|
9 |
|
$this->liableForChargeback = (string)$xml->LiableForChargeback; |
190
|
9 |
|
$this->CVVCheckResult = isset($xml->CVVCheckResult) ? (string)$xml->CVVCheckResult : null; |
191
|
9 |
|
$this->blacklistToken = (string)$xml->BlacklistToken; |
192
|
9 |
|
$this->shopOrderId = (string)$xml->ShopOrderId; |
193
|
9 |
|
$this->shop = (string)$xml->Shop; |
194
|
9 |
|
$this->terminal = (string)$xml->Terminal; |
195
|
9 |
|
$this->transactionStatus = (string)$xml->TransactionStatus; |
196
|
9 |
|
$this->reasonCode = (string)$xml->ReasonCode; |
197
|
9 |
|
$this->merchantCurrency = (int)$xml->MerchantCurrency; |
198
|
9 |
|
$this->merchantCurrencyAlpha = (string)$xml->MerchantCurrencyAlpha; |
199
|
9 |
|
$this->cardHolderCurrency = (int)$xml->CardHolderCurrency; |
200
|
9 |
|
$this->cardHolderCurrencyAlpha = (string)$xml->CardHolderCurrencyAlpha; |
201
|
9 |
|
$this->reservedAmount = (float)$xml->ReservedAmount; |
202
|
9 |
|
$this->capturedAmount = (float)$xml->CapturedAmount; |
203
|
9 |
|
$this->refundedAmount = (float)$xml->RefundedAmount; |
204
|
9 |
|
$this->creditedAmount = isset($xml->CreditedAmount) ? (float)$xml->CreditedAmount : null; |
205
|
9 |
|
$this->recurringDefaultAmount = (float)$xml->RecurringDefaultAmount; |
206
|
9 |
|
$this->surchargeAmount = isset($xml->SurchargeAmount) ? (float)$xml->SurchargeAmount : null; |
207
|
9 |
|
$this->paymentNature = (string)$xml->PaymentNature; |
208
|
9 |
|
$this->paymentSchemeName = isset($xml->PaymentSchemeName) ? (string)$xml->PaymentSchemeName : null; |
209
|
9 |
|
$this->addressVerification = isset($xml->AddressVerification) ? (string)$xml->AddressVerification : null; |
210
|
9 |
|
$this->addressVerificationDescription = isset($xml->AddressVerificationDescription) ? (string)$xml->AddressVerificationDescription : null; |
211
|
9 |
|
$this->fraudRiskScore = (float)$xml->FraudRiskScore; |
212
|
9 |
|
$this->fraudExplanation = (string)$xml->FraudExplanation; |
213
|
9 |
|
$this->hydratePaymentNatureService($xml); |
214
|
9 |
|
$this->hydratePaymentInfos($xml); |
215
|
9 |
|
$this->hydrateCustomerInfo($xml); |
216
|
9 |
|
$this->hydrateReconciliationIdentifiers($xml); |
217
|
9 |
|
$this->hydrateCreditCardExpiry($xml); |
218
|
|
|
|
219
|
9 |
|
$this->createdDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$xml->CreatedDate); |
220
|
9 |
|
if ($this->createdDate === false) { |
221
|
|
|
$exception = new XmlException('The created date format is wrong'); |
222
|
|
|
$exception->setXmlElement($xml); |
223
|
|
|
throw $exception; |
224
|
|
|
} |
225
|
|
|
|
226
|
9 |
|
$this->updatedDate = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', (string)$xml->UpdatedDate); |
227
|
9 |
View Code Duplication |
if ($this->updatedDate === false) { |
|
|
|
|
228
|
|
|
$exception = new XmlException('The updated date format is wrong'); |
229
|
|
|
$exception->setXmlElement($xml); |
230
|
|
|
throw $exception; |
231
|
|
|
} |
232
|
9 |
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return int |
236
|
|
|
*/ |
237
|
3 |
|
public function getTransactionId() : int |
238
|
|
|
{ |
239
|
3 |
|
return $this->transactionId; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
3 |
|
public function getPaymentId() : string |
246
|
|
|
{ |
247
|
3 |
|
return $this->paymentId; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
|
|
public function getAuthType(): string |
254
|
|
|
{ |
255
|
|
|
return $this->authType; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return string |
260
|
|
|
*/ |
261
|
3 |
|
public function getCardStatus() : string |
262
|
|
|
{ |
263
|
3 |
|
return $this->cardStatus; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return string |
268
|
|
|
*/ |
269
|
3 |
|
public function getCreditCardToken() : string |
270
|
|
|
{ |
271
|
3 |
|
return $this->creditCardToken; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return string |
276
|
|
|
*/ |
277
|
3 |
|
public function getCreditCardMaskedPan() : string |
278
|
|
|
{ |
279
|
3 |
|
return $this->creditCardMaskedPan; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return string |
284
|
|
|
*/ |
285
|
3 |
|
public function getThreeDSecureResult() : string |
286
|
|
|
{ |
287
|
3 |
|
return $this->threeDSecureResult; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return string |
292
|
|
|
*/ |
293
|
3 |
|
public function getLiableForChargeback() : string |
294
|
|
|
{ |
295
|
3 |
|
return $this->liableForChargeback; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return string |
300
|
|
|
*/ |
301
|
|
|
public function getCVVCheckResult(): string |
302
|
|
|
{ |
303
|
|
|
return $this->CVVCheckResult; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return string |
308
|
|
|
*/ |
309
|
3 |
|
public function getBlacklistToken() : string |
310
|
|
|
{ |
311
|
3 |
|
return $this->blacklistToken; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @return string |
316
|
|
|
*/ |
317
|
3 |
|
public function getShopOrderId() : string |
318
|
|
|
{ |
319
|
3 |
|
return $this->shopOrderId; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @return string |
324
|
|
|
*/ |
325
|
3 |
|
public function getShop() : string |
326
|
|
|
{ |
327
|
3 |
|
return $this->shop; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* @return string |
332
|
|
|
*/ |
333
|
3 |
|
public function getTerminal() : string |
334
|
|
|
{ |
335
|
3 |
|
return $this->terminal; |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
/** |
339
|
|
|
* @return string |
340
|
|
|
*/ |
341
|
3 |
|
public function getTransactionStatus() : string |
342
|
|
|
{ |
343
|
3 |
|
return $this->transactionStatus; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @return string |
348
|
|
|
*/ |
349
|
3 |
|
public function getReasonCode() : string |
350
|
|
|
{ |
351
|
3 |
|
return $this->reasonCode; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @return int |
356
|
|
|
*/ |
357
|
3 |
|
public function getMerchantCurrency() : int |
358
|
|
|
{ |
359
|
3 |
|
return $this->merchantCurrency; |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
/** |
363
|
|
|
* @return string |
364
|
|
|
*/ |
365
|
3 |
|
public function getMerchantCurrencyAlpha() : string |
366
|
|
|
{ |
367
|
3 |
|
return $this->merchantCurrencyAlpha; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @return int |
372
|
|
|
*/ |
373
|
3 |
|
public function getCardHolderCurrency() : int |
374
|
|
|
{ |
375
|
3 |
|
return $this->cardHolderCurrency; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
/** |
379
|
|
|
* @return string |
380
|
|
|
*/ |
381
|
3 |
|
public function getCardHolderCurrencyAlpha() : string |
382
|
|
|
{ |
383
|
3 |
|
return $this->cardHolderCurrencyAlpha; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return float |
388
|
|
|
*/ |
389
|
3 |
|
public function getReservedAmount() : float |
390
|
|
|
{ |
391
|
3 |
|
return $this->reservedAmount; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @return float |
396
|
|
|
*/ |
397
|
3 |
|
public function getCapturedAmount() : float |
398
|
|
|
{ |
399
|
3 |
|
return $this->capturedAmount; |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
/** |
403
|
|
|
* @return float |
404
|
|
|
*/ |
405
|
3 |
|
public function getRefundedAmount() : float |
406
|
|
|
{ |
407
|
3 |
|
return $this->refundedAmount; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* @return float |
412
|
|
|
*/ |
413
|
|
|
public function getCreditedAmount(): float |
414
|
|
|
{ |
415
|
|
|
return $this->creditedAmount; |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @return float |
420
|
|
|
*/ |
421
|
3 |
|
public function getRecurringDefaultAmount() : float |
422
|
|
|
{ |
423
|
3 |
|
return $this->recurringDefaultAmount; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
/** |
427
|
|
|
* @return float |
428
|
|
|
*/ |
429
|
|
|
public function getSurchargeAmount(): float |
430
|
|
|
{ |
431
|
|
|
return $this->surchargeAmount; |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @return \DateTimeImmutable |
436
|
|
|
*/ |
437
|
3 |
|
public function getCreatedDate() : \DateTimeImmutable |
438
|
|
|
{ |
439
|
3 |
|
return $this->createdDate; |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @return \DateTimeImmutable |
444
|
|
|
*/ |
445
|
3 |
|
public function getUpdatedDate() : \DateTimeImmutable |
446
|
|
|
{ |
447
|
3 |
|
return $this->updatedDate; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* @return string |
452
|
|
|
*/ |
453
|
3 |
|
public function getPaymentNature() : string |
454
|
|
|
{ |
455
|
3 |
|
return $this->paymentNature; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* @return float |
460
|
|
|
*/ |
461
|
3 |
|
public function getFraudRiskScore() : float |
462
|
|
|
{ |
463
|
3 |
|
return $this->fraudRiskScore; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* @return string |
468
|
|
|
*/ |
469
|
3 |
|
public function getFraudExplanation() : string |
470
|
|
|
{ |
471
|
3 |
|
return $this->fraudExplanation; |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
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.