How do I calculate PayPal's fees (2.9% + .30) on a fixed number?

Your function does seem strange. To break it down, PayPal is charging a fixed rate of $.30, and adding a transaction percentage fee of 2.9%.

The formula for this is to add the $.30 and then divide by the percentage difference (100% - 2.9%), which will give you the amount prior to the actual reduction by PayPal.

function memfees($amount)
{
    $amount += .30;
    return $amount / (1 - .029);
}

You can round and float that as you wish.


Because you're thinking about it the wrong way around.

You don't charge $30, you charge $31.20. Paypal takes the transaction fee (2.9%) off of that and then takes $0.30 from the result:

  $31.20
*  0.971 (1 - 2.9%)
  ------
  $30.2952
- $00.30
  ------
  $29.9952

So you have to reverse this process, i.e. add $0.3 to your total and divide by 0.971.


Here's a good mathematical explanation of how this works. We have this number, x, which we want to charge a credit card. We don't know what this number is, but we know that when we subtract 30 cents and subtract 2.9% of x, we get y, which is the amount of money we take home:

y = x - x * .029 - .3

We know y, because we know what amount we want to take home. Say, we wanted to take home $100, then y = 100. But what's x?

y = x - x * .029 - .3
y + .3 = x - x * .029
         = x(1 - .029)
(y + .3) / (1 - .029) = x
x = (y + .3) / .971

Note: because x - x * .029 can be written as x * 1 - x * .029 then all need to do is just use distributive property and we come up with x(1 - .029)

So we come up with the formula:

x = (y + .3) / .971

Which defines this infamous number, x. Also, it answers our question; What amount should I charge a card in order to cover the transaction fee and not fall short of the amount we want to take home? Well, all we need to do is fill in the take home amount, which is y:

x = (100 + .3) / .971
x = ~103.30

I hope this helps clarify.