In the IPN response code, the order gets recalculated about halfway through:
In the IPN response code, the order gets recalculated about halfway through:
I believe it's because the subtotal needs to match the sum of products (which isn't necessarily true since addon fees do not get put into the products array). The short answer is "because it's paypal so nothing is normal or simple".
Ideally in an order (or the $cart), there would be a separate 'fees' array where addons could add fee elements like:
$order_data['fee_subtotal'] = $8.00 ( sum from below) $order_data['fees'] = array('gift_wrap' => 5.00, 'premium_gift_card' => 3.00)
And of course there should be a corresponding 'credits' area too so returns could be clearly shown as a credit to an order....
The cart would then use:
$order_data['total'] = $order_data['subtotal'] + $order_data['shipping'] + $order_data['fees_subtotal'] - $order_data['credits_subtotal'] - $order_data['subtotal_discounts'] - $order_data['cart_discounts'];
Each payment provider with "special needs" could be adjusted to use the appropriate subtotal data which are the logical areas of an order.
ok thanks for that. It looked like it wasn't just the recalculation at fault, our promotion was looking for data in the wrong place during re-calculation.