Magento – Paypal Express with coupon and custom discount

paypal-express

Paypal Express works fine if there's no coupon applied. If there's a coupon applied, it fails with the usual #10413 error "totals of the cart item amounts do not match order amounts".

I have a requirement to customize the discount logic so that the discounts are reflected in the unit prices and not in the standard lump sum. There is a rounding issue when the quantities are large and Paypal will reject the payment. After hacking the Paypal module code, I can send a correct AMT = ITEMAMT + SHIPPING.

However, after returning from the Paypal payment confirmation page to Magento, for some reason the error #10413 appears again because AMT is changed (not the AMT that was sent to Paypal). I am not able to figure out why or how AMT is changed.

I am using Magento community version 1.8.1.0.

Best Answer

I spent 2 days but still could not find out who changed the value in AMT.

The following hack works for now. In app/code/core/Mage/Paypal/Model/Api/Nvp.php, change the method callDoExpressCheckoutPayment():

 ...
 $this->_exportLineItems($request);
 $finalTotal = $request['ITEMAMT'] + $request['SHIPPINGAMT'];
 if (sprintf('%.2F', $request['AMT']) != sprintf('%.2F', $finalTotal)) {
     $request['AMT'] = $finalTotal;
 }
Related Topic