/** * Get checkout method * * @return string */ public function getCheckoutMethod() { if ($this->_cart->getCustomerSession()->isLoggedIn()) { return \Magento\Checkout\Model\Type\Onepage::METHOD_CUSTOMER; } if (!$this->_cart->getQuote()->getCheckoutMethod()) { if ($this->_checkoutData->isAllowedGuestCheckout($this->_cart->getQuote())) { $this->_cart->getQuote()->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_GUEST); } else { $this->_cart->getQuote()->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER); } } return $this->_cart->getQuote()->getCheckoutMethod(); }
public function execute() { $redirectTo = 'checkout/cart'; $defaultErrorMessage = $this->_dataHelper->__('An error occurred during the payment process.'); try { $this->_logger->debug(__METHOD__ . ':' . print_r($this->_request->getPost()->toArray(), true)); $this->_cart->getCustomerSession()->unsUniqueId(); if (!$this->_request->isPost()) { throw new \Exception('Not a post request'); } $return = \WirecardCEE_QPay_ReturnFactory::getInstance($this->_request->getPost()->toArray(), $this->_dataHelper->getConfigData('basicdata/secret')); if (!$return->validate()) { throw new \Exception('Validation error: invalid response'); } if (!strlen($return->mage_orderId)) { throw new \Exception('Magento OrderId is missing'); } if (!strlen($return->mage_quoteId)) { throw new \Exception('Magento QuoteId is missing'); } $orderId = $this->_request->getPost('mage_orderId'); /** @var \Magento\Sales\Model\Order $order */ $order = $this->_objectManager->create('\\Magento\\Sales\\Model\\Order'); $order->loadByIncrementId($orderId); $orderExists = (bool) $order->getId(); if ($return->mage_orderCreation == 'before') { if (!$orderExists) { throw new \Exception('Order not found'); } $payment = $order->getPayment(); if (!strlen($payment->getAdditionalInformation('paymentState'))) { $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!'); $order = $this->_orderManagement->processOrder($return); } } if ($return->mage_orderCreation == 'after') { if (!$orderExists && ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS || $return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING)) { $this->_logger->debug(__METHOD__ . ':order not processed via confirm server2server request, check your packetfilter!'); $order = $this->_orderManagement->processOrder($return); } } switch ($return->getPaymentState()) { case \WirecardCEE_QPay_ReturnFactory::STATE_SUCCESS: case \WirecardCEE_QPay_ReturnFactory::STATE_PENDING: if ($return->getPaymentState() == \WirecardCEE_QPay_ReturnFactory::STATE_PENDING) { $this->messageManager->addNoticeMessage($this->_dataHelper->__('Your order will be processed as soon as we receive the payment confirmation from your bank.')); } /* needed for success page otherwise magento redirects to cart */ $this->_checkoutSession->setLastQuoteId($order->getQuoteId()); $this->_checkoutSession->setLastSuccessQuoteId($order->getQuoteId()); $this->_checkoutSession->setLastOrderId($order->getId()); $this->_checkoutSession->setLastRealOrderId($order->getIncrementId()); $this->_checkoutSession->setLastOrderStatus($order->getStatus()); $redirectTo = 'checkout/onepage/success'; break; case \WirecardCEE_QPay_ReturnFactory::STATE_CANCEL: /** @var \WirecardCEE_QPay_Return_Cancel $return */ $this->messageManager->addNoticeMessage($this->_dataHelper->__('You have canceled the payment process!')); if ($return->mage_orderCreation == 'before') { $quote = $this->_orderManagement->reOrder($return->mage_quoteId); $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId(); } break; case \WirecardCEE_QPay_ReturnFactory::STATE_FAILURE: /** @var \WirecardCEE_QPay_Return_Failure $return */ $msg = $return->getErrors()->getConsumerMessage(); if (!strlen($msg)) { $msg = $defaultErrorMessage; } $this->messageManager->addErrorMessage($msg); if ($return->mage_orderCreation == 'before') { $quote = $this->_orderManagement->reOrder($return->mage_quoteId); $this->_checkoutSession->replaceQuote($quote)->unsLastRealOrderId(); } break; default: throw new \Exception('Unhandled Wirecard Checkout Page payment state:' . $return->getPaymentState()); } if ($this->_request->getPost('iframeUsed')) { $redirectUrl = $this->_url->getUrl($redirectTo); $page = $this->_resultPageFactory->create(); $page->getLayout()->getBlock('checkout.back')->addData(['redirectUrl' => $redirectUrl]); return $page; } else { $this->_redirect($redirectTo); } } catch (\Exception $e) { if (!$this->messageManager->getMessages()->getCount()) { $this->messageManager->addErrorMessage($defaultErrorMessage); } $this->_logger->debug(__METHOD__ . ':' . $e->getMessage()); $this->_redirect($redirectTo); } }
/** * Returns uniqueId - required for duplicate request check, if the transaction was canceled * * @param CheckoutCart $cart * * @return string */ protected function _getUniqueId($cart) { $uniqueId = $cart->getCustomerSession()->getUniqueId(); if (!strlen($uniqueId)) { $uniqueId = $this->_generateUniqString(); $cart->getCustomerSession()->setUniqueId($uniqueId); } return $uniqueId; }