Skip to content

Commit

Permalink
MobilePay return action fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mareknaujas committed Mar 31, 2023
1 parent 0a1a02b commit e890171
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
75 changes: 73 additions & 2 deletions Controller/Payment/Returns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*
Expand All @@ -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');
}
}
}
}
2 changes: 1 addition & 1 deletion Model/Adapter/QuickPayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="QuickPay_Gateway" setup_version="2.3.4">
<module name="QuickPay_Gateway" setup_version="2.3.6">
<sequence>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
Expand Down

0 comments on commit e890171

Please sign in to comment.