Skip to content

Instantly share code, notes, and snippets.

@rianrainey
Last active December 15, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rianrainey/5217779 to your computer and use it in GitHub Desktop.
Save rianrainey/5217779 to your computer and use it in GitHub Desktop.
=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