Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancelled Paypal orders not showing in Magento admin

Tags:

magento

paypal

I have configured a Magento 1.9 community store and all orders for which payment is made through Paypal or other payment methods (like cash on delivery), are showing up in backend.

However, when I checkout selecting Paypal as the gateway, cancel my order on the Paypal page and return to the website - my order is not showing in the admin. Isn't it supposed to show up as a cancelled order.

Since this was a store migrated from Shopify, we had to manually create about a 100 orders and change their dates in the database manually. Can this be a reason for this unexpected behaviour?

Edit 1: No order info is displayed in the grid even if the paypal window is closed instead of clicking in cancel as many answers are suggesting.

like image 200
Sarthak Gupta Avatar asked Jul 10 '15 12:07

Sarthak Gupta


2 Answers

This is obvious because when you (as a customer) cancel an order in PayPal payment page it automatically destroys (unset) the order and the order quote before redirecting to shop - Not to be confused with the famous: Cancelled Order where as the name suggests is shown for the actual orders which have been actually done and then cancelled.

Depending on the PayPal method you are using this can be treated differently.

In standard PayPal you can find it in this controller:

\magento\app\code\core\Mage\Paypal\controllers\StandardController.php

when you cancel the order, cancelAction(), it first cancels the order:

    public function cancelAction()
{
    $session = Mage::getSingleton('checkout/session');
    $session->setQuoteId($session->getPaypalStandardQuoteId(true));
    if ($session->getLastRealOrderId()) {
        $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
        if ($order->getId()) {
            $order->cancel()->save();
        }
        Mage::helper('paypal/checkout')->restoreQuote();
    }
    $this->_redirect('checkout/cart');
}

and then redirectAction() unset the quote before redirecting back to the cart page:

    public function redirectAction()
{
    $session = Mage::getSingleton('checkout/session');
    $session->setPaypalStandardQuoteId($session->getQuoteId());
    $this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml());
    $session->unsQuoteId();
    $session->unsRedirectUrl();
}

On the other hand in PayPal Express, cancel operation is triggered in this controller:

\app\code\core\Mage\Paypal\Controller\Express\Abstract.php

    public function cancelAction()
{
    try {
        $this->_initToken(false);
        // TODO verify if this logic of order cancelation is deprecated
        // if there is an order - cancel it
        $orderId = $this->_getCheckoutSession()->getLastOrderId();
        $order = ($orderId) ? Mage::getModel('sales/order')->load($orderId) : false;
        if ($order && $order->getId() && $order->getQuoteId() == $this->_getCheckoutSession()->getQuoteId()) {
            $order->cancel()->save();
            $this->_getCheckoutSession()
                ->unsLastQuoteId()
                ->unsLastSuccessQuoteId()
                ->unsLastOrderId()
                ->unsLastRealOrderId()
                ->addSuccess($this->__('Express Checkout and Order have been canceled.'))
            ;
        } else {
            $this->_getCheckoutSession()->addSuccess($this->__('Express Checkout has been canceled.'));
        }
    } catch (Mage_Core_Exception $e) {
        $this->_getCheckoutSession()->addError($e->getMessage());
    } catch (Exception $e) {
        $this->_getCheckoutSession()->addError($this->__('Unable to cancel Express Checkout.'));
        Mage::logException($e);
    }

    $this->_redirect('checkout/cart');
}

where it unset everything in the same place.

So in your case if you need to keep the quote (which I suppose is what you have been exploiting in your custom module) you have to change this behavior of PayPal module.

Please remember if you are going to do this do not modify the original core files, instead extend these classes in your custom module and apply your changes there.

like image 153
hatef Avatar answered Oct 15 '22 01:10

hatef


When you cancel the order from Paypal page without completing the payment, it will redirect you back to your cart page. The order will not get placed.

If you close the page after paypal redirection, without completing the payment(note that you do not have to press cancel here) the order will get placed with pending payment status.

To verify whether paypal is working correctly or not, try to complete the payment process via paypal. If you are using it for testing purposes you can use the sandbox mode so that you won't get charged for your order.

Hope this helps!!

like image 32
Reena Parekh Avatar answered Oct 15 '22 01:10

Reena Parekh