public function execute() { $urls = ['confirm' => $this->_url->getUrl('wirecardcheckoutpage/checkout/confirm', ['_secure' => true, '_nosid' => true]), 'return' => $this->_url->getUrl('wirecardcheckoutpage/checkout/back', ['_secure' => true, '_nosid' => true])]; $payment = null; try { if ($this->getCheckoutMethod() == \Magento\Checkout\Model\Type\Onepage::METHOD_GUEST) { $this->prepareGuestQuote(); } $customerDob = $this->_cart->getQuote()->getPayment()->getAdditionalInformation('customerDob'); if (strlen($customerDob)) { $this->_cart->getQuote()->setCustomerDob($customerDob); } /** @var \Wirecard\CheckoutPage\Model\AbstractPayment $payment */ $payment = $this->_cart->getQuote()->getPayment()->getMethodInstance(); $init = $payment->initPaymentByCart($this->_cart, $urls, new \Magento\Framework\DataObject($payment->getInfoInstance()->getAdditionalInformation())); if ($this->_dataHelper->getConfigData('options/order_creation') == 'before') { $this->_orderManagement->submitOrder($this->_cart->getQuote()); } $this->getResponse()->setRedirect($init->getRedirectUrl()); } catch (\Exception $e) { $this->_logger->debug(__METHOD__ . ':' . $e->getMessage()); $this->messageManager->addErrorMessage($this->_dataHelper->__('An error occurred during the payment process')); if ($payment === null) { $this->_redirect('/'); } else { $this->getResponse()->setRedirect($this->_url->getUrl('wirecardcheckoutpage/checkout/failed', ['_secure' => true, '_query' => ['iframeused' => (int) ($payment->getDisplayMode() != 'redirect')]])); } } }
/** * Get resolved back url, rewritten to return checkout URL instead of cart url * * @param \Magento\Checkout\Controller\Cart\Add $subject * @return string */ public function afterExecute(\Magento\Checkout\Controller\Cart\Add $subject, \Magento\Framework\Controller\Result\Redirect $redirect) { $shouldRedirectToCart = $this->_config->getValue('checkout/cart/redirect_to_cart', \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if ($shouldRedirectToCart && !$subject->getRequest()->getParam('in_cart')) { $redirect->setUrl($this->_url->getUrl('checkout/index/index')); } return $redirect; }
public function execute() { $redirectTo = 'checkout/cart'; if ($this->_request->getParam('iframeused')) { $redirectUrl = $this->_url->getUrl($redirectTo); $page = $this->_resultPageFactory->create(); $page->getLayout()->getBlock('checkout.failed')->addData(['redirectUrl' => $redirectUrl]); return $page; } else { $this->_redirect($redirectTo); } }
/** * @test */ public function redirectUrl() { $result = $this->_controller->getBackUrl(null); $url = new \Magento\Framework\Url(); $expected = $url->getUrl('checkout/index/index'); $this->assert($expected, $result); }
/** * Custom logic to retrieve Urls * * @param string $routePath * @param array $routeParams * @return string */ public function getUrl($routePath = null, $routeParams = null) { if (filter_var($routePath, FILTER_VALIDATE_URL)) { return $routePath; } $cacheSecretKey = false; if (is_array($routeParams) && isset($routeParams['_cache_secret_key'])) { unset($routeParams['_cache_secret_key']); $cacheSecretKey = true; } $result = parent::getUrl($routePath, $routeParams); if (!$this->useSecretKey()) { return $result; } $this->_setRoutePath($routePath); $routeName = $this->_getRouteName('*'); $controllerName = $this->_getControllerName(self::DEFAULT_CONTROLLER_NAME); $actionName = $this->_getActionName(self::DEFAULT_ACTION_NAME); if ($cacheSecretKey) { $secret = [self::SECRET_KEY_PARAM_NAME => "\${$routeName}/{$controllerName}/{$actionName}\$"]; } else { $secret = [self::SECRET_KEY_PARAM_NAME => $this->getSecretKey($routeName, $controllerName, $actionName)]; } if (is_array($routeParams)) { $routeParams = array_merge($secret, $routeParams); } else { $routeParams = $secret; } if (is_array($this->_getRouteParams())) { $routeParams = array_merge($this->_getRouteParams(), $routeParams); } return parent::getUrl("{$routeName}/{$controllerName}/{$actionName}", $routeParams); }
/** * Send email with new customer password * * @param CustomerInterface $customer * @param string $newPasswordToken * @return $this */ public function sendPasswordReminderEmail($customer, $newPasswordToken) { $this->url->setScope($customer->getStoreId()); //TODO : Fix how template is built. Maybe Framework Object or create new Email template data model? // Check template to see what values need to be set in the data model to be passed // Need to set the reset_password_url property of the object $store = $this->storeManager->getStore($customer->getStoreId()); $resetUrl = $this->url->getUrl('customer/account/createPassword', ['_query' => ['id' => $customer->getId(), 'token' => $newPasswordToken], '_store' => $customer->getStoreId(), '_secure' => $store->isFrontUrlSecure()]); $customerEmailData = $this->getFullCustomerObject($customer); $customerEmailData->setResetPasswordUrl($resetUrl); $this->sendEmailTemplate($customer, self::XML_PATH_REMIND_EMAIL_TEMPLATE, self::XML_PATH_FORGOT_EMAIL_IDENTITY, ['customer' => $customerEmailData, 'store' => $store], $customer->getStoreId()); return $this; }
/** * Function for getting controller url for given router path * @param string $routePath * @return string */ public function getControllerUrl($routePath) { return $this->_urlApp->getUrl($routePath); }
/** * Get generate nonce URL * * @return string */ public function getAjaxGenerateNonceUrl() { return $this->urlBuilder->getUrl('braintree/creditcard/generate', ['_secure' => true]); }
/** * @param Item $item * @return string */ public function getPurchasedLinkUrl($item) { return $this->frontendUrlBuilder->getUrl('downloadable/download/link', ['id' => $item->getLinkHash(), '_scope' => $this->getOrder()->getStore(), '_secure' => true, '_nosid' => true]); }
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); } }