From 41c4a5a1ef20bf0497d06cbcdfbdec075f774d08 Mon Sep 17 00:00:00 2001 From: Kyle Drake Date: Sun, 1 Mar 2015 11:30:21 -0800 Subject: [PATCH] calculate the real revenue on stats after credit card fees --- app/stats.rb | 5 ++++- ext/float.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 ext/float.rb diff --git a/app/stats.rb b/app/stats.rb index d0deded3..0bf80618 100644 --- a/app/stats.rb +++ b/app/stats.rb @@ -56,7 +56,10 @@ get '/stats/?' do sub[:status] = 'active' plan = customer[:subscriptions][:data].first[:plan] - sub[:amount] = (plan[:amount] / 100.0).round(2) + sub[:amount_without_fees] = (plan[:amount] / 100.0).round(2) + sub[:percentage_fee] = (sub[:amount_without_fees]/(100/2.9)).ceil_to(2) + sub[:fixed_fee] = 0.30 + sub[:amount] = sub[:amount_without_fees] - sub[:percentage_fee] - sub[:fixed_fee] if(plan[:interval] == 'year') sub[:amount] = (sub[:amount] / 12).round(2) diff --git a/ext/float.rb b/ext/float.rb new file mode 100644 index 00000000..04d91322 --- /dev/null +++ b/ext/float.rb @@ -0,0 +1,13 @@ +class Float + def round_to(x) + (self * 10**x).round.to_f / 10**x + end + + def ceil_to(x) + (self * 10**x).ceil.to_f / 10**x + end + + def floor_to(x) + (self * 10**x).floor.to_f / 10**x + end +end