|
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 Getnet\PaymentMagento\Gateway\Config\Config; |
|
12
|
|
|
use Getnet\PaymentMagento\Gateway\Config\ConfigCc; |
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
use Magento\Framework\Serialize\Serializer\Json; |
|
15
|
|
|
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface; |
|
16
|
|
|
use Magento\Payment\Gateway\Response\HandlerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Two Cc Transaction Capture Handler - Handles reading responses for CC on capture. |
|
20
|
|
|
* |
|
21
|
|
|
* @SuppressWarnings(PHPCPD) |
|
22
|
|
|
*/ |
|
23
|
|
|
class TwoCcTransactionCaptureHandler implements HandlerInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* Combined Id - Block name. |
|
27
|
|
|
*/ |
|
28
|
|
|
public const COMBINED_ID = 'combined_id'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Response Payments - Block name. |
|
32
|
|
|
*/ |
|
33
|
|
|
public const PAYMENTS = 'payments'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Response Pay Credit - Block name. |
|
37
|
|
|
*/ |
|
38
|
|
|
public const CREDIT = 'credit'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Response Pay Payment Id - Block name. |
|
42
|
|
|
*/ |
|
43
|
|
|
public const RESPONSE_PAYMENT_ID = 'payment_id'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Response Pay Delayed - Block name. |
|
47
|
|
|
*/ |
|
48
|
|
|
public const RESPONSE_DELAYED = 'delayed'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Response Pay Status - Block name. |
|
52
|
|
|
*/ |
|
53
|
|
|
public const RESPONSE_STATUS = 'status'; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Response Pay Approved - Block name. |
|
57
|
|
|
*/ |
|
58
|
|
|
public const RESPONSE_APPROVED = 'APPROVED'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Response Pay Authorized - Block name. |
|
62
|
|
|
*/ |
|
63
|
|
|
public const RESPONSE_AUTHORIZED = 'AUTHORIZED'; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Response Pay Pending - Block name. |
|
67
|
|
|
*/ |
|
68
|
|
|
public const RESPONSE_PENDING = 'PENDING'; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @var Json |
|
72
|
|
|
*/ |
|
73
|
|
|
protected $json; |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @var Config |
|
77
|
|
|
*/ |
|
78
|
|
|
protected $config; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @var ConfigCc |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $configCc; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param Json $json |
|
87
|
|
|
* @param Config $config |
|
88
|
|
|
* @param ConfigCc $configCc |
|
89
|
|
|
*/ |
|
90
|
|
|
public function __construct( |
|
91
|
|
|
Json $json, |
|
92
|
|
|
Config $config, |
|
93
|
|
|
ConfigCc $configCc |
|
94
|
|
|
) { |
|
95
|
|
|
$this->json = $json; |
|
96
|
|
|
$this->config = $config; |
|
97
|
|
|
$this->configCc = $configCc; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Handles. |
|
102
|
|
|
* |
|
103
|
|
|
* @param array $handlingSubject |
|
104
|
|
|
* @param array $response |
|
105
|
|
|
* |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function handle(array $handlingSubject, array $response) |
|
109
|
|
|
{ |
|
110
|
|
|
if (!isset($handlingSubject['payment']) |
|
111
|
|
|
|| !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
|
112
|
|
|
) { |
|
113
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
|
114
|
|
|
} |
|
115
|
|
|
$isApproved = false; |
|
116
|
|
|
|
|
117
|
|
|
$isDenied = true; |
|
118
|
|
|
|
|
119
|
|
|
$paymentDO = $handlingSubject['payment']; |
|
120
|
|
|
|
|
121
|
|
|
$payment = $paymentDO->getPayment(); |
|
122
|
|
|
|
|
123
|
|
|
$order = $payment->getOrder(); |
|
124
|
|
|
|
|
125
|
|
|
$amount = $order->getBaseGrandTotal(); |
|
126
|
|
|
|
|
127
|
|
|
$baseAmount = $order->getGrandTotal(); |
|
128
|
|
|
|
|
129
|
|
|
foreach ($response[self::PAYMENTS] as $paymentCredit) { |
|
130
|
|
|
if ($paymentCredit[self::RESPONSE_STATUS] === self::RESPONSE_APPROVED || |
|
131
|
|
|
$paymentCredit[self::RESPONSE_STATUS] === self::RESPONSE_AUTHORIZED || |
|
132
|
|
|
$paymentCredit[self::RESPONSE_STATUS] === self::RESPONSE_PENDING |
|
133
|
|
|
) { |
|
134
|
|
|
$isApproved = true; |
|
135
|
|
|
$isDenied = false; |
|
136
|
|
|
} |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$transactionId = $response[self::COMBINED_ID]; |
|
140
|
|
|
$payment->setAuthorizationTransaction($transactionId); |
|
141
|
|
|
$payment->registerAuthorizationNotification($amount); |
|
142
|
|
|
$payment->setAmountAuthorized($amount); |
|
143
|
|
|
$payment->setBaseAmountAuthorized($baseAmount); |
|
144
|
|
|
$payment->setIsTransactionApproved($isApproved); |
|
145
|
|
|
$payment->setIsTransactionDenied($isDenied); |
|
146
|
|
|
$payment->registerCaptureNotification($amount); |
|
147
|
|
|
$payment->setTransactionId($transactionId); |
|
148
|
|
|
$payment->setTransactionDetails($this->json->serialize($response)); |
|
149
|
|
|
$payment->setAdditionalData($this->json->serialize($response)); |
|
|
|
|
|
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.