diff --git a/Controller/Payment/Returns.php b/Controller/Payment/Returns.php index 915e13d..bdce083 100644 --- a/Controller/Payment/Returns.php +++ b/Controller/Payment/Returns.php @@ -4,6 +4,47 @@ class Returns extends \Magento\Framework\App\Action\Action { + /** + * @var \Magento\Checkout\Model\Session + */ + protected $_checkoutSession; + + /** + * @var \Magento\Sales\Model\OrderFactory + */ + protected $_orderFactory; + + /** + * @var \Magento\Sales\Api\OrderRepositoryInterface + */ + protected $_orderRepository; + + /** + * @var \Magento\Framework\Api\SearchCriteriaBuilder + */ + protected $_searchCriteriaBuilder; + + /** + * @param \Magento\Framework\App\Action\Context $context + * @param \Magento\Checkout\Model\Session $checkoutSession + * @param \Magento\Sales\Model\OrderFactory $orderFactory + * @param \Magento\Sales\Api\OrderRepositoryInterface $orderRepository + * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder + */ + public function __construct( + \Magento\Framework\App\Action\Context $context, + \Magento\Checkout\Model\Session $checkoutSession, + \Magento\Sales\Model\OrderFactory $orderFactory, + \Magento\Sales\Api\OrderRepositoryInterface $orderRepository, + \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteriaBuilder + ) { + $this->_checkoutSession = $checkoutSession; + $this->_orderFactory = $orderFactory; + $this->_orderRepository = $orderRepository; + $this->_searchCriteriaBuilder = $searchCriteriaBuilder; + parent::__construct($context); + } + /** * @return \Magento\Checkout\Model\Session */ @@ -12,6 +53,28 @@ protected function _getCheckout() return $this->_objectManager->get('Magento\Checkout\Model\Session'); } + /** + * @return bool|\Magento\Sales\Model\Order + */ + public function getOrder() + { + $order = null; + if($protectCode = $this->getRequest()->getParam('order')){ + $searchCriteria = $this->_searchCriteriaBuilder->addFilter('protect_code', $protectCode) + ->setPageSize(1) + ->setCurrentPage(1) + ->create(); + $resultOrders = $this->_orderRepository->getList($searchCriteria); + + if ($resultOrders->getTotalCount() > 0) { + $orders = $resultOrders->getItems(); + $order = current($orders); + } + } + + return $order; + } + /** * Redirect to to checkout success * @@ -20,12 +83,20 @@ protected function _getCheckout() public function execute() { $area = $this->getRequest()->getParam('area'); + $order = $this->getOrder(); if($area == 'admin'){ $this->messageManager->addSuccess(__('Thank you for your purchase. You will soon receive a confirmation by email.')); } - if ($this->_getCheckout()->getLastRealOrderId()) { + if($order && $order->getId()){ + $this->_getCheckout()->setLastOrderId($order->getId()); + $this->_getCheckout()->setLastQuoteId($order->getQuoteId()); + $this->_getCheckout()->setLastSuccessQuoteId($order->getQuoteId()); + $this->_getCheckout()->setLastRealOrderId($order->getIncrementId()); + $this->_redirect('checkout/onepage/success'); + } else { + $this->_redirect('checkout/cart'); } } -} \ No newline at end of file +} diff --git a/Model/Adapter/QuickPayAdapter.php b/Model/Adapter/QuickPayAdapter.php index 748fe0a..a597eca 100644 --- a/Model/Adapter/QuickPayAdapter.php +++ b/Model/Adapter/QuickPayAdapter.php @@ -301,7 +301,7 @@ public function CreatePaymentLink($order, $area = 'frontend') $parameters = [ "amount" => $order->getBaseTotalDue() * 100, - "continueurl" => $this->url->getUrl('quickpaygateway/payment/returns'), + "continueurl" => $this->url->getUrl('quickpaygateway/payment/returns', ['order' => $order->getProtectCode()]), "cancelurl" => $this->url->getUrl('quickpaygateway/payment/cancel'), "callbackurl" => $this->url->getUrl('quickpaygateway/payment/callback'), "customer_email" => $order->getCustomerEmail(), diff --git a/etc/module.xml b/etc/module.xml index 1a46b29..2bbb037 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - +