|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright © Wirecard Brasil. All rights reserved. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bruno Elisei <[email protected]> |
|
6
|
|
|
* See COPYING.txt for license details. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Moip\Magento2\Observer; |
|
10
|
|
|
|
|
11
|
|
|
use Magento\Framework\Event\Observer; |
|
|
|
|
|
|
12
|
|
|
use Magento\Payment\Observer\AbstractDataAssignObserver; |
|
|
|
|
|
|
13
|
|
|
use Magento\Quote\Api\Data\PaymentInterface; |
|
|
|
|
|
|
14
|
|
|
use Moip\Magento2\Gateway\Config\Config; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class DataAssignObserverCc - Capture credit card payment information. |
|
18
|
|
|
*/ |
|
19
|
|
|
class DataAssignObserverCc extends AbstractDataAssignObserver |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @const Method Name Block |
|
23
|
|
|
*/ |
|
24
|
|
|
const METHOD_NAME = 'method_name'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @const Method Name |
|
28
|
|
|
*/ |
|
29
|
|
|
const METHOD_NAME_TYPE = 'Cartão de Crédito'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @const Hahs |
|
33
|
|
|
*/ |
|
34
|
|
|
const PAYER_HASH = 'cc_hash'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @const Credit Card Number |
|
38
|
|
|
*/ |
|
39
|
|
|
const PAYER_CC_NUMBER = 'cc_number'; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @const Credit Card Type |
|
43
|
|
|
*/ |
|
44
|
|
|
const PAYER_CC_TYPE = 'cc_type'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @const Credit Card Exp Month |
|
48
|
|
|
*/ |
|
49
|
|
|
const PAYER_CC_EXP_M = 'cc_exp_month'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @const Credit Card Type |
|
53
|
|
|
*/ |
|
54
|
|
|
const PAYER_CC_EXP_Y = 'cc_exp_year'; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @const Installment |
|
58
|
|
|
*/ |
|
59
|
|
|
const PAYER_CC_INSTALLMENTS = 'cc_installments'; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @const Holder Full Nane |
|
63
|
|
|
*/ |
|
64
|
|
|
const PAYER_HOLDER_FULLNAME = 'cc_holder_fullname'; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @const Holder Birth Date |
|
68
|
|
|
*/ |
|
69
|
|
|
const PAYER_HOLDER_BIRTH_DATE = 'cc_holder_birth_date'; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @const Holder Tax Document |
|
73
|
|
|
*/ |
|
74
|
|
|
const PAYER_HOLDER_TAX_DOCUMENT = 'cc_holder_tax_document'; |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @const Holder Phone |
|
78
|
|
|
*/ |
|
79
|
|
|
const PAYER_HOLDER_PHONE = 'cc_holder_phone'; |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @const Use save card |
|
83
|
|
|
*/ |
|
84
|
|
|
const PAYER_CC_SAVE = 'is_active_payment_token_enabler'; |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @const Credit Card - CVV |
|
88
|
|
|
*/ |
|
89
|
|
|
const PAYER_CC_CID = 'cc_cid'; |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @var array |
|
93
|
|
|
*/ |
|
94
|
|
|
protected $addInformationList = [ |
|
95
|
|
|
self::PAYER_HASH, |
|
96
|
|
|
self::PAYER_CC_TYPE, |
|
97
|
|
|
self::PAYER_CC_EXP_M, |
|
98
|
|
|
self::PAYER_CC_EXP_Y, |
|
99
|
|
|
self::PAYER_CC_NUMBER, |
|
100
|
|
|
self::PAYER_CC_INSTALLMENTS, |
|
101
|
|
|
self::PAYER_HOLDER_FULLNAME, |
|
102
|
|
|
self::PAYER_HOLDER_TAX_DOCUMENT, |
|
103
|
|
|
self::PAYER_HOLDER_BIRTH_DATE, |
|
104
|
|
|
self::PAYER_HOLDER_PHONE, |
|
105
|
|
|
self::PAYER_CC_SAVE, |
|
106
|
|
|
self::PAYER_CC_CID, |
|
107
|
|
|
]; |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @var |
|
111
|
|
|
*/ |
|
112
|
|
|
protected $config; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param Config $config |
|
116
|
|
|
*/ |
|
117
|
|
|
public function __construct( |
|
118
|
|
|
Config $config |
|
119
|
|
|
) { |
|
120
|
|
|
$this->config = $config; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param Observer $observer |
|
125
|
|
|
*/ |
|
126
|
|
|
public function execute(Observer $observer) |
|
127
|
|
|
{ |
|
128
|
|
|
$data = $this->readDataArgument($observer); |
|
129
|
|
|
|
|
130
|
|
|
$additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA); |
|
131
|
|
|
|
|
132
|
|
|
if (!is_array($additionalData)) { |
|
133
|
|
|
return; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
$paymentInfo = $this->readPaymentModelArgument($observer); |
|
137
|
|
|
|
|
138
|
|
|
$paymentInfo->setAdditionalInformation( |
|
139
|
|
|
self::METHOD_NAME, |
|
140
|
|
|
self::METHOD_NAME_TYPE |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
foreach ($this->addInformationList as $addInformationKey) { |
|
144
|
|
|
if (isset($additionalData[$addInformationKey])) { |
|
145
|
|
|
if ($addInformationKey === self::PAYER_CC_TYPE) { |
|
146
|
|
|
$paymentInfo->setAdditionalInformation( |
|
147
|
|
|
$addInformationKey, |
|
148
|
|
|
$this->getFullTypeName($additionalData[$addInformationKey]) |
|
149
|
|
|
); |
|
150
|
|
|
continue; |
|
151
|
|
|
} |
|
152
|
|
|
if ($addInformationKey === self::PAYER_CC_NUMBER) { |
|
153
|
|
|
$paymentInfo->setAdditionalInformation( |
|
154
|
|
|
$addInformationKey, |
|
155
|
|
|
'xxxx xxxx xxxx '.substr($additionalData[$addInformationKey], -4) |
|
156
|
|
|
); |
|
157
|
|
|
continue; |
|
158
|
|
|
} |
|
159
|
|
|
if ($additionalData[$addInformationKey]) { |
|
160
|
|
|
$paymentInfo->setAdditionalInformation( |
|
161
|
|
|
$addInformationKey, |
|
162
|
|
|
$additionalData[$addInformationKey] |
|
163
|
|
|
); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get Name for Cc Type. |
|
171
|
|
|
* |
|
172
|
|
|
* @parm string |
|
173
|
|
|
* |
|
174
|
|
|
* @return array |
|
175
|
|
|
*/ |
|
176
|
|
|
public function getFullTypeName(string $type): string |
|
177
|
|
|
{ |
|
178
|
|
|
$mapper = $this->config->getCcTypesMapper(); |
|
179
|
|
|
|
|
180
|
|
|
return $mapper[$type]; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths