From 2872a5f99043925013333f3bb75558d17adcdba9 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 8 Mar 2021 10:24:16 -0500 Subject: [PATCH] Switch to stepwise bonus factor breakpoints The max bonus is a bit smaller than the previous formula, but this one is perhaps more "explainable" and still matches current pricing. The breakpoints are done in native currency (not currency-converted) which means that CAD users get the next breakpoint "sooner" -- this is a small advantage to CAD users, who we want to encourage anyway. --- bin/process_pending_btc_transactions | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bin/process_pending_btc_transactions b/bin/process_pending_btc_transactions index 0c39f44f1e88a93e1f658efea8f623a47b62cfeb..c8d1cc420c604d2bf48091374fd4c23c01571826 100755 --- a/bin/process_pending_btc_transactions +++ b/bin/process_pending_btc_transactions @@ -102,9 +102,16 @@ class Plan @plan[:currency] end - def bonus_for(fiat_amount, cad_to_usd) - bonus = (0.050167 * fiat_amount) - (currency == :CAD ? 1 : cad_to_usd) - return bonus.round(4, :floor) if bonus > 0 + def bonus_for(fiat_amount) + return BigDecimal.new(0) if fiat_amount <= 15 + fiat_amount * case fiat_amount + when (15..29.99) + 0.01 + when (30..139.99) + 0.03 + else + 0.05 + end end def price @@ -195,9 +202,9 @@ class Customer result || BigDecimal.new(0) end - def add_btc_credit(txid, btc_amount, fiat_amount, cad_to_usd) + def add_btc_credit(txid, btc_amount, fiat_amount) add_transaction(txid, btc_amount, fiat_amount, "Bitcoin payment") - if (bonus = plan.bonus_for(fiat_amount, cad_to_usd)) + if (bonus = plan.bonus_for(fiat_amount)) add_transaction("bonus_for_#{txid}", bonus, "Bitcoin payment bonus") end notify_btc_credit(txid, btc_amount, fiat_amount, bonus) @@ -237,7 +244,7 @@ REDIS.hgetall("pending_btc_transactions").each do |(txid, customer_id)| customer = Customer.new(customer_id) if (plan = customer.plan) amount = btc * btc_sell_price.fetch(plan.currency).round(4, :floor) - customer.add_btc_credit(txid, btc, amount, cad_to_usd) + customer.add_btc_credit(txid, btc, amount) customer.plan.activate_any_pending_plan! REDIS.hdel("pending_btc_transactions", txid) else