I am angry on Easter bunny. Really... He delivered to me a nasty surprise: lots of my customers complained during/after Easter weekend, that their shops, sometimes the Easter's week began to malfunction: the users using PayPal as payment gateway aren't charged correctly. After studying the problem, I found, that is happening on shops running versions of VirtueMart 1.1.3 to 1.1.9, charging shipping to customers and using the old PayPal API to communicate with the gateway. More precisely, the sipping net amount was not transferred, the shipping tax was sent correctly.

Then, by searching for "virtuemart shipping not transferred to paypal" I discovered, that I am not alone: there where some 54k+ search results returned!

I spent a day with trying to find a solution provided by someone usable and workable, without success (switching to other gateway, or even to the new API was unpractical due various reasons) then decided to do an ugly, dirty hack to save my bacon (and my clients money) until someone - including myself - will found a better one.

Simply decided to not send the amount to be charged to the payment gateway in pieces as is normally works, by separately sending the gross amount of the goods and the amount of shipping charges (and the taxes for both) letting PayPal to calculate the grand total and charge the customers with that, but to send the gross amount alone. Easy, after one decided to do it Tongue out

Here's the recipe:

Go to VirtueMart Admin>Shop>List Payment Methods. Click on the PayPal payment method, to open the admin interface, then click on Configuration tab, to access the Payment Extra info editor window.

Locate this code:

"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total,
"shipping" => sprintf("%.2f", $db->f("order_shipping")),

and replace it with this:

"amount" => round( $db->f("order_subtotal")+$tax_total-$discount_total+sprintf("%.2f", $db->f("order_shipping")), 2),
"shipping" => "0",

Enjoy. I hope, you saved the original payment extra info before Wink. You know... just in case...

Category: VirtueMart hacks