cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2.x.x - cart/checkout item clears after failed payment

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Magento 2.x.x - cart/checkout item clears after failed payment

Hi there!

 

How do I prevent items in my cart to clear after a failed payment? It seems this problem only occurs when I use Paypal's Pro Hosted solution.

 

precondition

Magento 2.2.2

PHP 7.0

SQL 5.7

Steps to reproduce

  1. Add item to cart
  2. Proceed to checkout
  3. Checkout using Credit/Debit card.
  4. Refresh/go back page, cancel payment, failed payment

Expected results

  1. if refreshed page/go back - item should still be in still in the cart
  2. cancel/failed payment - give options to try again or even choose a different payment method.

Actual result

  1. clears item and redirects to an empty page (nothing is in your shopping cart)
  2. url is still cart/checkout
4 REPLIES 4

Re: Magento 2.x.x - cart/checkout item clears after failed payment

Re: Magento 2.x.x - cart/checkout item clears after failed payment

Below is the solution for magento 2.3.5

Please override Failure.php and change public function as below,

 public function execute()
    {
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $_checkoutSession = $objectManager->create('\Magento\Checkout\Model\Session');
        $_quoteFactory = $objectManager->create('\Magento\Quote\Model\QuoteFactory');
        
        $order = $_checkoutSession->getLastRealOrder();
        $quote = $_quoteFactory->create()->loadByIdWithoutStore($order->getQuoteId());
        if ($quote->getId()) {
            $quote->setIsActive(1)->setReservedOrderId(null)->save();
            $_checkoutSession->replaceQuote($quote);
            $resultRedirect = $this->resultRedirectFactory->create();
            $resultRedirect->setPath('checkout/cart');
            //$this->messageManager->addWarningMessage('Payment Failed.');
            return $resultRedirect;
        }
    }

Re: Magento 2.x.x - cart/checkout item clears after failed payment

Please mention the file path for Failure.php. 

Re: Magento 2.x.x - cart/checkout item clears after failed payment