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\Gateway\Request; |
10
|
|
|
|
11
|
|
|
use Magento\Payment\Gateway\Request\BuilderInterface; |
|
|
|
|
12
|
|
|
use Moip\Magento2\Gateway\Data\Order\OrderAdapterFactory; |
|
|
|
|
13
|
|
|
use Moip\Magento2\Gateway\SubjectReader; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class CustomerDataRequest - Customer structure. |
17
|
|
|
*/ |
18
|
|
|
class CustomerDataRequest implements BuilderInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Customer block name. |
22
|
|
|
*/ |
23
|
|
|
public const CUSTOMER = 'customer'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Unique user id. |
27
|
|
|
* Required. |
28
|
|
|
*/ |
29
|
|
|
const OWN_ID = 'ownId'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* The first name value must be less than or equal to 255 characters. |
33
|
|
|
* Required. |
34
|
|
|
*/ |
35
|
|
|
const FIRST_NAME = 'firstName'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The last name value must be less than or equal to 255 characters. |
39
|
|
|
* Required. |
40
|
|
|
*/ |
41
|
|
|
const LAST_NAME = 'lastName'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The full name value must be less than or equal to 255 characters. |
45
|
|
|
* Required. |
46
|
|
|
*/ |
47
|
|
|
const FULL_NAME = 'fullname'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* The customer birth Date. Date Y-MM-dd. |
51
|
|
|
* Required. |
52
|
|
|
*/ |
53
|
|
|
const BIRTH_DATE = 'birthDate'; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The customer’s company. 255 character maximum. |
57
|
|
|
* Required. |
58
|
|
|
*/ |
59
|
|
|
const COMPANY = 'company'; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* The customer’s email address. |
63
|
|
|
* Required. |
64
|
|
|
*/ |
65
|
|
|
const EMAIL = 'email'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Phone block name. |
69
|
|
|
*/ |
70
|
|
|
const PHONE = 'phone'; |
71
|
|
|
|
72
|
|
|
/* |
73
|
|
|
* Phone Country Code. Must be 2 characters and can (DDI) |
74
|
|
|
* Required. |
75
|
|
|
*/ |
76
|
|
|
const PHONE_CONNTRY_CODE = 'countryCode'; |
77
|
|
|
|
78
|
|
|
/* |
79
|
|
|
* Phone Area code. Must be 2 characters and can (DDD) |
80
|
|
|
* Required. |
81
|
|
|
*/ |
82
|
|
|
const PHONE_AREA_CODE = 'areaCode'; |
83
|
|
|
|
84
|
|
|
/* |
85
|
|
|
* Phone Number. Must be 8 - 9 characters |
86
|
|
|
* Required. |
87
|
|
|
*/ |
88
|
|
|
const PHONE_NUMBER = 'number'; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var SubjectReader |
92
|
|
|
*/ |
93
|
|
|
private $subjectReader; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var OrderAdapterFactory |
97
|
|
|
*/ |
98
|
|
|
private $orderAdapterFactory; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @param SubjectReader $subjectReader |
102
|
|
|
* @param OrderAdapterFactory $orderAdapterFactory |
103
|
|
|
*/ |
104
|
|
|
public function __construct( |
105
|
|
|
SubjectReader $subjectReader, |
106
|
|
|
OrderAdapterFactory $orderAdapterFactory |
107
|
|
|
) { |
108
|
|
|
$this->subjectReader = $subjectReader; |
109
|
|
|
$this->orderAdapterFactory = $orderAdapterFactory; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Value For Field Address. |
114
|
|
|
* |
115
|
|
|
* @param $param_telefone |
116
|
|
|
* @param $return_ddd |
117
|
|
|
* |
118
|
|
|
* @return string value |
119
|
|
|
*/ |
120
|
|
|
public function getNumberOrDDD($param_telefone, $return_ddd = false) |
121
|
|
|
{ |
122
|
|
|
$cust_ddd = '11'; |
123
|
|
|
$cust_telephone = preg_replace('/[^0-9]/', '', $param_telefone); |
124
|
|
|
if (strlen($cust_telephone) == 11) { |
125
|
|
|
$str = strlen($cust_telephone) - 9; |
126
|
|
|
$indice = 9; |
127
|
|
|
} else { |
128
|
|
|
$str = strlen($cust_telephone) - 8; |
129
|
|
|
$indice = 8; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if ($str > 0) { |
133
|
|
|
$cust_ddd = substr($cust_telephone, 0, 2); |
134
|
|
|
$cust_telephone = substr($cust_telephone, $str, $indice); |
135
|
|
|
} |
136
|
|
|
if ($return_ddd === false) { |
137
|
|
|
$number = $cust_telephone; |
138
|
|
|
} else { |
139
|
|
|
$number = $cust_ddd; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $number; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* StructurePhone. |
147
|
|
|
* |
148
|
|
|
* @param $phone full phone number, |
|
|
|
|
149
|
|
|
* @param $defaultCountryCode, |
150
|
|
|
* |
151
|
|
|
* @return array |
152
|
|
|
*/ |
153
|
|
|
public function structurePhone($phone, $defaultCountryCode) |
154
|
|
|
{ |
155
|
|
|
return [ |
156
|
|
|
self::PHONE_CONNTRY_CODE => (int) $defaultCountryCode, |
157
|
|
|
self::PHONE_AREA_CODE => (int) $this->getNumberOrDDD($phone, true), |
158
|
|
|
self::PHONE_NUMBER => (int) $this->getNumberOrDDD($phone), |
159
|
|
|
]; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* {@inheritdoc} |
164
|
|
|
*/ |
165
|
|
|
public function build(array $buildSubject) |
166
|
|
|
{ |
167
|
|
|
$paymentDO = $this->subjectReader->readPayment($buildSubject); |
168
|
|
|
|
169
|
|
|
$name = null; |
170
|
|
|
|
171
|
|
|
$payment = $paymentDO->getPayment(); |
172
|
|
|
|
173
|
|
|
$orderAdapter = $this->orderAdapterFactory->create( |
174
|
|
|
['order' => $payment->getOrder()] |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$billingAddress = $orderAdapter->getBillingAddress(); |
178
|
|
|
|
179
|
|
|
$defaultCountryCode = ''; |
180
|
|
|
|
181
|
|
|
if ($billingAddress->getCountryId() == 'BR') { |
182
|
|
|
$defaultCountryCode = '55'; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$dob = $orderAdapter->getCustomerDob(); |
186
|
|
|
$dob = $dob ? date('Y-m-d', strtotime($dob)) : '1985-10-10'; |
187
|
|
|
|
188
|
|
|
if ($dob === date('Y-m-d')) { |
189
|
|
|
$dob = '1985-11-11'; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
//* sobrescreve na order o name caso seja capturado no formulario de pagamento |
193
|
|
|
if ($payment->getAdditionalInformation('boleto_payer_fullname')) { |
194
|
|
|
$name = $payment->getAdditionalInformation('boleto_payer_fullname'); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
if (!$name) { |
198
|
|
|
$name = $billingAddress->getFirstname().' '.$billingAddress->getLastname(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
return [ |
202
|
|
|
self::CUSTOMER => [ |
203
|
|
|
self::OWN_ID => $billingAddress->getEmail(), |
204
|
|
|
self::FULL_NAME => $name, |
205
|
|
|
self::COMPANY => $billingAddress->getCompany(), |
206
|
|
|
self::PHONE => $this->structurePhone($billingAddress->getTelephone(), $defaultCountryCode), |
207
|
|
|
self::EMAIL => $billingAddress->getEmail(), |
208
|
|
|
self::BIRTH_DATE => $dob, |
209
|
|
|
], |
210
|
|
|
]; |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
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