Created
November 14, 2012 02:50
-
-
Save taeber/4069988 to your computer and use it in GitHub Desktop.
PHP implementation of PayPal fee calculator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/// Start of a PayPal fee calculator that I'll probably never finish. :-[ | |
/* | |
Given: | |
total(cost, fee) := cost + fee(cost) | |
fee(cost) := F + P*cost | |
F := $0.30 | |
P := 2.9% | |
Find: | |
Total amount to charge so that the customer pays all fees. | |
paid - fees >= cost | |
fees := fee(paid) = F + P*paid | |
paid - (F + P - paid) | |
paid*(1-P) - F >= cost | |
paid >= (cost + F)/(1-P) | |
*/ | |
/** | |
* Calculates the total amount to charge based a customer based on a given | |
* sub-total amount. | |
*/ | |
function total($subtotal, $fees) | |
{ | |
// total := subtotal + fees | |
return bcadd($subtotal, $fees($subtotal)); | |
} | |
function paypal_fees($subtotal, $flat_fee = "0.30", $variable_rate = "0.029") | |
{ | |
// fees := F + P * subtotal | |
// subtotal + F | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment