Bug in gateway fee calculation and flat fee

More
13 years 4 months ago #6195 by betc
Hi there,

I believe there is a miscalculation in the way the gateway fee is calculated. Right now, the code looks like this:
Code:
$row->amount*(1 + $config->convenience_fee/100)

This gives you the percent over the desired amount which seems right at first. However, the payment gateway will actually take the convenience fee percent of the total amount presented to them. So if you try to donate $100 with a 2.2% fee, JoomDonation will adjust it up to 102.20. But the gateway (PayPal in my case) will look at 102.20 and take out 2.2% of that, or $2.25. So the amount that the recipient ends up getting is 102.20 - 2.25 = 99.95.

To account for this, I think you want the calculation to instead look like this:
Code:
$data['gateway_amount'] = number_format(ceil(($row->amount/(1 - $config->convenience_fee/100)) * 100) / 100,2);

The ceil in there is to handle PayPal's (and I presume others') desire to round up to the whole cent.

Now the other thing I wanted to mention is that PayPal (not sure about others) also includes a flat fee per transaction, not just the percentage. It'd be great if we could set that through the UI. In my case, I've modified the above line (and the other places the fee is used) to look like this:
Code:
$data['gateway_amount'] = number_format(ceil(($row->amount/(1 - $config->convenience_fee/100) + 0.30) * 100) / 100,2);

(I added $.30 to the fee before doing the rounding)

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

Moderators: Mr. DamDũng Nguyễn Việt