|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Getnet. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bruno Elisei <[email protected]> |
|
6
|
|
|
* See LICENSE for license details. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Getnet\PaymentMagento\Gateway\Response; |
|
10
|
|
|
|
|
11
|
|
|
use InvalidArgumentException; |
|
12
|
|
|
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
|
13
|
|
|
use Magento\Payment\Gateway\Response\HandlerInterface; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class Accept Payment Handler - Set flow when accepting a payment. |
|
17
|
|
|
* |
|
18
|
|
|
* @SuppressWarnings(PHPCPD) |
|
19
|
|
|
*/ |
|
20
|
|
|
class AcceptPaymentHandler implements HandlerInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @const TXN ID |
|
24
|
|
|
*/ |
|
25
|
|
|
public const TXN_ID = 'TXN_ID'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Handles. |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $handlingSubject |
|
31
|
|
|
* @param array $response |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function handle(array $handlingSubject, array $response) |
|
36
|
|
|
{ |
|
37
|
|
|
if (!isset($handlingSubject['payment']) |
|
38
|
|
|
|| !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
|
39
|
|
|
) { |
|
40
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if ($response['RESULT_CODE']) { |
|
44
|
|
|
$paymentDO = $handlingSubject['payment']; |
|
45
|
|
|
|
|
46
|
|
|
$payment = $paymentDO->getPayment(); |
|
47
|
|
|
|
|
48
|
|
|
$order = $payment->getOrder(); |
|
49
|
|
|
$amount = $order->getTotalDue(); |
|
50
|
|
|
$baseAmount = $order->getBaseTotalDue(); |
|
51
|
|
|
|
|
52
|
|
|
$payment->registerAuthorizationNotification($amount); |
|
53
|
|
|
$payment->registerCaptureNotification($amount); |
|
54
|
|
|
$payment->setIsTransactionApproved(true); |
|
55
|
|
|
$payment->setIsTransactionDenied(false); |
|
56
|
|
|
$payment->setIsInProcess(true); |
|
57
|
|
|
$payment->setIsTransactionClosed(true); |
|
58
|
|
|
$payment->setShouldCloseParentTransaction(true); |
|
59
|
|
|
$payment->setAmountAuthorized($amount); |
|
60
|
|
|
$payment->setBaseAmountAuthorized($baseAmount); |
|
61
|
|
|
$payment->setShouldCloseParentTransaction(true); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|