Skip to content

Instantly share code, notes, and snippets.

@terribleplan
Created August 1, 2016 17:40
Show Gist options
  • Save terribleplan/85183e6f0d7c49f52b3ed82e4e40359f to your computer and use it in GitHub Desktop.
Save terribleplan/85183e6f0d7c49f52b3ed82e4e40359f to your computer and use it in GitHub Desktop.
CC/Paypal Fee Calculator
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