After extensive testing, your solution does not fix all the rounding errors.
You need to add the following code as well as yours, to solve all the issues. (tested on +/-500 PAYPAL orders)
/includes/modules/payment/paypalwpp.php
Find the following, around line 1320
// check subtotals
if (strval($subTotalLI) - strval($sumOfLineItems) > 0.02) {
$this->zcLog('getLineItemDetails 5', 'Line-item subtotals do not add up properly. Line-item-details skipped.' . "\n" . (float)$sumOfLineItems . ' ' . (float)$subTotalTax . print_r(array_merge($optionsST, $optionsLI), true));
$optionsLI = array();
}
After the code, Add the following
/****** BOF BUG FIX ******/
// By Adrian kriel : root-at-extremecooling-dot-org
// Do extra sanity check on item amount and line item totals (bug fix to prevent fail with error code 10413)
//(caused by item being on sale, price is rounded off before the qty multiplication, hence why totals will be out by a few cents)
// this will add an extra line item that will appear on the paypal invoice.
$this->zcLog('getLineItemDetails 6', 'PayPal Correction Info:(sumOfLineItems: '.$sumOfLineItems.', ITEMAMT: '.$optionsST['ITEMAMT'].')'."\n");
if(strval($optionsST['ITEMAMT'])!= strval($sumOfLineItems)){ //$optionsST['ITEMAMT'] seems to be a more correct varible, than using $subTotalLI
$numberOfLineItemsProcessed++;
$k = $numberOfLineItemsProcessed;
//check to make sure we have more than 1 line option
if($k >= 1){
//calculate the correction value required.
$lineItemCorrection = strval($optionsST['ITEMAMT']) - strval($sumOfLineItems);
$this->zcLog('getLineItemDetails 6', 'PayPal Correction Fixed: Line-item subtotals do not add up properly (sumOfLineItems: '.$sumOfLineItems.', ITEMAMT: '.$optionsST['ITEMAMT'].'). Adding Bugfix line item with ammount: '. $lineItemCorrection .'\n');
//you could reset the array instead of assigning an extra line item
//$optionsLI = array();
$optionsLI["L_NUMBER$k"] = "";
$optionsLI["L_NAME$k"] = "PayPal Correction";
$optionsLI["L_AMT$k"] = strval($lineItemCorrection);
$optionsLI["L_QTY$k"] = 1;
$sumOfLineItems += strval($lineItemCorrection); //update the $sumOfLineItems Total
}
}
/****** EOF BUG FIX ******/
[ updates | coding | maintenance | bug fixes | dedicated servers ]