Last active
May 11, 2016 02:57
-
-
Save erichelgeson/fdd6a72977050271806f2a156b55b041 to your computer and use it in GitHub Desktop.
Estimate Stripe fees to pass on
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
| // based on https://support.stripe.com/questions/can-i-charge-my-stripe-fees-to-my-customers | |
| class StripeFees { | |
| static BigDecimal creditCardPct = 0.029 | |
| static Integer creditCardFixed = 30 // cents | |
| static BigDecimal achPct = 0.008 | |
| static Integer achMaxFee = 500 // cents | |
| /** | |
| * @param goalCents The amount of money, in cents, you would like to end up in your account | |
| * @param feeSplit Amount to divide the fees by, eg you'd like to split the fee 2 ways | |
| * @return Amount you should charge in stripe to split the fees | |
| */ | |
| static Integer CreditCard(Integer goalCents, Integer feeSplit = 0) { | |
| if(feeSplit == 0) { | |
| return goalCents | |
| } else { | |
| return Math.round(( goalCents + (creditCardFixed / feeSplit )) / ( 1 - ( creditCardPct / feeSplit ))) | |
| } | |
| } | |
| /** | |
| * @param goalCents The amount of money you would like to end up in your account in cents | |
| * @param feeSplit Amount to divide the fees by, eg you'd like to pay 1/N of the fee | |
| * @return Amount you should charge in stripe to split the fees | |
| */ | |
| static Integer ACH(Integer goalCents, Integer feeSplit = 0) { | |
| if(feeSplit == 0) { | |
| return goalCents | |
| } else { | |
| def newGoal = Math.round( goalCents / ( 1 - ( achPct / feeSplit ))) | |
| return (newGoal - goalCents > achMaxFee) ? goalCents + achMaxFee : newGoal | |
| } | |
| } | |
| } | |
| def totalBill = 10000 // $100.00 | |
| println "ACH on $totalBill they pay ${StripeFees.ACH(10000,1) - 10000} cents" | |
| println "CC on $totalBill they pay ${StripeFees.CreditCard(10000,1) - 10000} cents" | |
| println "CC split by 2 on $totalBill they pay ${StripeFees.CreditCard(10000,2) - 10000} cents" | |
| println "CC we pay fee on $totalBill they pay ${StripeFees.CreditCard(10000,0) - 10000} cents" | |
| // ACH on 10000 they pay 81 cents | |
| // CC on 10000 they pay 330 cents | |
| // CC split by 2 on 10000 they pay 162 cents | |
| // CC we pay fee on 10000 they pay 0 cents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment