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