PayPal Express Checkout bug handling extra line items

Project: 
Ubercart
Category: 
bug report
Priority: 
critical
Status: 
patch (needs review)

One of our client's sites was not processing PayPal Express Checkout payments -- the payment request was sent to PayPal, and some response was received, but no payment was ever credited.

After some debugging assistance from PayPal technical support, we tracked the problem to how Ubercart generates the EC request.

PayPal requires that the sum of the ITEMAMT, TAXAMT, and SHIPPINGAMT variables equal the AMT variable.

In this case, we are using the Coupon module, which adds a line item deduction for the order total. However, Ubercart does not take line items (other than tax and shipping) into account when calculating the variables for the PayPal request.

I added some debug code to dump the PayPal request to show these variables (I've redacted some of the values):

METHOD=DoExpressCheckoutPayment&TOKEN=XXXXX&PAYMENTACTION=Sale&PAYERID=XXXXX&AMT=23.15&DESC=XXXXX&INVNUM=XXXXX&BUTTONSOURCE=Ubercart_ShoppingCart_EC_US&NOTIFYURL=XXXXX&ITEMAMT=17.95&SHIPPINGAMT=7.00&TAXAMT=0.00&CURRENCYCODE=USD&USER=XXXXX&PWD=XXXXX&VERSION=3.0&SIGNATURE=XXXXX

As you can see, the ITEMAMT (17.95) + SHIPPINGAMT (7.00) + TAXAMT (0.00) equals 24.95. However, the Coupon module adds a line item subtracting 1.80 from the order total, which becomes the AMT variable (23.15).

I implemented a fix by recalculating the ITEMAMT variable as the difference remaining from AMT - TAXAMT - SHIPPINGAMT.

Attached is the patch for this fix.

AttachmentSize
uc_paypal-line_item_fix.diff643 bytes

Re: PayPal Express Checkout bug handling extra line items

Thanks for taking the time to debug this issue! I'm testing it right now and will commit it this afternoon. Smiling