## ~singpolyma/jmp-pay

2872a5f99043925013333f3bb75558d17adcdba9 — Stephen Paul Weber 2 years ago
```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.
```
```1 files changed, 13 insertions(+), 6 deletions(-)

M bin/process_pending_btc_transactions
```
`M bin/process_pending_btc_transactions => bin/process_pending_btc_transactions +13 -6`
```@@ 102,9 102,16 @@ class Plan
@plan[:currency]
end

-		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

-		if (bonus = plan.bonus_for(fiat_amount, cad_to_usd))
+		if (bonus = plan.bonus_for(fiat_amount))
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)