VirtueMart Forum
VirtueMart 2 + 3 => Virtuemart Development and bug reports => Topic started by: Marttyn on August 08, 2013, 22:07:15 pm

Hello!
Im using Joomla 2.5.8 and VM2.0.22a
Im setting up the payment methods, and ive realized that if i set a fee for some payment method, the fee is not calculated correctly.
The problem is on both plugins Standard, and Paypal.
I will start explaining with Standard as its easier:
I have a "Cash on delivery" payment method, using Standard plugin. The shipping company charges me 3% of the amount plus TAX.
Im using "percentage of total amount" = 3, and general TAX rules, here in Spain, TAX is 21%.
That means that 3% of the TOTAL AMOUNT should be calculated, but it calculates 3% of products + shipping.
If i have an order of $100 (and free shipping to make it easy), then the calculated fee for this payment method is: $3.63. This is because 3% of $100 is $3, plus 21% TAX, makes $3.63.
But in fact, the fee should be $3.77, plus $100 product makes $103.77 order total.
3% of $103.77 is $3.11. $3.11 plus 21% tax makes $3.77 < this is how shipping companies charges for "cash on delivery service".
So, if i charge $103.77, and the shipping company keeps $3.77, i have my $100 of the order...
Thats why i think the plug in is not working properly.
With Paypal occurs the same, but more complex:
Paypal charges me $0.35 fixed fee, plus 3.4% of total amount.
So I configure the plugin with 0.35 transaction fee, and 3.4 for percentage of total amount. With 21% tax
Same example: $100 product, free shipping.
Paypal fee charged by VM is $4.54 ($100 * 3.4% = $3.4  $3.4 + $0.35 = $3.75  $3.75 * 21% = $4.54)
The correct fee should be $4.73, plus $100 product makes $104.73 order total.
3.4% of $104.73 is $3.56. $3.56 plus 0.35 fixed fee is $3.91. And $3.91 plus 21% tax makes $4.73 < this is how paypal charges the fees. (although 21% TAX is not charged by paypal, im obliged to do it by estate treasury)
Thats why i think the plug in is not working properly.
Maybe TAX is making it more difficult to explain and the calculations are a little bit more difficult, but the problem is still the same: the fee is calculated over the product + shipping total, and not over the amount to pay.
Here you have a Paypal calculator to check http://www.rememberingrolbe.com/paypal.htm
Check the image attached to quickly see how the plug in is calculating wrong.
(http://i299.photobucket.com/albums/mm317/Marttyn/Electronica/Sintiacutetulo1.png)
If you consider this a bug as i do, ive made all calculations and formulas to get the correct values. If you need this just ask.
Regards!

Are you sure that it's not misconfiguration? There're plenty threads on forum with calculation 'bugs'. Find some of them and study.

Are you sure that it's not misconfiguration? There're plenty threads on forum with calculation 'bugs'. Find some of them and study.
Thank you Maxim for your attention.
Yesterday i spend 3 hours trying to understand why I get this values, and how are the calculations made.
Im not the best mathematician, but Im not the worst also. Im sure that the calculation is wrong, unless VM want this behaviour like it is now. But in this case you should notice people that the calculated fee will not match the real paypal fee.
And of course, with Standard, and other payment methods should happen the same.
You can check very easily adding a new Paypal payment method, and configuring only percentage of total amount to 5% like this:
(http://i299.photobucket.com/albums/mm317/Marttyn/Electronica/config.png)
Then you go to your cart and add an item (i added 100€ to make it more simple) and choose the previously created payment method, mine is called "Prueba", like this:
(http://i299.photobucket.com/albums/mm317/Marttyn/Electronica/cart.png)
And as you can see, VM will calculate the fee over the total of products plus shipping (no shipping used in this example). But Paypal will charge you over the total of the whole order. You can clearly see that (supposing that paypal charges a 5% fee, and without fixed fees) 5% of the total (105€) is 5.25€.
So VM charges 5€ for Paypal fee, but in fact Paypal will charge you 5.25€ for this transaction...
Regards!

Would be great if someone pay attention to this. Its a verified bug, and its charging wrong fees to people around the world!

Hello
I will have a look.

Thank you Alatak!
I was thinking that nobody was "interested" in this bug...
Can you please at least confirm if it is a calculation error on the plugin? This way people interested on this can take action, deactivate or charge different percentage to be closer to the real fee charged.
Please remember this is not only a Paypal plugin problem, also with Standard plugin happens the same (and probably with other payment methods, but i didnt check).
Regards!

hello
yes it is bug.
thank you for the detailed description.
It helped a lot.
I have done the fix. It will be available in the next version.

hello
you can test the fix by adding this function in both file
 plugins/vmpayment/paypal/paypal.php
 plugins/vmpayment/standard/standard.php
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method) {
if (!class_exists ('calculationHelper')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
}
if (!class_exists ('calculationHelper')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
}
$calculator = calculationHelper::getInstance ();
$_psType = ucfirst ($this>_psType);
if(isset($method>tax_id) and (int)$method>tax_id === 1){
} else if (!empty($method>tax_id)) {
$cart_prices[$this>_psType . '_calc_id'] = $method>tax_id;
$db = JFactory::getDBO ();
$q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method>tax_id . '" ';
$db>setQuery ($q);
$taxrules = $db>loadAssocList ();
} else {
//This construction makes trouble, if there are products with different vats in the cart
//on the other side, it is very unlikely to have different vats in the cart and simultaneous it is not possible to use a fixed tax rule for the shipment
if(!empty($calculator>_cartData['VatTax']) and count ($calculator>_cartData['VatTax']) == 1){
$taxrules = $calculator>_cartData['VatTax'];
foreach($taxrules as &$rule){
$rule['subTotal'] = $cart_prices[$this>_psType . 'Value'];
}
} else {
$taxrules = $calculator>_cartData['taxRulesBill'];
foreach($taxrules as &$rule){
unset($rule['subTotal']);
}
}
}
$cartTotalAmount=$cart_prices['salesPrice'] + $cart_prices['salesPriceShipment']  $cart_prices['salesPriceCoupon'] ;
if (isset($method>cost_percent_total)) {
if (preg_match ('/%$/', $method>cost_percent_total)) {
$cost_percent_total = (substr ($method>cost_percent_total, 0, 1))/100;
} else {
$cost_percent_total = $method>cost_percent_total;
}
} else {
$cost_percent_total=0;
}
if (isset($method>cost_per_transaction)) {
$cost_per_transaction=$method>cost_per_transaction;
} else {
$cost_per_transaction=0;
}
if (count ($taxrules) > 0) {
$cost_percent_total_vat = $calculator>executeCalculation($taxrules, $cost_percent_total, true);
$cost_per_transaction_vat = $calculator>executeCalculation($taxrules, $cost_per_transaction, true);
$NewTotalAmount= ($cartTotalAmount+$cost_per_transaction_vat) / ( 1  $cost_percent_total_vat );
$feeWithVat=$NewTotalAmount$cartTotalAmount;
$calculator>setRevert(true);
$feeNoVat = $calculator>roundInternal($calculator>executeCalculation($taxrules,$feeWithVat, true), 'salesPrice');
$calculator>setRevert(false);
$cart_prices[$this>_psType . 'Tax']=$feeWithVat$feeNoVat;
$cart_prices['salesPrice' . $_psType] =$feeWithVat;
$cart_prices[ $_psType.'Value'] = $feeNoVat;
reset($taxrules);
$taxrule = current($taxrules);
$cart_prices[$this>_psType . '_calc_id'] = $taxrule['virtuemart_calc_id'];
} else {
$NewTotalAmount=($cartTotalAmount+ $method>cost_per_transaction) / (1 $cost_percent_total);
$fee=$NewTotalAmount$cartTotalAmount;
$cart_prices['salesPrice' . $_psType] = $fee;
$cart_prices[$this>_psType . 'Tax'] = 0;
$cart_prices[$this>_psType . '_calc_id'] = 0;
}
return $cart_prices['salesPrice' . $_psType];
}

Hello Alatak!
Thank you for your attention :)
Ive place the code where you told me, but it seems that the price is still the same. For testing, i use 5% fee, and for 100€, it shows a fee of 5€.
The correct fee should be 105.26€, as the 5% of this its 5.26€.
Im a C programmer, but dont fully understand PHP. Im trying to understand where do you call the new function added. Because its a new function, shouldnt you be make a call from other place? But as you didnt modify any other part, it looks like you are not calling it...
Well, i dont know... you are the expert :)
Please reffer to this calculator to compare the real fees with the ones given by VM: http://www.rememberingrolbe.com/paypal.htm
Regards!

Hello
Yes you are rigth.
There was a error when the Fee per transaction was a value.
If 5 or 5% is the same.
The correct code is this one
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method) {
if (!class_exists ('calculationHelper')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
}
if (!class_exists ('calculationHelper')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
}
$calculator = calculationHelper::getInstance ();
$_psType = ucfirst ($this>_psType);
if(isset($method>tax_id) and (int)$method>tax_id === 1){
} else if (!empty($method>tax_id)) {
$cart_prices[$this>_psType . '_calc_id'] = $method>tax_id;
$db = JFactory::getDBO ();
$q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method>tax_id . '" ';
$db>setQuery ($q);
$taxrules = $db>loadAssocList ();
} else {
//This construction makes trouble, if there are products with different vats in the cart
//on the other side, it is very unlikely to have different vats in the cart and simultaneous it is not possible to use a fixed tax rule for the shipment
if(!empty($calculator>_cartData['VatTax']) and count ($calculator>_cartData['VatTax']) == 1){
$taxrules = $calculator>_cartData['VatTax'];
foreach($taxrules as &$rule){
$rule['subTotal'] = $cart_prices[$this>_psType . 'Value'];
}
} else {
$taxrules = $calculator>_cartData['taxRulesBill'];
foreach($taxrules as &$rule){
unset($rule['subTotal']);
}
}
}
$cartTotalAmount=$cart_prices['salesPrice'] + $cart_prices['salesPriceShipment']  $cart_prices['salesPriceCoupon'] ;
if (isset($method>cost_percent_total)) {
if (preg_match ('/%$/', $method>cost_percent_total)) {
$cost_percent_total = (substr ($method>cost_percent_total, 0, 1)) * 0.01;
} else {
$cost_percent_total = $method>cost_percent_total * 0.01;
}
} else {
$cost_percent_total=0;
}
if (isset($method>cost_per_transaction)) {
$cost_per_transaction=$method>cost_per_transaction;
} else {
$cost_per_transaction=0;
}
if (count ($taxrules) > 0) {
$cost_percent_total_vat = $calculator>executeCalculation($taxrules, $cost_percent_total, true);
$cost_per_transaction_vat = $calculator>executeCalculation($taxrules, $cost_per_transaction, true);
$NewTotalAmount= ($cartTotalAmount+$cost_per_transaction_vat) / ( 1  $cost_percent_total_vat );
$feeWithVat=$NewTotalAmount$cartTotalAmount;
$calculator>setRevert(true);
$feeNoVat = $calculator>roundInternal($calculator>executeCalculation($taxrules,$feeWithVat, true), 'salesPrice');
$calculator>setRevert(false);
$cart_prices[$this>_psType . 'Tax']=$feeWithVat$feeNoVat;
$cart_prices['salesPrice' . $_psType] =$feeWithVat;
$cart_prices[ $_psType.'Value'] = $feeNoVat;
reset($taxrules);
$taxrule = current($taxrules);
$cart_prices[$this>_psType . '_calc_id'] = $taxrule['virtuemart_calc_id'];
} else {
$NewTotalAmount=($cartTotalAmount+ $method>cost_per_transaction) / (1 $cost_percent_total);
$fee=$NewTotalAmount$cartTotalAmount;
$cart_prices['salesPrice' . $_psType] = $fee;
$cart_prices[$this>_psType . 'Tax'] = 0;
$cart_prices[$this>_psType . '_calc_id'] = 0;
}
return $cart_prices['salesPrice' . $_psType];
}

Thank you Valerie for your attention, and for sharing!
I will make changes, and as you told, in the next release this will be added, so my changes will be overwritten with the new corrected one, right? or should i be alert to undo the changes in next release?

Hello
The fix will be included in the next release.

Hello Valerie!
This bug was corrected in the new release 2.0.22c?
Regards!

Hello
Yes it is fixed in the release 2.0.22c

By doing a discount on the total payment by the method chosen, the system does not correctly calculate the amount.
1. a product of € 100 without taxes and with a 2% discount on payment > the discount percentage is wrong.
2. I installed the plug istraxx quantity for quantity discounts and neither ignored.
Where is the error? I installed an old version of VM (2.0. 8) and it works perfectly.
How I can solve the problem?
Attached some screenshots to see the problem
thanks
[attachment cleanup by admin]

Took me some time to reproduce it. It works fine with discount rules per product, but it seems not to take the correct value for the Rule per Bill. Lets see how we can solve this.

Hello,
I have this problem. I set Fee per transaction for every of my three payment methods. Paypal, Check Payment and Payment in Delivery. The two of them are 3.50 and the third 6.50. I use Rupostel One Page Checkout. In total is calculated only the 3.50 euros, even if i choose the payment method with 6.50 transaction per fee. I made some tests and it calculates the fee with the smallest value. Can you help me?

Nmihos, this is a another question and very likely related to the Rupostels One Page checkout.
For the other problem sardonic32 please try the attached file at \administrator\components\com_virtuemart\plugins
[attachment cleanup by admin]

Sorry Milbo.
If I replace the file with the new "vmpsplugin.php" you have sent, all I get are blank pages :(

Turn on Error reporting in Joomla config and post here your specific blank screen error, please.

Hi Maxim. these are the errors
Strict Standards: Declaration of VirtueMartControllerCart::display() should be compatible with that of JController::display() in /Applications/MAMP/htdocs/KMT20131002/components/com_virtuemart/controllers/cart.php on line 34
Strict Standards: Declaration of JParameter::loadSetupFile() should be compatible with that of JRegistry::loadSetupFile() in /Applications/MAMP/htdocs/KMT20131002/libraries/joomla/html/parameter.php on line 512
Fatal error: Cannot redeclare vmPSPlugin::convert_condition_amount() in /Applications/MAMP/htdocs/KMT20131002/administrator/components/com_virtuemart/plugins/vmpsplugin.php on line 892
Thank you very much for your work. Best regards

ah this was a small error happened due the synch with the both versions
[attachment cleanup by admin]

Hello Milbo. I tried the new file and the results are the same as with the old file. I do not know where the error is but 2% of 100 is calculated by the system in 1.96.
Also it does not used the discount amount by plugging amount of product to calculate the correct discount.
I made a downgrade to the web and I installed vm 2.0.8e and calculation is done correctly.
Sorry for the inconvenience. Thanks for your interest
[attachment cleanup by admin]

Ehrm did you read the begin of this post?
2% is in case of a payment plugin NOT 2! Please read the begin of the post again.

Hello Milbo. Now I'm a little lost.
I will try to explain better with my poor English.
I'll do the calculations as simple as possible and without taxes to simplify.
1. I have an order of 100€ and if if the customer chooses the pay by transfer, I do a discount of 2% on the amount. (I'm using "percentage of total amount" = 2) in the shipping plugin.
In this case, Virtuemart deducts 1.96€ instead of 2€.  > Is this a mistake or not? (In the same case vm2.0.8e make a discount of 2€)
2. In another order, I have an amount of € 1,000 for the purchase of 10 products. For being 10 products there is a discount of € 300 which is made with the plug istraxx quantity for quantity discounts.
And besides, if the payment is by transfer, 2% will be deducted from the amount that would be € 14 (2% of 700) is that correct?
This amount is also incorrect.
Am I doing something incoherent?
I don't know where´s the calculation error but clearly there is because previous releases made it properly.
Thank you very much for your time. And for make virtuemart, one great ecommerce platform.

Hello Milbo. Sorry that insists but I think this bug may be important.
1. I installed a clean version of joomla 2.5.14 and the latest version of vm (2.0.24) with example products.
2. I modified the price of one product to 100 € to do it more simple.
3. I created a payment method with 2% discount on the total amount.
The results are:
If I buy 1 product of € 100 and I select the payment method with discount, the amount should be € 98.00 (100  [2% 100]) isn't it?
But the result is: € 98.04 (100  [2% {1002}]) and the error increases when increasing amounts.
I tested with a 5% discount in the payment plug and the discount calculation that the system make is:
5% {TOTALAMOUNT5} instead of 5% of TOTALAMOUNT.
It would be interesting to check this calculation because it seems important.
I have not tried to install the plug istraxx quantity for quantity discounts and see if the calculation is correct with it
[attachment cleanup by admin]

Hi Milbo.
I've done several tests and found that the error occurs in changing from version 2.0.22a (working properly) to 2.022b (and miscalculates).
Have you found where the error is?
Best regards

I don't understand.
No one has detected the error in calculating the percentage discount on the payment plugin?
I think I'm going back to version VM2.0.22a. It was working properly. :(
regards

I experienced the same calculation error in version 2.0.24a with joomla 2.5
Is this bug already fixed?
In which version?
What is the last version without the bug?
Regards

Again Sardonic32, you did not read the post.
There is no error, your calculation is wrong. Your calculation is not having the payment costs itself calculated.
you wanna pay 100 euro?,... you have to pay for that 2 euro, yes? So you have to pay actually the fee for 102 euro, which is not 2 anylonger, because it is for 102 and not 100, right? So the fee must be calculated for 102, which is 2.04, so you have to pay 102,04 euro. You could now do the calculation again, but you wont see a difference anylonger due rounding.

Thanks Milbo for reply.
I don't have any tax.
Only payment type discount of 2% and the payment has no cost.
So if I make a order of 100 €, selecting my payment type I should pay 98€ (100€  (2%100)) and not 98,16 € (100(2%(98))).
In my opinion this should be the correct calculation (as made in version 2.0.22).
By the way why since version 2.0.22b the calculation method should be different?
Regards

THe calculation adds the shipping costs also.
I have added 10% at the "Percent of the total product amount"
and I get this screen.
The 10% is calculated at the total ammount of the order.
If I m not mistaken it should be 10% of the "product price result" + shipping = 2,36
[attachment cleanup by admin]

pcmillhouse,
it has nothing todo with your tax.
Your products costs 90 and your shipment 10. So you have to pay 100 euro, right? The payment has a fee of 2%, so if you have to pay for 100, you must pay with fee 102, right? But the costs for 102 are not anylonger just 2, the costs are still 2%, but of 102 now. => So the costs for the payment are now 2.04, alltogether 102.4.
It has nothing todo with the tax, only with the fee

THe calculation adds the shipping costs also.
of course
I have added 10% at the "Percent of the total product amount"
and I get this screen.
The 10% is calculated at the total ammount of the order.
If I m not mistaken it should be 10% of the "product price result" + shipping = 2,36
That is completly right. The payment is using the amount to PAY. Not any other fantasy number. You can have taxes, discounts, coupons and shipment, we should ignore that? If you have to pay to your payment processor 2.5% they do not care for which service. It is 2.5% for each kind of product.

Yes but at the plugin configuration at the description of "Percent of the total product amount" It sais "Shipment costs are not included"
minor mistake.
The calculation is almost right
At my example the total value is 23,69 x 10% = 2.37
So this added to the total is 23,69 + 2,37 =26,06
The 10% of this is 2,60 and not 2,63.
Am I wrong?

ok, I calculated again and it adds also the paypal ammount to the total before percentage.
It is right. sorry for the misunderstanding

Maybe we changed that already, but I see "percent of the total amount".

Thanks Milbo for your reply but I can't understand.
I've no tax and shipment cost.
I've only a payment discount of 2%.
If I make a order of 100 €, selecting my payment type I should pay 98€ (100€  (2%100)) and not 98,16 € (100(2%(98))).
In my opinion this should be the correct calculation (as made in version 2.0.22).
By the way why since version 2.0.22b the calculation method should be different?
Thanks for the support

Sorry for digging this up, but just like sardonic32 I need the discount for the standard payment method to be simply a percental discount to the final price. Say 100€ price, 2% discount > final price 98€.
Can someone tell me how and where I can adjust the calculation? I looked into the standard.php file, but I'm no expert on PHP and I couldn't figure out where to change the file.
Would be a great help!
Thanks