News:

Support the VirtueMart project and become a member

Main Menu

Posible bug in paymen plugin cost calculation

Started by razor7, December 29, 2021, 16:30:42 PM

Previous topic - Next topic

razor7

As stated in this old thread, https://forum.virtuemart.net/index.php?topic=117823.30 payment plugin cost calculation could be wrong. See screenshots and code proposal for fixing it. The issue seems to be in administrator/components/com_virtuemart/plugins/vmpsplugin.php

For example, for an order total of $10 and a discount of payment method of -10% I wolud expect to pay a grand total of $9, but instead VM calculates a grand total of $9.09 and payment discount of $-0.91

Set payment cashback to -10%


Buggy discount calculated payment price


Code change proposal is in function setCartPrices from this:

if(!$progressive){
//Simple
$cartTotalAmount=($cartTotalAmountOrig + $method->cost_per_transaction) * (1 +($method->cost_percent_total * 0.01));
//vmdebug('Simple $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') * (1 + ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Simple $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction).' * '. (1 + $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
} else {
//progressive
        $cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) / (1 - ($method->cost_percent_total * 0.01));
//vmdebug('Progressive $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') / (1 - ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Progressive $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction) .' / '. (1 - $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
}


To this:

if(!$progressive){
//Simple
$cartTotalAmount=($cartTotalAmountOrig + $method->cost_per_transaction) * (1 +($method->cost_percent_total * 0.01));
//vmdebug('Simple $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') * (1 + ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Simple $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction).' * '. (1 + $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
} else {
//progressive
        $cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) * (1 + ($method->cost_percent_total * 0.01));
//vmdebug('Progressive $cartTotalAmount = ('.$cartTotalAmountOrig.' + '.$method->cost_per_transaction.') / (1 - ('.$method->cost_percent_total.' * 0.01)) = '.$cartTotalAmount );
//vmdebug('Progressive $cartTotalAmount = '.($cartTotalAmountOrig + $method->cost_per_transaction) .' / '. (1 - $method->cost_percent_total * 0.01) .' = '.$cartTotalAmount );
}
MGS Creativa - VirtueMart Payment Plugin Experts
http://www.mgscreativa.com

Take a look at our downloads section for VirtueMart payment plugins and mouch more!
http://www.mgscreativa.com/en/online-store