Skip to content

Instantly share code, notes, and snippets.

@bhfailor
Last active August 29, 2015 13:57
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 bhfailor/9792836 to your computer and use it in GitHub Desktop.
Save bhfailor/9792836 to your computer and use it in GitHub Desktop.
Difference between transaction amount and charged amount due to FeeCalculator.service_fee which truncates the service fee
# rails console in the development environment
1.9.3p484 :009 > (10...40).each {|amt| puts "amount #{amt.to_f.round(2)} and charge #{(FeeCalculator.service_fee((amt.to_f-1.0)/1.05)+ (amt.to_f-1.0)/1.05).round(2)}"}
amount 10.0 and charge 9.99
amount 11.0 and charge 10.99
amount 12.0 and charge 12.0
amount 13.0 and charge 13.0
amount 14.0 and charge 13.99
amount 15.0 and charge 14.99
amount 16.0 and charge 16.0
amount 17.0 and charge 17.0
amount 18.0 and charge 17.99
amount 19.0 and charge 18.99
amount 20.0 and charge 20.0
amount 21.0 and charge 21.0
amount 22.0 and charge 22.0
amount 23.0 and charge 22.99
amount 24.0 and charge 23.99
amount 25.0 and charge 25.0
amount 26.0 and charge 26.0
amount 27.0 and charge 26.99
amount 28.0 and charge 27.99
amount 29.0 and charge 29.0
amount 30.0 and charge 30.0
amount 31.0 and charge 30.99
amount 32.0 and charge 31.99
amount 33.0 and charge 33.0
amount 34.0 and charge 34.0
amount 35.0 and charge 34.99
amount 36.0 and charge 35.99
amount 37.0 and charge 37.0
amount 38.0 and charge 38.0
amount 39.0 and charge 38.99
=> 10...40
1.9.3p484 :010 > (10...40).each {|amt| puts "amount #{amt.to_f.round(2)} and charge #{(FeeCalculator.service_fee_without_truncation((amt.to_f-1.0)/1.05)+ (amt.to_f-1.0)/1.05).round(2)}"}
amount 10.0 and charge 10.0
amount 11.0 and charge 11.0
amount 12.0 and charge 12.0
amount 13.0 and charge 13.0
amount 14.0 and charge 14.0
amount 15.0 and charge 15.0
amount 16.0 and charge 16.0
amount 17.0 and charge 17.0
amount 18.0 and charge 18.0
amount 19.0 and charge 19.0
amount 20.0 and charge 20.0
amount 21.0 and charge 21.0
amount 22.0 and charge 22.0
amount 23.0 and charge 23.0
amount 24.0 and charge 24.0
amount 25.0 and charge 25.0
amount 26.0 and charge 26.0
amount 27.0 and charge 27.0
amount 28.0 and charge 28.0
amount 29.0 and charge 29.0
amount 30.0 and charge 30.0
amount 31.0 and charge 31.0
amount 32.0 and charge 32.0
amount 33.0 and charge 33.0
amount 34.0 and charge 34.0
amount 35.0 and charge 35.0
amount 36.0 and charge 36.0
amount 37.0 and charge 37.0
amount 38.0 and charge 38.0
amount 39.0 and charge 39.0
=> 10...40
@bhfailor
Copy link
Author

The current FeeCalculator.service_fee truncates up to 1 cent from the service_fee which results in a credit card charge that is 1 cent different from the transaction amount about 50% of the time. Using FeeCalculator.service_fee_without_truncation eliminates the problem for ticketed events.

In particular, a transaction amount of $15.00 for the Taper Madness ticketed event results in $14.99 which is reproduced above as is the correct amount using the version without truncation.

The same could happen for registered events. Will check for that next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment