1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Computop\Mapper\Init\PostPlace; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\ComputopAddressLineTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\ComputopAddressTransfer; |
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\ComputopBrowserInfoTransfer; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\ComputopConsumerTransfer; |
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\ComputopCountryTransfer; |
|
|
|
|
15
|
|
|
use Generated\Shared\Transfer\ComputopCredentialOnFileTransfer; |
|
|
|
|
16
|
|
|
use Generated\Shared\Transfer\ComputopCredentialOnFileTypeTransfer; |
|
|
|
|
17
|
|
|
use Generated\Shared\Transfer\ComputopCustomerInfoTransfer; |
|
|
|
|
18
|
|
|
use Generated\Shared\Transfer\ComputopPayNowPaymentTransfer; |
|
|
|
|
19
|
|
|
use Generated\Shared\Transfer\CountryCollectionTransfer; |
|
|
|
|
20
|
|
|
use Generated\Shared\Transfer\CountryTransfer; |
|
|
|
|
21
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
22
|
|
|
use Spryker\Yves\Router\Router\Router; |
23
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig as ComputopSharedConfig; |
24
|
|
|
use SprykerEco\Shared\Computop\Config\ComputopApiConfig; |
25
|
|
|
use SprykerEco\Yves\Computop\Mapper\Init\AbstractMapper; |
26
|
|
|
use SprykerEco\Yves\Computop\Plugin\Router\ComputopRouteProviderPlugin; |
27
|
|
|
|
28
|
|
|
class PayNowMapper extends AbstractMapper |
29
|
|
|
{ |
30
|
|
|
protected const HEADER_USER_AGENT = 'User-Agent'; |
31
|
|
|
protected const HEADER_ACCEPT = 'Accept'; |
32
|
|
|
protected const IFRAME_COLOR_DEPTH = 24; |
33
|
|
|
protected const IFRAME_SCREEN_HEIGHT = 723; |
34
|
|
|
protected const IFRAME_SCREEN_WIDTH = 1536; |
35
|
|
|
protected const IFRAME_TIME_ZONE_OFFSET = '300'; |
36
|
|
|
protected const IFRAME_IS_JAVA_ENABLED = false; |
37
|
|
|
protected const IFRAME_IS_JAVA_SCRIPT_ENABLED = true; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
41
|
|
|
* |
42
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
43
|
|
|
*/ |
44
|
|
|
public function createComputopPaymentTransfer(QuoteTransfer $quoteTransfer) |
45
|
|
|
{ |
46
|
|
|
/** @var \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPaymentTransfer */ |
47
|
|
|
$computopPaymentTransfer = parent::createComputopPaymentTransfer($quoteTransfer); |
48
|
|
|
$computopPaymentTransfer->setMac( |
49
|
|
|
$this->computopApiService->generateEncryptedMac( |
50
|
|
|
$this->createRequestTransfer($computopPaymentTransfer) |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$decryptedValues = $this->computopApiService->getEncryptedArray( |
55
|
|
|
$this->getDataSubArray($computopPaymentTransfer), |
56
|
|
|
$this->config->getBlowfishPassword() |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$computopPaymentTransfer->setData($decryptedValues[ComputopApiConfig::DATA]); |
60
|
|
|
$computopPaymentTransfer->setLen($decryptedValues[ComputopApiConfig::LENGTH]); |
61
|
|
|
$computopPaymentTransfer->setUrl($this->config->getPayNowInitActionUrl()); |
62
|
|
|
|
63
|
|
|
return $computopPaymentTransfer; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
68
|
|
|
* |
69
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
70
|
|
|
*/ |
71
|
|
|
protected function createTransferWithUnencryptedValues(QuoteTransfer $quoteTransfer) |
72
|
|
|
{ |
73
|
|
|
$computopPaymentTransfer = new ComputopPayNowPaymentTransfer(); |
74
|
|
|
|
75
|
|
|
$computopPaymentTransfer->setCapture( |
76
|
|
|
$this->getCaptureType(ComputopSharedConfig::PAYMENT_METHOD_PAY_NOW) |
77
|
|
|
); |
78
|
|
|
$computopPaymentTransfer->setTransId($this->generateTransId($quoteTransfer)); |
79
|
|
|
$computopPaymentTransfer->setTxType($this->config->getPayNowTxType()); |
80
|
|
|
$computopPaymentTransfer->setUrlSuccess( |
81
|
|
|
$this->router->generate(ComputopRouteProviderPlugin::PAY_NOW_SUCCESS, [], Router::ABSOLUTE_URL) |
82
|
|
|
); |
83
|
|
|
$computopPaymentTransfer->setOrderDesc( |
84
|
|
|
$this->computopApiService->getDescriptionValue($quoteTransfer->getItems()->getArrayCopy()) |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithShipToCustomer($computopPaymentTransfer, $quoteTransfer); |
88
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithBillToCustomer($computopPaymentTransfer, $quoteTransfer); |
89
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithShippingAddress($computopPaymentTransfer, $quoteTransfer); |
90
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithBillingAddress($computopPaymentTransfer, $quoteTransfer); |
91
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithCredentialOnFile($computopPaymentTransfer); |
92
|
|
|
$computopPaymentTransfer = $this->expandPayNowPaymentWithBrowserInfo($computopPaymentTransfer); |
93
|
|
|
|
94
|
|
|
return $computopPaymentTransfer; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
99
|
|
|
* |
100
|
|
|
* @return array |
101
|
|
|
*/ |
102
|
|
|
protected function getDataSubArray(ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer) |
103
|
|
|
{ |
104
|
|
|
$dataSubArray[ComputopApiConfig::TRANS_ID] = $computopPayNowPaymentTransfer->getTransId(); |
|
|
|
|
105
|
|
|
$dataSubArray[ComputopApiConfig::AMOUNT] = $computopPayNowPaymentTransfer->getAmount(); |
106
|
|
|
$dataSubArray[ComputopApiConfig::CURRENCY] = $computopPayNowPaymentTransfer->getCurrency(); |
107
|
|
|
$dataSubArray[ComputopApiConfig::URL_SUCCESS] = $computopPayNowPaymentTransfer->getUrlSuccess(); |
108
|
|
|
$dataSubArray[ComputopApiConfig::URL_NOTIFY] = $computopPayNowPaymentTransfer->getUrlNotify(); |
109
|
|
|
$dataSubArray[ComputopApiConfig::URL_FAILURE] = $computopPayNowPaymentTransfer->getUrlFailure(); |
110
|
|
|
$dataSubArray[ComputopApiConfig::CAPTURE] = $computopPayNowPaymentTransfer->getCapture(); |
111
|
|
|
$dataSubArray[ComputopApiConfig::RESPONSE] = $computopPayNowPaymentTransfer->getResponse(); |
112
|
|
|
$dataSubArray[ComputopApiConfig::MAC] = $computopPayNowPaymentTransfer->getMac(); |
113
|
|
|
$dataSubArray[ComputopApiConfig::TX_TYPE] = $computopPayNowPaymentTransfer->getTxType(); |
114
|
|
|
$dataSubArray[ComputopApiConfig::ORDER_DESC] = $computopPayNowPaymentTransfer->getOrderDesc(); |
115
|
|
|
$dataSubArray[ComputopApiConfig::ETI_ID] = $this->config->getEtiId(); |
116
|
|
|
$dataSubArray[ComputopApiConfig::IP_ADDRESS] = $computopPayNowPaymentTransfer->getClientIp(); |
117
|
|
|
$dataSubArray[ComputopApiConfig::SHIPPING_ZIP] = $computopPayNowPaymentTransfer->getShippingZip(); |
118
|
|
|
|
119
|
|
|
$dataSubArray[ComputopApiConfig::MSG_VER] = ComputopApiConfig::PSD2_MSG_VERSION; |
120
|
|
|
$dataSubArray[ComputopApiConfig::BILL_TO_CUSTOMER] = $this->encodeRequestParameterData( |
121
|
|
|
$computopPayNowPaymentTransfer->getBillToCustomer()->toArray(true, true) |
122
|
|
|
); |
123
|
|
|
$dataSubArray[ComputopApiConfig::SHIP_TO_CUSTOMER] = $this->encodeRequestParameterData( |
124
|
|
|
$computopPayNowPaymentTransfer->getShipToCustomer()->toArray(true, true) |
125
|
|
|
); |
126
|
|
|
$dataSubArray[ComputopApiConfig::BILLING_ADDRESS] = $this->encodeRequestParameterData( |
127
|
|
|
$computopPayNowPaymentTransfer->getBillingAddress()->toArray(true, true) |
128
|
|
|
); |
129
|
|
|
$dataSubArray[ComputopApiConfig::SHIPPING_ADDRESS] = $this->encodeRequestParameterData( |
130
|
|
|
$computopPayNowPaymentTransfer->getShippingAddress()->toArray(true, true) |
131
|
|
|
); |
132
|
|
|
$dataSubArray[ComputopApiConfig::CREDENTIAL_ON_FILE] = $this->encodeRequestParameterData( |
133
|
|
|
$computopPayNowPaymentTransfer->getCredentialOnFile()->toArray(true, true) |
134
|
|
|
); |
135
|
|
|
$dataSubArray[ComputopApiConfig::BROWSER_INFO] = $this->encodeRequestParameterData( |
136
|
|
|
$computopPayNowPaymentTransfer->getBrowserInfo()->toArray(true, true) |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
return $dataSubArray; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
144
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
145
|
|
|
* |
146
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
147
|
|
|
*/ |
148
|
|
|
protected function expandPayNowPaymentWithShipToCustomer( |
149
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer, |
150
|
|
|
QuoteTransfer $quoteTransfer |
151
|
|
|
): ComputopPayNowPaymentTransfer { |
152
|
|
|
$computopCustomerInfoTransfer = (new ComputopCustomerInfoTransfer()) |
153
|
|
|
->setConsumer( |
154
|
|
|
(new ComputopConsumerTransfer()) |
155
|
|
|
->setFirstName($quoteTransfer->getShippingAddress()->getFirstName()) |
156
|
|
|
->setLastName($quoteTransfer->getShippingAddress()->getLastName()) |
157
|
|
|
->setSalutation($quoteTransfer->getShippingAddress()->getSalutation()) |
158
|
|
|
) |
159
|
|
|
->setEmail($quoteTransfer->getCustomer()->getEmail()); |
160
|
|
|
|
161
|
|
|
$computopPayNowPaymentTransfer->setShipToCustomer($computopCustomerInfoTransfer); |
162
|
|
|
|
163
|
|
|
return $computopPayNowPaymentTransfer; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
168
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
169
|
|
|
* |
170
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
171
|
|
|
*/ |
172
|
|
|
protected function expandPayNowPaymentWithBillToCustomer( |
173
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer, |
174
|
|
|
QuoteTransfer $quoteTransfer |
175
|
|
|
): ComputopPayNowPaymentTransfer { |
176
|
|
|
if ($quoteTransfer->getBillingSameAsShipping()) { |
177
|
|
|
$computopPayNowPaymentTransfer->setBillToCustomer( |
178
|
|
|
$computopPayNowPaymentTransfer->getShipToCustomer() |
179
|
|
|
); |
180
|
|
|
|
181
|
|
|
return $computopPayNowPaymentTransfer; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
$computopCustomerInfoTransfer = (new ComputopCustomerInfoTransfer()) |
185
|
|
|
->setConsumer( |
186
|
|
|
(new ComputopConsumerTransfer()) |
187
|
|
|
->setFirstName($quoteTransfer->getBillingAddress()->getFirstName()) |
188
|
|
|
->setLastName($quoteTransfer->getBillingAddress()->getLastName()) |
189
|
|
|
->setSalutation($quoteTransfer->getBillingAddress()->getSalutation()) |
190
|
|
|
) |
191
|
|
|
->setEmail($quoteTransfer->getCustomer()->getEmail()); |
192
|
|
|
|
193
|
|
|
$computopPayNowPaymentTransfer->setBillToCustomer($computopCustomerInfoTransfer); |
194
|
|
|
|
195
|
|
|
return $computopPayNowPaymentTransfer; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
200
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
201
|
|
|
* |
202
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
203
|
|
|
*/ |
204
|
|
|
protected function expandPayNowPaymentWithShippingAddress( |
205
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer, |
206
|
|
|
QuoteTransfer $quoteTransfer |
207
|
|
|
): ComputopPayNowPaymentTransfer { |
208
|
|
|
$countryCollectionTransfer = (new CountryCollectionTransfer()) |
209
|
|
|
->addCountries( |
210
|
|
|
(new CountryTransfer())->setIso2Code($quoteTransfer->getShippingAddress()->getIso2Code()) |
211
|
|
|
); |
212
|
|
|
$countryCollectionTransfer = $this->countryClient->findCountriesByIso2Codes($countryCollectionTransfer); |
213
|
|
|
|
214
|
|
|
$computopAddressTransfer = (new ComputopAddressTransfer()) |
215
|
|
|
->setCity($quoteTransfer->getShippingAddress()->getCity()) |
216
|
|
|
->setCountry( |
217
|
|
|
(new ComputopCountryTransfer()) |
218
|
|
|
->setCountryA3($countryCollectionTransfer->getCountries()->offsetGet(0)->getIso3Code()) |
219
|
|
|
) |
220
|
|
|
->setAddressLine1( |
221
|
|
|
(new ComputopAddressLineTransfer()) |
222
|
|
|
->setStreet($quoteTransfer->getShippingAddress()->getAddress1()) |
223
|
|
|
->setStreetNumber($quoteTransfer->getShippingAddress()->getAddress2()) |
224
|
|
|
) |
225
|
|
|
->setPostalCode($quoteTransfer->getShippingAddress()->getZipCode()); |
226
|
|
|
|
227
|
|
|
$computopPayNowPaymentTransfer->setShippingAddress($computopAddressTransfer); |
228
|
|
|
|
229
|
|
|
return $computopPayNowPaymentTransfer; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
234
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
235
|
|
|
* |
236
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
237
|
|
|
*/ |
238
|
|
|
protected function expandPayNowPaymentWithBillingAddress( |
239
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer, |
240
|
|
|
QuoteTransfer $quoteTransfer |
241
|
|
|
): ComputopPayNowPaymentTransfer { |
242
|
|
|
if ($quoteTransfer->getBillingSameAsShipping()) { |
243
|
|
|
$computopPayNowPaymentTransfer->setBillingAddress( |
244
|
|
|
$computopPayNowPaymentTransfer->getShippingAddress() |
245
|
|
|
); |
246
|
|
|
|
247
|
|
|
return $computopPayNowPaymentTransfer; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
$countryCollectionTransfer = (new CountryCollectionTransfer()) |
251
|
|
|
->addCountries( |
252
|
|
|
(new CountryTransfer())->setIso2Code($quoteTransfer->getBillingAddress()->getIso2Code()) |
253
|
|
|
); |
254
|
|
|
$countryCollectionTransfer = $this->countryClient->findCountriesByIso2Codes($countryCollectionTransfer); |
255
|
|
|
|
256
|
|
|
$computopAddressTransfer = (new ComputopAddressTransfer()) |
257
|
|
|
->setCity($quoteTransfer->getBillingAddress()->getCity()) |
258
|
|
|
->setCountry( |
259
|
|
|
(new ComputopCountryTransfer()) |
260
|
|
|
->setCountryA3($countryCollectionTransfer->getCountries()->offsetGet(0)->getIso3Code()) |
261
|
|
|
) |
262
|
|
|
->setAddressLine1( |
263
|
|
|
(new ComputopAddressLineTransfer()) |
264
|
|
|
->setStreet($quoteTransfer->getBillingAddress()->getAddress1()) |
265
|
|
|
->setStreetNumber($quoteTransfer->getBillingAddress()->getAddress2()) |
266
|
|
|
) |
267
|
|
|
->setPostalCode($quoteTransfer->getBillingAddress()->getZipCode()); |
268
|
|
|
|
269
|
|
|
$computopPayNowPaymentTransfer->setBillingAddress($computopAddressTransfer); |
270
|
|
|
|
271
|
|
|
return $computopPayNowPaymentTransfer; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
276
|
|
|
* |
277
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
278
|
|
|
*/ |
279
|
|
|
protected function expandPayNowPaymentWithCredentialOnFile( |
280
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
281
|
|
|
): ComputopPayNowPaymentTransfer { |
282
|
|
|
$computopCredentialOnFileTransfer = (new ComputopCredentialOnFileTransfer()) |
283
|
|
|
->setType( |
284
|
|
|
(new ComputopCredentialOnFileTypeTransfer()) |
285
|
|
|
->setUnscheduled(ComputopApiConfig::UNSCHEDULED_CUSTOMER_INITIATED_TRANSACTION) |
286
|
|
|
) |
287
|
|
|
->setInitialPayment(true); |
288
|
|
|
|
289
|
|
|
$computopPayNowPaymentTransfer->setCredentialOnFile($computopCredentialOnFileTransfer); |
290
|
|
|
|
291
|
|
|
return $computopPayNowPaymentTransfer; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
296
|
|
|
* |
297
|
|
|
* @return \Generated\Shared\Transfer\ComputopPayNowPaymentTransfer |
298
|
|
|
*/ |
299
|
|
|
protected function expandPayNowPaymentWithBrowserInfo( |
300
|
|
|
ComputopPayNowPaymentTransfer $computopPayNowPaymentTransfer |
301
|
|
|
): ComputopPayNowPaymentTransfer { |
302
|
|
|
$computopBrowserInfoTransfer = (new ComputopBrowserInfoTransfer()) |
303
|
|
|
->setAcceptHeaders($this->request->headers->get(static::HEADER_ACCEPT)) |
304
|
|
|
->setIpAddress($this->request->getClientIp()) |
305
|
|
|
->setUserAgent($this->request->headers->get(static::HEADER_USER_AGENT)) |
306
|
|
|
->setJavaEnabled(static::IFRAME_IS_JAVA_ENABLED) |
307
|
|
|
->setJavaScriptEnabled(static::IFRAME_IS_JAVA_SCRIPT_ENABLED) |
308
|
|
|
->setColorDepth(static::IFRAME_COLOR_DEPTH) |
309
|
|
|
->setScreenHeight(static::IFRAME_SCREEN_HEIGHT) |
310
|
|
|
->setScreenWidth(static::IFRAME_SCREEN_WIDTH) |
311
|
|
|
->setTimeZoneOffset(static::IFRAME_TIME_ZONE_OFFSET) |
312
|
|
|
->setLanguage(mb_strtoupper($this->store->getCurrentLanguage())); |
313
|
|
|
|
314
|
|
|
$computopPayNowPaymentTransfer->setBrowserInfo($computopBrowserInfoTransfer); |
315
|
|
|
|
316
|
|
|
return $computopPayNowPaymentTransfer; |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|
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