Created
August 1, 2016 17:40
-
-
Save terribleplan/85183e6f0d7c49f52b3ed82e4e40359f to your computer and use it in GitHub Desktop.
CC/Paypal Fee Calculator
This file contains 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
const FIXED_FEE = 30; //The number of cents you are charged per transaction | |
const PERCENTAGE_FEE = .029; //The percentage of the transaction your processor will take in addition to the fixed fee | |
/** | |
* This function calculates how much you need to charge your customer to recoup the cost of transaction fees | |
* | |
* @param targetPrice The target number of cents you want to earn | |
* @return The number of cents that you want to actually charge the customer, including fractions of a cent | |
*/ | |
const calculateFee = (targetPrice) => (targetPrice + FIXED_FEE) / (1 - PERCENTAGE_FEE; | |
/** | |
* This function calculates how much you need to charge your customer to recoup the cost of transaction fees | |
* | |
* Note that this will round to the nearest cent in your favor. | |
* @param targetPrice The target number of cents you want to earn | |
* @return The number of cents that you want to actually charge the customer, rounded up to the nearest whole cent. | |
*/ | |
module.exports = (targetPrice) => Math.ceil(calculateFee(targetPrice)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment