Last active
December 15, 2015 06:39
-
-
Save rianrainey/5217779 to your computer and use it in GitHub Desktop.
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
=begin | |
This program calculates the amount to charge a client using Square as a payment processor. | |
The variation in cost depends largely on if the credit card is present. | |
=end | |
puts "--------------------------------------" | |
puts "---Welcome to the Square Calculator---" | |
puts "--------------------------------------" | |
# Output commas in large number | |
def comma_numbers(number, delimiter = ',') | |
number.to_s.reverse.gsub(%r{([0-9]{3}(?=([0-9])))}, "\\1#{delimiter}").reverse | |
end | |
# Get Amount Owed | |
puts "\tHow much do you want to get paid?" | |
amount = gets.chomp # Read in from command line | |
# Is CC Present | |
puts "\tIs the credit card physically present? Enter Y or N" | |
ccPresent = gets.chomp | |
if ccPresent.downcase == "y" # CC is Present | |
transactionFee = 0.0275 | |
total = amount.to_i / (1 - transactionFee) | |
else # CC is Absent | |
transactionFee = 0.035 | |
fixedFee = 0.15 | |
total = (amount.to_i + fixedFee) / (1 - transactionFee) | |
end | |
puts "The total amount to charge is: $#{ comma_numbers(total.round(2)) }" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment