News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Weird calculation for a payment plugin

Started by man.of.earth, January 14, 2020, 16:14:17 PM

Previous topic - Next topic

man.of.earth

Hello,

I'm developing a payment plugin that uses tax per transaction and percent of the amount as commission.
I see that the automatic calculation, based on these two parameters, is slightly different from the calculation made using a calculator. By comparison, PayPal fixed method of calculation calculated the sum correctly.
Does any of you knows where to look, in order to fix this?

LE: I found the function setCartPrices in /administrator/components/com_virtuemart/plugins/vmpsplugin.php, which has the $progressive parameter set as true.
The simple method of calculationdefined there is
$cartTotalAmount=$method->cost_per_transaction + ($cartTotalAmountOrig) * (1 +($method->cost_percent_total * 0.01));
while I need this one
$cartTotalAmount=($cartTotalAmountOrig + $method->cost_per_transaction) * (1 +($method->cost_percent_total * 0.01));
Does anyone know how to call or make the correct calculation from the payment plugin, in order to be shown properly in frontend?
I'd like to ask the developers:
If I change the calculation formula in the file mentioned above, will this affect other functions of the shop?

Studio 42

You can certainly calculate a fixed fee and a percent in the payment method(eg. 2€ + 0.01% of the cart amount).
Why you want modify the core for this ?

man.of.earth

#2
Hello Studio 42,

I don't necessarily want to modify the core if I find another solution.
I find it somewhat odd that the simple formula (fixed tax + amount*(1+percent/100)) is not among those options. The only two options available there are ,,simple", using the formula
$cartTotalAmount=($cartTotalAmountOrig + $method->cost_per_transaction) * (1 +($method->cost_percent_total * 0.01))
and ,,progressive", using
$cartTotalAmount = ($cartTotalAmountOrig + $method->cost_per_transaction) / (1 -($method->cost_percent_total * 0.01))

Maybe a third option, simpler than these, could be defined there and made available:
$cartTotalAmount = $method->cost_per_transaction + $cartTotalAmountOrig * (1 + $method->cost_percent_total * 0.01)
I'm looking for a way to do that calculation inside the payment plugin. Looking to other payment plugins that do similar calculations, I found that they use a function called plgVmDisplayListFEPayment. I'm not sure yet how to redefine it inside the plugin, in order to calculate using the formula I need.