In Magento 2.2.5, after payment failure cart is going empty. I want to keep this, that if payment failed cart will not be empty, that will show last cart items.

I'm using the PayUMoney Payment Method. How can I do this?

I get a lot of example of this problem on Magento 1.9 version but didn't get any suitable solution for Magento 2.2.5.

Please help me, how I solve this issue.

Thank you


This is a sample code for reactivate quote when payment is failed. This is a controller where it redirect after payment failure. You need to use it in your payment module and update the code according to your requirement or module structure.

namespace [Vendor]\[Module]\Controller\Order;

class Failure extends \Magento\Framework\App\Action\Action
    protected $_quoteFactory;
    protected $_checkoutSession;
    public function __construct(
        \Magento\Quote\Model\QuoteFactory $quoteFactory,
        \Magento\Checkout\Model\Session $checkoutSession,
        $this->_quoteFactory = $quoteFactory;
        $this->_checkoutSession = $checkoutSession;

    public function execute()
        $order = $this->_checkoutSession->getLastRealOrder();
        $quote = $this->_quoteFactory->create()->loadByIdWithoutStore($order->getQuoteId());
        if ($quote->getId()) {
            $resultRedirect = $this->resultRedirectFactory->create();
            $this->messageManager->addWarningMessage('Payment Failed.');
            return $resultRedirect;
  • Thank you for sharing the solution. But unable to do this. in the file path -- vendor/module-checkout/Controller/Onepage/Failure.php in this page I tried to implement your above code. But it's not working for me. I tried to implement in my payment method extension that is PayUM. But didn't find any failure page. I think this extension using Magento default failure function. Please help, what I did wrong. – M.Suman Sep 14 '18 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.