Skip to content

Instantly share code, notes, and snippets.

@arrowtype
Last active February 28, 2023 17:36
Show Gist options
  • Save arrowtype/1df07b15b9b9500306d142fec79fb1e2 to your computer and use it in GitHub Desktop.
Save arrowtype/1df07b15b9b9500306d142fec79fb1e2 to your computer and use it in GitHub Desktop.
A quick Python script to compute Stripe fees, for invoicing customers
"""
A simple Python3 script to take in a project price, and output the fee Stripe will charge on an invoice.
See also:
https://support.stripe.com/questions/passing-the-stripe-fee-on-to-customers
USAGE - Call the script with Python3 and its path, and give your project/goal price as an arg:
python3 calculate-stripe-fee.py 95.00
(Leave out the "$" sign from your project price)
You could alternatively call this file as a function from within a .bashprofile or similar:
stripe () {
python3 <PATH_TO_WHEREVER_YOU_STORE_THIS_FILE>/calculate-stripe-fee.py $1
}
...and then have a little command line tool available like the following:
▶ stripe 95
Assuming a Stripe fee of 0.029% + $0.3...
Your goal: $95.00
Stripe fee: $3.15
Total to charge: $98.15
"""
import sys
# stripe fee (https://stripe.com/pricing)
flatFee = 0.30
percentageFee = 0.029
# check if the user has included a project price, exit if not
if len(sys.argv) == 1:
print()
print("⚠️ You must include your project price / goal price")
exit()
# gets the input of the goal pricing
projectPrice = sys.argv[1]
def calculateStripeCharge(goal, flatFee=0.30, percentageFee=0.029):
"""
Simple function to determine Stripe fee, and return info as formatted currency strings.
"""
goal = float(goal)
total = round((goal + flatFee) / (1 - percentageFee), 2)
fee = round(total - goal, 2)
return(f"${goal:.2f}", f"${total:.2f}", f"${fee:.2f}")
pricing = calculateStripeCharge(projectPrice, flatFee=flatFee, percentageFee=percentageFee)
print()
print(f"Assuming a Stripe fee of {percentageFee}% + ${flatFee:.2f}...")
print()
print(f"Your goal: {pricing[0].rjust(12)}")
print(f"Stripe fee: {pricing[2].rjust(12)}")
print(f"Total to charge: {pricing[1].rjust(12)}")
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment