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
|
|
|
* Txn Id Cc Handler - Handles reading responses for Boleto payment. |
20
|
|
|
*/ |
21
|
|
|
class TxnIdTwoCcHandler implements HandlerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Cc Payment Id - Payment Addtional Information. |
25
|
|
|
*/ |
26
|
|
|
public const PAYMENT_INFO_PAYMENT_ID = 'payment_id'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Cc Terminal NSU - Payment Addtional Information. |
30
|
|
|
*/ |
31
|
|
|
public const PAYMENT_INFO_TERMINAL_NSU = 'terminal_nsu'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Cc Authorization Code - Payment Addtional Information. |
35
|
|
|
*/ |
36
|
|
|
public const PAYMENT_INFO_AUTHORIZATION_CODE = 'authorization_code'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Cc Acquirer Transaction Id - Payment Addtional Information. |
40
|
|
|
*/ |
41
|
|
|
public const PAYMENT_INFO_ACQUIRER_TRANSACTION_ID = 'acquirer_transaction_id'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Cc Transaction Id - Payment Addtional Information. |
45
|
|
|
*/ |
46
|
|
|
public const PAYMENT_INFO_TRANSACTION_ID = 'transaction_id'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Cc Payment Id Secondary - Payment Addtional Information. |
50
|
|
|
*/ |
51
|
|
|
public const PAYMENT_INFO_PAYMENT_ID_SECONDARY = 'payment_id_secondary'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Cc Terminal NSU Secondary - Payment Addtional Information. |
55
|
|
|
*/ |
56
|
|
|
public const PAYMENT_INFO_TERMINAL_NSU_SECONDARY = 'terminal_nsu_secondary'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Cc Authorization Code Secondary - Payment Addtional Information. |
60
|
|
|
*/ |
61
|
|
|
public const PAYMENT_INFO_AUTHORIZATION_CODE_SECONDARY = 'authorization_code_secondary'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Cc Acquirer Transaction Id Secondary - Payment Addtional Information. |
65
|
|
|
*/ |
66
|
|
|
public const PAYMENT_INFO_ACQUIRER_TRANSACTION_ID_SECONDARY = 'acquirer_transaction_id_secondary'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Cc Transaction Id Secondary - Payment Addtional Information. |
70
|
|
|
*/ |
71
|
|
|
public const PAYMENT_INFO_TRANSACTION_ID_SECONDARY = 'transaction_id_secondary'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Cc Type - Payment Addtional Information. |
75
|
|
|
*/ |
76
|
|
|
public const PAYMENT_INFO_CC_TYPE = 'cc_type'; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Cc Number - Payment Addtional Information. |
80
|
|
|
*/ |
81
|
|
|
public const PAYMENT_INFO_CC_NUMBER = 'cc_number'; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Cc Owner - Payment Addtional Information. |
85
|
|
|
*/ |
86
|
|
|
public const PAYMENT_INFO_CC_OWNER = 'cc_holder_fullname'; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Cc Exp Month - Payment Addtional Information. |
90
|
|
|
*/ |
91
|
|
|
public const PAYMENT_INFO_CC_EXP_MONTH = 'cc_exp_month'; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Cc Exp Year - Payment Addtional Information. |
95
|
|
|
*/ |
96
|
|
|
public const PAYMENT_INFO_CC_EXP_YEAR = 'cc_exp_year'; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Cc Number Token - Payment Addtional Information. |
100
|
|
|
*/ |
101
|
|
|
public const PAYMENT_INFO_CC_NUMBER_ENC = 'cc_hash'; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Response Payments - Block name. |
105
|
|
|
*/ |
106
|
|
|
public const PAYMENTS = 'payments'; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Response Pay Credit - Block name. |
110
|
|
|
*/ |
111
|
|
|
public const CREDIT = 'credit'; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Response Pay Payment Id - Block name. |
115
|
|
|
*/ |
116
|
|
|
public const RESPONSE_PAYMENT_ID = 'payment_id'; |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Response Pay Terminal NSU - Block name. |
120
|
|
|
*/ |
121
|
|
|
public const RESPONSE_TERMINAL_NSU = 'terminal_nsu'; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Response Pay Authorization Code - Block name. |
125
|
|
|
*/ |
126
|
|
|
public const RESPONSE_AUTHORIZATION_CODE = 'authorization_code'; |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Response Pay Acquirer Transaction Id - Block name. |
130
|
|
|
*/ |
131
|
|
|
public const RESPONSE_ACQUIRER_TRANSACTION_ID = 'acquirer_transaction_id'; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Response Pay Transaction Id - Block name. |
135
|
|
|
*/ |
136
|
|
|
public const RESPONSE_TRANSACTION_ID = 'transaction_id'; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Response Pay Delayed - Block name. |
140
|
|
|
*/ |
141
|
|
|
public const RESPONSE_DELAYED = 'delayed'; |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Response Pay Status - Block name. |
145
|
|
|
*/ |
146
|
|
|
public const RESPONSE_STATUS = 'status'; |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Response Pay Approved - Block name. |
150
|
|
|
*/ |
151
|
|
|
public const RESPONSE_APPROVED = 'APPROVED'; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Response Pay Authorized - Block name. |
155
|
|
|
*/ |
156
|
|
|
public const RESPONSE_AUTHORIZED = 'AUTHORIZED'; |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Response Pay Pending - Block name. |
160
|
|
|
*/ |
161
|
|
|
public const RESPONSE_PENDING = 'PENDING'; |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @var Json |
165
|
|
|
*/ |
166
|
|
|
private $json; |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @var Config |
170
|
|
|
*/ |
171
|
|
|
private $config; |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @var ConfigCc |
175
|
|
|
*/ |
176
|
|
|
private $configCc; |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param Json $json |
180
|
|
|
* @param Config $config |
181
|
|
|
* @param ConfigCc $configCc |
182
|
|
|
*/ |
183
|
|
|
public function __construct( |
184
|
|
|
Json $json, |
185
|
|
|
Config $config, |
186
|
|
|
ConfigCc $configCc |
187
|
|
|
) { |
188
|
|
|
$this->json = $json; |
189
|
|
|
$this->config = $config; |
190
|
|
|
$this->configCc = $configCc; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Handles. |
195
|
|
|
* |
196
|
|
|
* @param array $handlingSubject |
197
|
|
|
* @param array $response |
198
|
|
|
* |
199
|
|
|
* @return void |
200
|
|
|
*/ |
201
|
|
|
public function handle(array $handlingSubject, array $response) |
202
|
|
|
{ |
203
|
|
|
if (!isset($handlingSubject['payment']) |
204
|
|
|
|| !$handlingSubject['payment'] instanceof PaymentDataObjectInterface |
205
|
|
|
) { |
206
|
|
|
throw new InvalidArgumentException('Payment data object should be provided'); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
$idx = 0; |
210
|
|
|
|
211
|
|
|
$payments = $response[self::PAYMENTS]; |
212
|
|
|
|
213
|
|
|
foreach ($payments as $paymentIdx) { |
214
|
|
|
$this->setDataForPaymentIdx($idx, $handlingSubject, $paymentIdx); |
215
|
|
|
$idx++; |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Set Data For Payment Idx. |
221
|
|
|
* |
222
|
|
|
* @param int $idx |
223
|
|
|
* @param array $handlingSubject |
224
|
|
|
* @param array $paymentIdx |
225
|
|
|
* |
226
|
|
|
* @return void |
227
|
|
|
*/ |
228
|
|
|
public function setDataForPaymentIdx( |
229
|
|
|
int $idx, |
230
|
|
|
array $handlingSubject, |
231
|
|
|
array $paymentIdx |
232
|
|
|
) { |
233
|
|
|
$paymentDO = $handlingSubject['payment']; |
234
|
|
|
$payment = $paymentDO->getPayment(); |
235
|
|
|
$payCredit = $paymentIdx[self::CREDIT]; |
236
|
|
|
if ($idx === 0) { |
237
|
|
|
$payment->setAdditionalInformation( |
238
|
|
|
self::PAYMENT_INFO_PAYMENT_ID, |
239
|
|
|
$paymentIdx[self::RESPONSE_PAYMENT_ID] |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
$payment->setAdditionalInformation( |
243
|
|
|
self::PAYMENT_INFO_TERMINAL_NSU, |
244
|
|
|
$payCredit[self::RESPONSE_TERMINAL_NSU] |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
$payment->setAdditionalInformation( |
248
|
|
|
self::PAYMENT_INFO_AUTHORIZATION_CODE, |
249
|
|
|
$payCredit[self::RESPONSE_AUTHORIZATION_CODE] |
250
|
|
|
); |
251
|
|
|
|
252
|
|
|
$payment->setAdditionalInformation( |
253
|
|
|
self::PAYMENT_INFO_ACQUIRER_TRANSACTION_ID, |
254
|
|
|
$payCredit[self::RESPONSE_ACQUIRER_TRANSACTION_ID] |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
$payment->setAdditionalInformation( |
258
|
|
|
self::PAYMENT_INFO_TRANSACTION_ID, |
259
|
|
|
$payCredit[self::RESPONSE_TRANSACTION_ID] |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
if ($idx === 1) { |
264
|
|
|
$payment->setAdditionalInformation( |
265
|
|
|
self::PAYMENT_INFO_PAYMENT_ID_SECONDARY, |
266
|
|
|
$paymentIdx[self::RESPONSE_PAYMENT_ID] |
267
|
|
|
); |
268
|
|
|
|
269
|
|
|
$payment->setAdditionalInformation( |
270
|
|
|
self::PAYMENT_INFO_TERMINAL_NSU_SECONDARY, |
271
|
|
|
$payCredit[self::RESPONSE_TERMINAL_NSU] |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
$payment->setAdditionalInformation( |
275
|
|
|
self::PAYMENT_INFO_AUTHORIZATION_CODE_SECONDARY, |
276
|
|
|
$payCredit[self::RESPONSE_AUTHORIZATION_CODE] |
277
|
|
|
); |
278
|
|
|
|
279
|
|
|
$payment->setAdditionalInformation( |
280
|
|
|
self::PAYMENT_INFO_ACQUIRER_TRANSACTION_ID_SECONDARY, |
281
|
|
|
$payCredit[self::RESPONSE_ACQUIRER_TRANSACTION_ID] |
282
|
|
|
); |
283
|
|
|
|
284
|
|
|
$payment->setAdditionalInformation( |
285
|
|
|
self::PAYMENT_INFO_TRANSACTION_ID_SECONDARY, |
286
|
|
|
$payCredit[self::RESPONSE_TRANSACTION_ID] |
287
|
|
|
); |
288
|
|
|
} |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|