Magento order status updated to "Processing" even if PayPal payment failed

I have a problem with Magento 1.9 and PayPal payment method. When a customer pays with PayPal and there is a payment check, the order in such cases will have the status "Payment Review".

However, the problem is that in cases where the payment actually fails (ie insufficient funds in the customer's account), Magento updates the order status to "Processing" and customers end up receiving free items.

What do I need to do when, when calling the "Failed" IPN, I need to set the status to "Closed" for that particular order. I spent more than 4 hours looking for a solution but couldn't find a suitable solution.

If anyone has any fixes please share with me.

enter image description here

PayPal IPN Response Variables:

        [payer_email] => xxx@xxx.com
        [payer_id] => xxxxxxxxxxxx
        [payer_status] => unverified
        [payment_date] => 14:33:46 Jun 08, 2015 PDT
        [payment_gross] => 43.24
        [payment_status] => Failed
        [payment_type] => echeck
        [protection_eligibility] => Ineligible

      

Thanks in advance.

+3


source to share


2 answers


We faced the same issue and found the root cause of this. This appears to be a Magento Bug Tracker issue.

See https://www.magentocommerce.com/bug-tracking/issue/index/id/1041

You can fix this by rewriting the Ipn model as shown below:



<?php
/**
 * Rewrite the core fix an issue with IPN notifications of "failed" payments
 */
class Magento_CoreFixes_Model_Paypal_Ipn extends Mage_Paypal_Model_Ipn
{

    /**
     * @see https://www.magentocommerce.com/bug-tracking/issue/index/id/1041
     */
    protected function _registerPaymentFailure()
    {
        $this->_importPaymentInformation();

        // This is the fix allowing order to get the cancelled status
        foreach ($this->_order->getInvoiceCollection() as $invoice){
            $invoice->cancel()->save();
        }

        $this->_order
            ->registerCancellation($this->_createIpnComment(''), false)
            ->save();
    }
}

      

Hope it helps!

+3


source


Pierre MARTIN 's answer took me straight to the source of this problem and made it trivial to fix.

I wrapped this fix in a module that can be easily installed in any store. You can find source and installation instructions on GitHub



This is because if the order contains invalid invoices, the call registerCancellation()

raises an exception. An exception means that the status never changes and the default is "processing".

0


source







All Articles