Jump to content

Can someone explain this part of the paypal express script?

Recommended Posts

Hi folks,


Hit a slight problem with transactions with more than one item quantity. The installation (v2.3.1) this is on has some issues with the tax implementation, but I'm not quite sure what the purpose of the following piece of script is in the paypal express script (ext\modules\payment\paypal\express.php).


 $nProd = sizeof($order->products);
 $subtotal = 0;
 for ($i = 0; $i < $nProd; ++$i) {
	 $subtotal += $paypal_express->format_raw($order->products[$i]['final_price']) * $order->products[$i]['qty'];
 $difst = 0;
 if ($subtotal != $paypal_express->format_raw($order->info['subtotal'])) {
	 $difst = $paypal_express->format_raw($order->info['subtotal']) - $subtotal;
 $order->products[$nProd - 1]['final_price'] += $difst;


Can anyone explain the purpose of this? I'm not quite sure why the script seems to be comparing the order subtotal to an aggregate product total, and then offsetting the last item by that difference?


Many thanks,



Share this post

Link to post
Share on other sites

I would surmise that they are correcting for any difference between the sum of totals with tax and tax applied to the total price. It's not uncommon for there to be a penny or so difference, and they're just hiding it by adjusting one item's price. The alternative is to have the customer complaining that price totals don't add up.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now