Last active
April 14, 2018 08:04
-
-
Save aslamhadi/88204c31f844b1acfb42d40d24e4358b to your computer and use it in GitHub Desktop.
Simple script to calculate Paypal fee
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
#!/usr/bin/env python | |
import sys | |
from math import ceil | |
def ceil_two_digits(amount): | |
return (ceil(amount * 100) / 100.0) | |
def calculate_invoice(invoice_amount): | |
""" Calculate paypal fee (4.4%) + 0.3 USD""" | |
total_amount = 100 * invoice_amount / 95.6 | |
paypal_fee = total_amount - invoice_amount + 0.3 # there is an additional fee 0.3 USD. | |
# ceil the amount | |
paypal_fee = ceil_two_digits(paypal_fee) | |
total_amount = ceil_two_digits(invoice_amount + paypal_fee) | |
return paypal_fee, total_amount | |
if __name__ == "__main__": | |
""" example: python paypal.py 431.75 """ | |
if len(sys.argv) < 2: | |
print("Please add your invoice amount => 'python paypal.py 431.75' ") | |
sys.exit() | |
invoice_amount = float(sys.argv[1]) | |
paypal_fee, total_amount = calculate_invoice(invoice_amount) | |
print("Invoice amount: {}".format(invoice_amount)) | |
print("Paypal Fee: {}".format(paypal_fee)) | |
print("Total Invoice: {}".format(total_amount)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment