5

I'm trying to find out why some logged in customers are being logged out of their accounts and redirected to an empty shopping cart after clicking the place order button in Magento.

I am using SagePay 4.1.3 and Idev_OnstepCheckout

I've been looking into the saveAfter event in sagePay to see where the session is terminated but I am not able to locate the function call but I can see where the failedPayment.log is called.

public function saveAfter($o)
{
    $order = $o->getEvent()->getOrder();

    $isSage = Mage::helper('sagepaysuite')->isSagePayMethod($order->getPayment()->getMethod());

    if (!$order->getId() || $isSage === false || $order->getIsRecurring()) {
        return $o;
    }

    $dbtrn = $this->_getTransactionsModel()->loadByParent($order->getId());

    if ($dbtrn->getId()) {
        return $o;
    }

    $rqVendorTxCode = Mage::app()->getRequest()->getParam('vtxc');
    $sessionVendor = ($rqVendorTxCode) ? $rqVendorTxCode : $this->getSession()->getLastVendorTxCode();

    if($sessionVendor == null){
        $sessionVendor = Mage::app()->getRequest()->getParam('VendorTxCode');
    }

    /**
     * Multishipping vendors
     */
    $multiShippingTxCodes = Mage::registry('sagepaysuite_ms_txcodes');
    if ($multiShippingTxCodes) {

        Mage::unregister('sagepaysuite_ms_txcodes');

        $sessionVendor = current($multiShippingTxCodes);

        array_shift($multiShippingTxCodes);
        reset($multiShippingTxCodes);

        Mage::register('sagepaysuite_ms_txcodes', $multiShippingTxCodes);
    }
    /**
     * Multishipping vendors
     */

    $reg = Mage::registry('Ebizmarts_SagePaySuite_Model_Api_Payment::recoverTransaction');
    if (!is_null($reg)) {
        $sessionVendor = $reg;
    }

    if (is_null($sessionVendor)) {


        if (!$dbtrn->getId()) {

            #For empty payments or old orders (standalone payment methods).
            if ((Mage::app()->getRequest()->getControllerModule() == 'Mage_Api') || Mage::registry('current_shipment') || Mage::registry('sales_order') || Mage::registry('current_creditmemo') || Mage::registry('current_invoice') || ($order->getPayment()->getMethod() == 'sagepayrepeat')) {
                return $o;
            }

            $logfileName = $order->getIncrementId() . '-' . time() . '_Payment_Failed.log';

            $request_data = $_REQUEST;
            if (isset($request_data['payment'])) {
                $request_data['payment']['cc_number'] = 'XXXXXXXXXXXXX';
                $request_data['payment']['cc_cid'] = 'XXX';
            }

            Sage_Log::log($order->getIncrementId(), null, $logfileName);
            Sage_Log::log(Mage::helper('core/http')->getHttpUserAgent(false), null, $logfileName);
            Sage_Log::log(print_r($request_data, true), null, $logfileName);
            Sage_Log::log('--------------------', null, $logfileName);

            Mage::throwException('Payment has failed, please reload checkout page and try again. Your card has not been charged.');
        }

        return $o;
    }

Has anyone seen this problem before and know roughly how to resolve it?

Any ideas will be welcomed.

  • yes, I faced this problem earlier when I am making APIs for the mobile app. After checkout the cart is empty. :( then I have tried in private window that time is working fine for the website.) for mobile I handled with session $cart = Mage::getSingleton('checkout/cart'); //getModel $cart->init(); $cart->addProduct($product, $qty); // update session $session->setCartWasUpdated(true); $cart->save(); – 55840 Aug 28 '18 at 17:48
  • How was you able to reproduce the error? It only happens on the live website... – user1704524 Aug 28 '18 at 18:02
  • I think session remove before that. – kunj Aug 29 '18 at 12:43
  • 1
    I actually resolved the issue but upgrading both SagePay and OSC making sure to remove all overrides that were added in the past. – user1704524 Aug 30 '18 at 6:46
  • Great!!, Please add your solution in the answer and accept it so it will help to other. – kunj Aug 31 '18 at 11:36
3

Resolved the issue by upgrading OSC and SagePay and removing all of the crap overrides from previous merges - works now!

1

I do not have access to all your code base but for following ;

I am not able to locate the function call but I can see where the failedPayment.log is called.

I think it is being called here -

Sage_Log::log(print_r($request_data, true), null, $logfileName);

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.