[nopCommerce] Partial refund bug in nopCommerce

There is a “known” PayPal partial refund bug in nopCommerce 3.50 version that has been reported by several nop users.

Issues (reported by users):

1) Anytime when a store admin issues a partial refund via PayPal, the nopCommerce dashboard automatically shows that the entire total amount has been refunded

2) The order notes does show the correct issued partial refund amount

3) The issue leads to incorrect profit / sales numbers because even the cancelled orders are there as a part of the sales / profit section in nopCommerce

Here is the bug in the code: 

src/Plugins/Nop.Plugin.Payments.PayPalDirect/Controllers/PaymentPayPalDirectController.cs
public class PaymentPayPalStandardController  -> public ActionResult IPNHandler()
total = decimal.Parse(values["mc_gross"], new CultureInfo("en-US"));
 
 
case PaymentStatus.Refunded:
{
    if (_orderProcessingService.CanRefundOffline(order))
    {
        _orderProcessingService.RefundOffline(order);
    }
}
 A quick fix will be as follows (alternative fix):
case PaymentStatus.Refunded:
{
    if (order.OrderTotal == Math.Abs(total))
    {
        if (_orderProcessingService.CanRefundOffline(order))
        {
            _orderProcessingService.RefundOffline(order);
        }
    }
    else
    {
        if (_orderProcessingService.CanPartiallyRefundOffline(order, Math.Abs(total)))
        {
            _orderProcessingService.PartiallyRefundOffline(order, Math.Abs(total));
        }
    }  
}

A complete fix (in respect of nopCommerce code) will be:

{
    var totalToRefund = Math.Abs(mc_gross);
    if (totalToRefund > 0 && Math.Round(totalToRefund, 2).Equals(Math.Round(order.OrderTotal, 2)))
      {
         //refund
        if (_orderProcessingService.CanRefundOffline(order))
       {
       _orderProcessingService.RefundOffline(order);
         }
           }
       else
    {
    //partial refund
    if (_orderProcessingService.CanPartiallyRefundOffline(order, totalToRefund))
          {
              _orderProcessingService.PartiallyRefundOffline(order, totalToRefund);
            }
}
}

For a complete solution, please see the changeset: https://nopcommerce.codeplex.com/SourceControl/changeset/1e3b16cf3fe2af5d43f676af2bedf39f64a4e9aa

 

Looking for quality nopCommerce Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , | Posted under nopCommerce | RSS 2.0

Author Spotlight

Lavish Kumar

Founder, developer and owner of StrivingProgrammers.com - By profession, he is a software programmer / web developer, web designer & DBA. He is passionate about technology and electronic gadgets. He enjoys writing tech articles and developing web applications. He is a nopCommerce MVP and author of official nopCommerce Designer's Guide.

Leave a Reply

Your email address will not be published. Required fields are marked *