|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify |
|
5
|
|
|
* it under the terms of the GNU Lesser General Public License as published by |
|
6
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
7
|
|
|
* (at your option) any later version. |
|
8
|
|
|
* |
|
9
|
|
|
* PAYONE Magento 2 Connector is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU Lesser General Public License for more details. |
|
13
|
|
|
* |
|
14
|
|
|
* You should have received a copy of the GNU Lesser General Public License |
|
15
|
|
|
* along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>. |
|
16
|
|
|
* |
|
17
|
|
|
* PHP version 5 |
|
18
|
|
|
* |
|
19
|
|
|
* @category Payone |
|
20
|
|
|
* @package Payone_Magento2_Plugin |
|
21
|
|
|
* @author FATCHIP GmbH <[email protected]> |
|
22
|
|
|
* @copyright 2003 - 2018 Payone GmbH |
|
23
|
|
|
* @license <http://www.gnu.org/licenses/> GNU Lesser General Public License |
|
24
|
|
|
* @link http://www.payone.de |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
namespace Payone\Core\Controller\Amazon; |
|
28
|
|
|
|
|
29
|
|
|
use Magento\Framework\App\ResponseInterface; |
|
|
|
|
|
|
30
|
|
|
use Magento\Framework\Controller\Result\Json; |
|
|
|
|
|
|
31
|
|
|
use Payone\Core\Model\Exception\AuthorizationException; |
|
32
|
|
|
use Payone\Core\Model\PayoneConfig; |
|
33
|
|
|
use Magento\Quote\Model\Quote; |
|
|
|
|
|
|
34
|
|
|
use Magento\Checkout\Model\Type\Onepage; |
|
|
|
|
|
|
35
|
|
|
use Magento\Customer\Model\Group; |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* TransactionStatus receiver |
|
39
|
|
|
*/ |
|
40
|
|
|
class LoadReview extends \Magento\Framework\App\Action\Action |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* Result factory |
|
44
|
|
|
* |
|
45
|
|
|
* @var \Magento\Framework\Controller\Result\JsonFactory |
|
|
|
|
|
|
46
|
|
|
*/ |
|
47
|
|
|
protected $resultJsonFactory; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var \Magento\Framework\App\ViewInterface |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
|
|
protected $view; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @var \Payone\Core\Block\Onepage\Review |
|
56
|
|
|
*/ |
|
57
|
|
|
protected $reviewBlock; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Page result factory |
|
61
|
|
|
* |
|
62
|
|
|
* @var \Magento\Framework\View\Result\PageFactory |
|
|
|
|
|
|
63
|
|
|
*/ |
|
64
|
|
|
protected $pageFactory; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Checkout session |
|
68
|
|
|
* |
|
69
|
|
|
* @var \Magento\Checkout\Model\Session |
|
|
|
|
|
|
70
|
|
|
*/ |
|
71
|
|
|
protected $checkoutSession; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var \Magento\Checkout\Model\Cart |
|
|
|
|
|
|
75
|
|
|
*/ |
|
76
|
|
|
protected $cart; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var \Magento\Quote\Api\CartRepositoryInterface |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
protected $quoteRepository; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Coupon factory |
|
85
|
|
|
* |
|
86
|
|
|
* @var \Magento\SalesRule\Model\CouponFactory |
|
|
|
|
|
|
87
|
|
|
*/ |
|
88
|
|
|
protected $couponFactory; |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Object of getconfiguration request |
|
92
|
|
|
* |
|
93
|
|
|
* @var \Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration |
|
94
|
|
|
*/ |
|
95
|
|
|
protected $getConfiguration; |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Object of getorderreferencedetails request |
|
99
|
|
|
* |
|
100
|
|
|
* @var \Payone\Core\Model\Api\Request\Genericpayment\GetOrderReferenceDetails |
|
101
|
|
|
*/ |
|
102
|
|
|
protected $getOrderReferenceDetails; |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Object of setorderreferencedetails request |
|
106
|
|
|
* |
|
107
|
|
|
* @var \Payone\Core\Model\Api\Request\Genericpayment\SetOrderReferenceDetails |
|
108
|
|
|
*/ |
|
109
|
|
|
protected $setOrderReferenceDetails; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Amazon Pay payment object |
|
113
|
|
|
* |
|
114
|
|
|
* @var \Payone\Core\Model\Methods\AmazonPay |
|
115
|
|
|
*/ |
|
116
|
|
|
protected $payment; |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* PAYONE order helper |
|
120
|
|
|
* |
|
121
|
|
|
* @var \Payone\Core\Helper\Order |
|
122
|
|
|
*/ |
|
123
|
|
|
protected $orderHelper; |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* PAYONE order helper |
|
127
|
|
|
* |
|
128
|
|
|
* @var \Payone\Core\Helper\Checkout |
|
129
|
|
|
*/ |
|
130
|
|
|
protected $checkoutHelper; |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* Cart management interface |
|
134
|
|
|
* |
|
135
|
|
|
* @var \Magento\Quote\Api\CartManagementInterface |
|
|
|
|
|
|
136
|
|
|
*/ |
|
137
|
|
|
protected $cartManagement; |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Existing Payone error codes mapped to their Amazon error codes |
|
141
|
|
|
* |
|
142
|
|
|
* @var array |
|
143
|
|
|
*/ |
|
144
|
|
|
protected $amazonErrors = [ |
|
145
|
|
|
109 => 'AmazonRejected', |
|
146
|
|
|
900 => 'UnspecifiedError', |
|
147
|
|
|
980 => 'TransactionTimedOut', |
|
148
|
|
|
981 => 'InvalidPaymentMethod', |
|
149
|
|
|
982 => 'AmazonRejected', |
|
150
|
|
|
983 => 'ProcessingFailure', |
|
151
|
|
|
984 => 'BuyerEqualsSeller', |
|
152
|
|
|
985 => 'PaymentMethodNotAllowed', |
|
153
|
|
|
986 => 'PaymentPlanNotSet', |
|
154
|
|
|
987 => 'ShippingAddressNotSet' |
|
155
|
|
|
]; |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Constructor |
|
159
|
|
|
* |
|
160
|
|
|
* @param \Magento\Framework\App\Action\Context $context |
|
161
|
|
|
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory |
|
162
|
|
|
* @param \Payone\Core\Block\Onepage\Review $reviewBlock |
|
163
|
|
|
* @param \Magento\Framework\App\ViewInterface $view |
|
164
|
|
|
* @param \Magento\Framework\View\Result\PageFactory $pageFactory |
|
165
|
|
|
* @param \Magento\Checkout\Model\Session $checkoutSession |
|
166
|
|
|
* @param \Magento\Checkout\Model\Cart $cart |
|
167
|
|
|
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository |
|
168
|
|
|
* @param \Magento\SalesRule\Model\CouponFactory $couponFactory |
|
169
|
|
|
* @param \Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration $getConfiguration, |
|
170
|
|
|
* @param \Payone\Core\Model\Api\Request\Genericpayment\GetOrderReferenceDetails $getOrderReferenceDetails, |
|
171
|
|
|
* @param \Payone\Core\Model\Api\Request\Genericpayment\SetOrderReferenceDetails $setOrderReferenceDetails |
|
172
|
|
|
* @param \Payone\Core\Model\Methods\AmazonPay $payment |
|
173
|
|
|
* @param \Payone\Core\Helper\Order $orderHelper |
|
174
|
|
|
* @param \Payone\Core\Helper\Checkout $checkoutHelper |
|
175
|
|
|
* @param \Magento\Quote\Api\CartManagementInterface $cartManagement |
|
176
|
|
|
*/ |
|
177
|
|
|
public function __construct( |
|
178
|
|
|
\Magento\Framework\App\Action\Context $context, |
|
|
|
|
|
|
179
|
|
|
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, |
|
180
|
|
|
\Payone\Core\Block\Onepage\Review $reviewBlock, |
|
181
|
|
|
\Magento\Framework\App\ViewInterface $view, |
|
182
|
|
|
\Magento\Framework\View\Result\PageFactory $pageFactory, |
|
183
|
|
|
\Magento\Checkout\Model\Session $checkoutSession, |
|
184
|
|
|
\Magento\Checkout\Model\Cart $cart, |
|
185
|
|
|
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository, |
|
186
|
|
|
\Magento\SalesRule\Model\CouponFactory $couponFactory, |
|
187
|
|
|
\Payone\Core\Model\Api\Request\Genericpayment\GetConfiguration $getConfiguration, |
|
188
|
|
|
\Payone\Core\Model\Api\Request\Genericpayment\GetOrderReferenceDetails $getOrderReferenceDetails, |
|
189
|
|
|
\Payone\Core\Model\Api\Request\Genericpayment\SetOrderReferenceDetails $setOrderReferenceDetails, |
|
190
|
|
|
\Payone\Core\Model\Methods\AmazonPay $payment, |
|
191
|
|
|
\Payone\Core\Helper\Order $orderHelper, |
|
192
|
|
|
\Payone\Core\Helper\Checkout $checkoutHelper, |
|
193
|
|
|
\Magento\Quote\Api\CartManagementInterface $cartManagement |
|
194
|
|
|
) { |
|
195
|
|
|
parent::__construct($context); |
|
196
|
|
|
$this->resultJsonFactory = $resultJsonFactory; |
|
197
|
|
|
$this->view = $view; |
|
198
|
|
|
$this->reviewBlock = $reviewBlock; |
|
199
|
|
|
$this->pageFactory = $pageFactory; |
|
200
|
|
|
$this->checkoutSession = $checkoutSession; |
|
201
|
|
|
$this->cart = $cart; |
|
202
|
|
|
$this->quoteRepository = $quoteRepository; |
|
203
|
|
|
$this->couponFactory = $couponFactory; |
|
204
|
|
|
$this->getConfiguration = $getConfiguration; |
|
205
|
|
|
$this->getOrderReferenceDetails = $getOrderReferenceDetails; |
|
206
|
|
|
$this->setOrderReferenceDetails = $setOrderReferenceDetails; |
|
207
|
|
|
$this->payment = $payment; |
|
208
|
|
|
$this->orderHelper = $orderHelper; |
|
209
|
|
|
$this->checkoutHelper = $checkoutHelper; |
|
210
|
|
|
$this->cartManagement = $cartManagement; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
/** |
|
214
|
|
|
* Executing TransactionStatus handling |
|
215
|
|
|
* |
|
216
|
|
|
* @return Json|ResponseInterface |
|
217
|
|
|
*/ |
|
218
|
|
|
public function execute() |
|
219
|
|
|
{ |
|
220
|
|
|
$aReturnData = []; |
|
221
|
|
|
|
|
222
|
|
|
$blSuccess = false; |
|
223
|
|
|
|
|
224
|
|
|
$sAction = $this->getRequest()->getParam('action'); |
|
225
|
|
|
switch ($sAction) { |
|
226
|
|
|
case 'confirmSelection': |
|
227
|
|
|
$aReturnData = $this->confirmSelection($aReturnData); |
|
228
|
|
|
if (!empty($aReturnData['workorderId'])) { |
|
229
|
|
|
$blSuccess = true; |
|
230
|
|
|
} |
|
231
|
|
|
break; |
|
232
|
|
|
case 'placeOrder': |
|
233
|
|
|
$aReturnData = $this->placeOrder($aReturnData); |
|
234
|
|
|
if (!empty($aReturnData['successUrl'])) { |
|
235
|
|
|
$blSuccess = true; |
|
236
|
|
|
} |
|
237
|
|
|
break; |
|
238
|
|
|
case 'updateShipping': |
|
239
|
|
|
$blSuccess = $this->updateShippingMethod($this->getRequest()->getParam('shippingMethod')); |
|
240
|
|
|
break; |
|
241
|
|
|
case 'updateCoupon': |
|
242
|
|
|
$blSuccess = $this->handleCouponRequest(); |
|
243
|
|
|
break; |
|
244
|
|
|
case 'cancelToBasket': |
|
245
|
|
|
$this->messageManager->addErrorMessage(__('Sorry, your transaction with Amazon Pay was not successful. Please choose another payment method.')); |
|
|
|
|
|
|
246
|
|
|
return $this->_redirect('checkout/cart'); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
if ($sAction != 'placeOrder' || empty($aReturnData['successUrl'])) { |
|
250
|
|
|
$oPageReturn = $this->pageFactory->create(false, ['template' => 'Payone_Core::blank.phtml']); |
|
251
|
|
|
|
|
252
|
|
|
$aReturnData['html'] = $oPageReturn->getLayout()->getOutput(); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
$aReturnData['success'] = $blSuccess; |
|
256
|
|
|
|
|
257
|
|
|
$resultJson = $this->resultJsonFactory->create(); |
|
258
|
|
|
return $resultJson->setData($aReturnData); |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
/** |
|
262
|
|
|
* Get Amazon workorder_id from session or request |
|
263
|
|
|
* |
|
264
|
|
|
* @return string |
|
265
|
|
|
*/ |
|
266
|
|
|
protected function collectWorkorderId() |
|
267
|
|
|
{ |
|
268
|
|
|
$sWorkorderId = $this->checkoutSession->getAmazonWorkorderId(); |
|
269
|
|
|
if (empty($sWorkorderId)) { |
|
270
|
|
|
$aResult = $this->getConfiguration->sendRequest($this->payment); |
|
271
|
|
|
if (isset($aResult['status']) && $aResult['status'] == 'OK' && isset($aResult['workorderid'])) { |
|
272
|
|
|
$sWorkorderId = $aResult['workorderid']; |
|
273
|
|
|
$this->checkoutSession->setAmazonWorkorderId($aResult['workorderid']); |
|
274
|
|
|
} |
|
275
|
|
|
} |
|
276
|
|
|
return $sWorkorderId; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Update shipping method |
|
281
|
|
|
* |
|
282
|
|
|
* @param string $sShippingMethod |
|
283
|
|
|
* @return bool |
|
284
|
|
|
*/ |
|
285
|
|
|
protected function updateShippingMethod($sShippingMethod) |
|
286
|
|
|
{ |
|
287
|
|
|
$oQuote = $this->checkoutSession->getQuote(); |
|
288
|
|
|
$oShippingAddress = $oQuote->getShippingAddress(); |
|
289
|
|
|
if (!$oQuote->getIsVirtual() && $oShippingAddress) { |
|
290
|
|
|
if ($sShippingMethod != $oShippingAddress->getShippingMethod()) { |
|
291
|
|
|
$this->ignoreAddressValidation($oQuote); |
|
292
|
|
|
$oShippingAddress->setShippingMethod($sShippingMethod)->setCollectShippingRates(true); |
|
293
|
|
|
$cartExtension = $oQuote->getExtensionAttributes(); |
|
294
|
|
|
if ($cartExtension && $cartExtension->getShippingAssignments()) { |
|
295
|
|
|
$cartExtension->getShippingAssignments()[0]->getShipping()->setMethod($sShippingMethod); |
|
296
|
|
|
} |
|
297
|
|
|
$oQuote->collectTotals(); |
|
298
|
|
|
$this->quoteRepository->save($oQuote); |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
return true; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Disable validation to make sure addresses will always be saved |
|
306
|
|
|
* |
|
307
|
|
|
* @param Quote $oQuote |
|
308
|
|
|
* @return void |
|
309
|
|
|
*/ |
|
310
|
|
|
protected function ignoreAddressValidation(Quote $oQuote) |
|
311
|
|
|
{ |
|
312
|
|
|
$oQuote->getBillingAddress()->setShouldIgnoreValidation(true); |
|
313
|
|
|
if (!$oQuote->getIsVirtual()) { |
|
314
|
|
|
$oQuote->getShippingAddress()->setShouldIgnoreValidation(true); |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
/** |
|
319
|
|
|
* Handle coupon management |
|
320
|
|
|
* |
|
321
|
|
|
* @return bool |
|
322
|
|
|
*/ |
|
323
|
|
|
protected function handleCouponRequest() |
|
324
|
|
|
{ |
|
325
|
|
|
$couponCode = ''; |
|
326
|
|
|
if ($this->getRequest()->getParam('remove') != 1) { |
|
327
|
|
|
$couponCode = trim($this->getRequest()->getParam('couponCode')); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
$cartQuote = $this->checkoutSession->getQuote(); |
|
331
|
|
|
$oldCouponCode = $cartQuote->getCouponCode(); |
|
332
|
|
|
|
|
333
|
|
|
$codeLength = strlen($couponCode); |
|
334
|
|
|
if (!$codeLength && !strlen($oldCouponCode)) { |
|
335
|
|
|
return true; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
try { |
|
339
|
|
|
$isCodeLengthValid = $codeLength && $codeLength <= \Magento\Checkout\Helper\Cart::COUPON_CODE_MAX_LENGTH; |
|
|
|
|
|
|
340
|
|
|
|
|
341
|
|
|
$itemsCount = $cartQuote->getItemsCount(); |
|
342
|
|
|
if ($itemsCount) { |
|
343
|
|
|
$cartQuote->getShippingAddress()->setCollectShippingRates(true); |
|
344
|
|
|
$cartQuote->setCouponCode($isCodeLengthValid ? $couponCode : '')->collectTotals(); |
|
345
|
|
|
$this->quoteRepository->save($cartQuote); |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
if ($codeLength) { |
|
349
|
|
|
#$escaper = $this->_objectManager->get('Magento\Framework\Escaper'); |
|
|
|
|
|
|
350
|
|
|
if (!$itemsCount) { |
|
351
|
|
|
if ($isCodeLengthValid) { |
|
352
|
|
|
$coupon = $this->couponFactory->create(); |
|
353
|
|
|
$coupon->load($couponCode, 'code'); |
|
354
|
|
|
if ($coupon->getId()) { |
|
355
|
|
|
$this->checkoutSession->getQuote()->setCouponCode($couponCode)->save(); |
|
356
|
|
|
//$this->messageManager->addSuccess(__('You used coupon code "%1".', $escaper->escapeHtml($couponCode))); |
|
|
|
|
|
|
357
|
|
|
} else { |
|
|
|
|
|
|
358
|
|
|
//$this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode))); |
|
|
|
|
|
|
359
|
|
|
} |
|
360
|
|
|
} else { |
|
|
|
|
|
|
361
|
|
|
//$this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode))); |
|
|
|
|
|
|
362
|
|
|
} |
|
363
|
|
|
} else { |
|
364
|
|
|
if ($isCodeLengthValid && $couponCode == $cartQuote->getCouponCode()) { |
|
|
|
|
|
|
365
|
|
|
//$this->messageManager->addSuccess(__('You used coupon code "%1".', $escaper->escapeHtml($couponCode))); |
|
|
|
|
|
|
366
|
|
|
} else { |
|
367
|
|
|
//$this->messageManager->addError(__('The coupon code "%1" is not valid.', $escaper->escapeHtml($couponCode))); |
|
|
|
|
|
|
368
|
|
|
$this->cart->save(); |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} else { |
|
|
|
|
|
|
372
|
|
|
//$this->messageManager->addSuccess(__('You canceled the coupon code.')); |
|
|
|
|
|
|
373
|
|
|
} |
|
374
|
|
|
} catch (\Magento\Framework\Exception\LocalizedException $e) { |
|
|
|
|
|
|
375
|
|
|
$this->messageManager->addError($e->getMessage()); |
|
376
|
|
|
} catch (\Exception $e) { |
|
377
|
|
|
//$this->messageManager->addError(__('We cannot apply the coupon code.')); |
|
|
|
|
|
|
378
|
|
|
//$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e); |
|
|
|
|
|
|
379
|
|
|
} |
|
380
|
|
|
return true; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
/** |
|
384
|
|
|
* confirmSelection action |
|
385
|
|
|
* Executes getorderreference details |
|
386
|
|
|
* |
|
387
|
|
|
* @param array $aReturnData |
|
388
|
|
|
* @return array |
|
389
|
|
|
*/ |
|
390
|
|
|
protected function confirmSelection($aReturnData) |
|
391
|
|
|
{ |
|
392
|
|
|
$sWorkorderId = $this->collectWorkorderId(); |
|
393
|
|
|
if (!empty($sWorkorderId)) { |
|
394
|
|
|
$amazonReferenceId = $this->getRequest()->getParam('amazonReferenceId'); |
|
395
|
|
|
$amazonAddressToken = $this->getRequest()->getParam('amazonAddressToken'); |
|
396
|
|
|
|
|
397
|
|
|
$aResult = $this->getOrderReferenceDetails->sendRequest($this->payment, $sWorkorderId, $amazonReferenceId, $amazonAddressToken); |
|
398
|
|
|
if (isset($aResult['status']) && $aResult['status'] == 'OK') { |
|
399
|
|
|
$this->checkoutSession->setAmazonAddressToken($amazonAddressToken); |
|
400
|
|
|
$this->checkoutSession->setAmazonReferenceId($amazonReferenceId); |
|
401
|
|
|
|
|
402
|
|
|
$oQuote = $this->checkoutSession->getQuote(); |
|
403
|
|
|
$oQuote = $this->orderHelper->updateAddresses($oQuote, $aResult); |
|
404
|
|
|
|
|
405
|
|
|
$oPayment = $oQuote->getPayment(); |
|
406
|
|
|
$oPayment->setMethod(PayoneConfig::METHOD_AMAZONPAY); |
|
407
|
|
|
|
|
408
|
|
|
$oQuote->collectTotals()->save(); |
|
409
|
|
|
} |
|
410
|
|
|
} |
|
411
|
|
|
$aReturnData['workorderId'] = $sWorkorderId; |
|
412
|
|
|
|
|
413
|
|
|
return $aReturnData; |
|
414
|
|
|
} |
|
415
|
|
|
|
|
416
|
|
|
/** |
|
417
|
|
|
* Return error identifier for given error code |
|
418
|
|
|
* |
|
419
|
|
|
* @param int $iErrorCode |
|
420
|
|
|
* @return string |
|
421
|
|
|
*/ |
|
422
|
|
|
protected function getErrorIdentifier($iErrorCode) |
|
423
|
|
|
{ |
|
424
|
|
|
$sIdentifier = 'UnknownError'; |
|
425
|
|
|
if (isset($this->amazonErrors[$iErrorCode])) { |
|
426
|
|
|
$sIdentifier = $this->amazonErrors[$iErrorCode]; |
|
427
|
|
|
} |
|
428
|
|
|
return $sIdentifier; |
|
429
|
|
|
} |
|
430
|
|
|
|
|
431
|
|
|
/** |
|
432
|
|
|
* placeOrder action |
|
433
|
|
|
* Generates the order |
|
434
|
|
|
* |
|
435
|
|
|
* @param array $aReturnData |
|
436
|
|
|
* @return array |
|
437
|
|
|
*/ |
|
438
|
|
|
protected function placeOrder($aReturnData) |
|
439
|
|
|
{ |
|
440
|
|
|
$oQuote = $this->checkoutSession->getQuote(); |
|
441
|
|
|
|
|
442
|
|
|
$sWorkorderId = $this->checkoutSession->getAmazonWorkorderId(); |
|
443
|
|
|
$amazonReferenceId = $this->checkoutSession->getAmazonReferenceId(); |
|
444
|
|
|
$amazonAddressToken = $this->checkoutSession->getAmazonAddressToken(); |
|
445
|
|
|
$blSetOrderReferenceDetailsExecuted = $this->checkoutSession->getOrderReferenceDetailsExecuted(); |
|
446
|
|
|
|
|
447
|
|
|
if (!$blSetOrderReferenceDetailsExecuted) { |
|
448
|
|
|
$aResult = $this->setOrderReferenceDetails->sendRequest($this->payment, $oQuote->getGrandTotal(), $sWorkorderId, $amazonReferenceId, $amazonAddressToken); |
|
449
|
|
|
if (!isset($aResult['status']) || $aResult['status'] != 'OK') { |
|
450
|
|
|
return $aReturnData; |
|
451
|
|
|
} |
|
452
|
|
|
} |
|
453
|
|
|
|
|
454
|
|
|
$this->checkoutSession->setOrderReferenceDetailsExecuted(true); |
|
455
|
|
|
try { |
|
456
|
|
|
if ($this->checkoutHelper->getCurrentCheckoutMethod($oQuote) == Onepage::METHOD_GUEST) { |
|
457
|
|
|
$oQuote->setCustomerId(null) |
|
458
|
|
|
->setCustomerEmail($oQuote->getBillingAddress()->getEmail()) |
|
459
|
|
|
->setCustomerIsGuest(true) |
|
460
|
|
|
->setCustomerGroupId(Group::NOT_LOGGED_IN_ID); |
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
#$oQuote->setPayment($oPayment); |
|
|
|
|
|
|
464
|
|
|
$oQuote->setInventoryProcessed(false); |
|
465
|
|
|
$oQuote->getBillingAddress()->setShouldIgnoreValidation(true); |
|
466
|
|
|
$oQuote->getShippingAddress()->setShouldIgnoreValidation(true); |
|
467
|
|
|
$oQuote->collectTotals()->save(); |
|
468
|
|
|
$this->cartManagement->placeOrder($oQuote->getId()); |
|
469
|
|
|
$oQuote->setIsActive(false)->save(); |
|
470
|
|
|
|
|
471
|
|
|
$this->unsetSessionVariables(); |
|
472
|
|
|
|
|
473
|
|
|
$aReturnData['successUrl'] = $this->_url->getUrl('checkout/onepage/success/'); |
|
474
|
|
|
} catch (AuthorizationException $e) { |
|
475
|
|
|
$aResponse = $e->getResponse(); |
|
476
|
|
|
$aReturnData['errorMessage'] = $this->getErrorIdentifier($aResponse['errorcode']); |
|
477
|
|
|
if (isset($aResponse['status']) && $aResponse['status'] == 'ERROR' && in_array($aResponse['errorcode'], [980, 982])) { |
|
478
|
|
|
$aReturnData['errorUrl'] = $this->_url->getUrl('payone/amazon/loadReview', ['action' => 'cancelToBasket']); |
|
479
|
|
|
$this->unsetSessionVariables(); |
|
480
|
|
|
} |
|
481
|
|
|
} catch (\Exception $e) { |
|
482
|
|
|
//error_log($e->getMessage()); |
|
|
|
|
|
|
483
|
|
|
$aReturnData['errorMessage'] = __('There has been an error processing your request.'); |
|
|
|
|
|
|
484
|
|
|
} |
|
485
|
|
|
return $aReturnData; |
|
486
|
|
|
} |
|
487
|
|
|
|
|
488
|
|
|
/** |
|
489
|
|
|
* Removes the amazon session variables |
|
490
|
|
|
* |
|
491
|
|
|
* @return void |
|
492
|
|
|
*/ |
|
493
|
|
|
protected function unsetSessionVariables() |
|
494
|
|
|
{ |
|
495
|
|
|
$this->checkoutSession->unsAmazonWorkorderId(); |
|
496
|
|
|
$this->checkoutSession->unsAmazonReferenceId(); |
|
497
|
|
|
$this->checkoutSession->unsAmazonAddressToken(); |
|
498
|
|
|
$this->checkoutSession->unsOrderReferenceDetailsExecuted(); |
|
499
|
|
|
} |
|
500
|
|
|
} |
|
501
|
|
|
|
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