~singpolyma/jmp-pay

77715a39c986445f98253bf275c759b5e95a81fa — Stephen Paul Weber 1 year, 6 months ago c09aa94
Include BTC amount and currency in notification
1 files changed, 7 insertions(+), 7 deletions(-)

M bin/process_pending_btc_transactions
M bin/process_pending_btc_transactions => bin/process_pending_btc_transactions +7 -7
@@ 196,19 196,19 @@ class Customer
		result || BigDecimal.new(0)
	end

	def add_btc_credit(txid, fiat_amount, cad_to_usd)
		add_transaction(txid, fiat_amount, "Bitcoin payment")
	def add_btc_credit(txid, btc_amount, fiat_amount, cad_to_usd)
		add_transaction(txid, btc_amount, fiat_amount, "Bitcoin payment")
		if (bonus = plan.bonus_for(fiat_amount, cad_to_usd))
			add_transaction("bonus_for_#{txid}", bonus, "Bitcoin payment bonus")
		end
		notify_btc_credit(txid, fiat_amount, bonus)
		notify_btc_credit(txid, btc_amount, fiat_amount, bonus)
	end

	def notify_btc_credit(txid, fiat_amount, bonus)
	def notify_btc_credit(txid, btc_amount, fiat_amount, bonus)
		tx_hash, = txid.split("/", 2)
		notify([
			"Your Bitcoin transaction has been added as ",
			"$#{'%.4f' % fiat_amount} ",
			"Your Bitcoin transaction of #{btc_amount.to_s('F')} BTC ",
			"has been added as $#{'%.4f' % fiat_amount} (#{plan.currency}) ",
			("+ $#{'%.4f' % bonus} bonus " if bonus),
			"to your account.\n(txhash: #{tx_hash})"
		].compact.join)


@@ 238,7 238,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, amount, cad_to_usd)
			customer.add_btc_credit(txid, btc, amount, cad_to_usd)
			customer.plan.activate_any_pending_plan!
			REDIS.hdel("pending_btc_transactions", txid)
		else