Paypal plugin fee calculation

  • Posts: 5
  • Thank you received: 1
7 years 8 months ago #263717

I searched the forum and didn't see anything about this. The Paypal fee isn't being calculated correctly, because Paypal calculates the fee based on the total amount you send to them (which includes the fee), not on the base amount. For example, if your base amount is $30.00 and the Paypal formula is $0.30+2.2%, then it is incorrect to calculate 0.3+2.2%*(30) = 0.96 and then send $30.96 to Paypal. If you do, Paypal will charge $0.30+2.2%*($30.96) which is $0.98. So you end up with only $29.98 rather than $30.00. Does that make sense?

So the proper calculation would be:

( ( $30+$0.30) / 0.978) - $30

Or in the general case where B is the base amount we want to end up with, P is the price in the configuration menu, Q is the Percentage in the configuration menu and F is the calculated fee:

F = (B+P) / (1-Q) - B

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 8 months ago #263725

Hi,

That's right, PayPal calculate its fees the same way the payment fee HikaShop payment plugins will calculate using the price and percentage settings in them based on the total amount before the fee is added, but since the payment fee calculated by the payment system is added during the checkout, the PayPal fee will be based on the total amount after the HiakShop payment fee has been added. So if you put the same numbers in the percentage and price field of the PayPal payment method of HikaShop, the payment fee calculated will have a different value that the fee PayPal will charge.

It's not that this is "incorrect", it's just not meant to try to do what you want it to do.
Payment fees is a system general to all the payment plugins of HikaShop. And its goal is not to come up with the same fees as PayPal. The price and percentage fields of payment plugins are based on the percentage and price fields of the shipping plugins and the calculations are done the same way, for consistency.

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 1
7 years 8 months ago #263823

Thanks for your reply and I understand your reasoning, but still would like the calculation to match Paypal. Can you point me to what source code does the calculation so I can try to do my own mod?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 8 months ago #263824

Hi,

It is done by the line:

$methods[$k]->payment_price = $currencyClass->round(($price_all * (float)@$method->payment_params->payment_percentage / 100) + @$method->payment_price, $currencyClass->getRounding($currency,true));
in the file administrator/components/com_hikashop/class/payment.php

Beware that as explained before, changing that will change the calculations not only for the PayPal payment method but for all the payment methods on your website too.

The following user(s) said Thank You: johniac

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 1
7 years 8 months ago #264079

Here's the new code if anybody else wants it:

$methods[$k]->payment_price = $currencyClass->round((($price_all + @$method->payment_price) / (1-(float)@$method->payment_params->payment_percentage / 100))-$price_all,$currencyClass->getRounding($currency,true));

But now when I go to checkout, it's showing the correct fee next to the payment method, but the amount shown under "Payment fee" at the bottom (and added into the total) is still the old calculation. Is there another place I need to change the formula?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 8 months ago #264082

Hi,

Thanks !
It's probably just a cache thing. Logout and login again and that should clear it.

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 1
7 years 8 months ago #264145

No, it's definitely persisting. Anything else I can try?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 8 months ago #264163

Hi,

Then that line might need to be changed too:

$payment->payment_price = $currencyClass->round(($price_all * (float)@$payment->payment_params->payment_percentage / 100) + $payment_price, $currencyClass->getRounding($currency, true));
it's in the same file.

Please Log in or Create an account to join the conversation.

  • Posts: 5
  • Thank you received: 1
7 years 8 months ago #264303

That was it. It's perfect now. Thanks so much!

New code:

$payment->payment_price = $currencyClass->round((($price_all + $payment_price) / (1 - (float)@$payment->payment_params->payment_percentage / 100)) - $price_all,$currencyClass->getRounding($currency, true));

The following user(s) said Thank You: lesk

Please Log in or Create an account to join the conversation.

Time to create page: 0.067 seconds
Powered by Kunena Forum