Marek123
Marek123

Reputation: 1211

Magento - Paypal dispute create credit memo automatically

first of all, I am using Magento 1.7.

The problem is that if someone opens a PayPal dispute a credit memo email is also created within Magento and an email is sent to the customer to tell them they have been refunded when they haven’t. Instead PayPal just puts a hold on the funds until the dispute is resolved.

When we resolve the dispute, the credit memo is still there and we cannot delete it or cancel it.

Does anyone know how to prevent this from happening?

Thanks.

Marek

Upvotes: 2

Views: 3413

Answers (1)

Scruffy Paws
Scruffy Paws

Reputation: 1250

I find this an annoying bug in the newer versions of Magento that I came across after upgrading from v1.4.0.1 to v1.7.0.2. I think it came about right around v1.4.2.0. There are so many ways this can go wrong I don't know why they thought it was a good idea to add it.

The code that is powering this action is in the registerRefundNotification() method of the Mage_Sales_Model_Order_Payment class in /app/code/core/Mage/Sales/Model/Order/Payment.php.

Per timpea's fix at http://www.magentocommerce.com/boards/viewthread/261158/ you just need to overload the registerRefundNotification() and comment out the offending portion, which in v1.7.0.2 would be the portion below.

$serviceModel = Mage::getModel('sales/service_order', $order);
if ($invoice) {
    if ($invoice->getBaseTotalRefunded() > 0) {
        $adjustment = array('adjustment_positive' => $amount);
    } else {
        $adjustment = array('adjustment_negative' => $baseGrandTotal - $amount);
    }
    $creditmemo = $serviceModel->prepareInvoiceCreditmemo($invoice, $adjustment);
    if ($creditmemo) {
        $totalRefunded = $invoice->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal();
        $this->setShouldCloseParentTransaction($invoice->getBaseGrandTotal() <= $totalRefunded);
    }
} else {
    if ($order->getBaseTotalRefunded() > 0) {
        $adjustment = array('adjustment_positive' => $amount);
    } else {
        $adjustment = array('adjustment_negative' => $baseGrandTotal - $amount);
    }
    $creditmemo = $serviceModel->prepareCreditmemo($adjustment);
    if ($creditmemo) {
        $totalRefunded = $order->getBaseTotalRefunded() + $creditmemo->getBaseGrandTotal();
        $this->setShouldCloseParentTransaction($order->getBaseGrandTotal() <= $totalRefunded);
    }
}

$creditmemo->setPaymentRefundDisallowed(true)
    ->setAutomaticallyCreated(true)
    ->register()
    ->addComment(Mage::helper('sales')->__('Credit memo has been created automatically'))
    ->save();

$this->_updateTotals(array(
    'amount_refunded' => $creditmemo->getGrandTotal(),
    'base_amount_refunded_online' => $amount
));

$this->setCreatedCreditmemo($creditmemo);

Upvotes: 1

Related Questions