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