~singpolyma/jmp-pay

2872a5f99043925013333f3bb75558d17adcdba9 — Stephen Paul Weber 2 years ago e0ba65c
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

	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