Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
142
rated 0 times [  148] [ 6]  / answers: 1 / hits: 67534  / 12 Years ago, wed, may 16, 2012, 12:00:00

Sounds like an easy question, I know. I am literally stumped.



Here are two websites that have made the simple calculator:



http://thefeecalculator.com



http://ppcalc.com



I'm needing to calculate these PayPal's fees in my PHP application.



Here's what I got, say we wanted to be paid $30 even for membership fees. This is the function I'm using to calculate what we should charge to make up for it using PayPal's calculations (also described on both of the sites above): 2.9% of the transaction + $0.30.



function memfees()
{
$calc = round((30 * .029) + 30 + .30,2);
return $calc;
}


Test it here: http://matt.mw/junk/php/memfees.php
As you can see, it says 31.17.
Both of the other websites say it should be 31.20.
If I try $130.00, mine calculates to $134.07 and both of theirs calculate to $134.19.



What am I doing wrong?



Why am I using a Round function? Percentages cause some decimals to go past the hundredths place, and PayPal generates an error if there is more then 2 digits after the decimal. I thought people normally round money, (e.g. $31.6342 will be $31.63) but if that is the case, what am I doing wrong in my function? The amount that is off is further if there are large payments. This leads me to believe that something is wrong with the percentage portion.



Could you offer some help on this?



Thank you for your time.


More From » php

 Answers
82

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.


[#85551] Tuesday, May 15, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;