~singpolyma/sgx-jmp

310c4870521216074c62d086605ccb72fbff77e8 — Stephen Paul Weber 9 months ago 3e70351
LowBalance returns amount added, if any
2 files changed, 20 insertions(+), 6 deletions(-)

M lib/low_balance.rb
M lib/transaction.rb
M lib/low_balance.rb => lib/low_balance.rb +16 -6
@@ 37,6 37,7 @@ class LowBalance
			"Your balance of $#{'%.4f' % @customer.balance} is low." \
			"#{btc_addresses_for_notification}"
		@customer.stanza_to(m)
		EMPromise.resolve(0)
	end

	def btc_addresses_for_notification


@@ 62,20 63,29 @@ class LowBalance
			end
		end

		def failed(e)
			@message.body =
				"Automatic top-up transaction for " \
				"$#{@customer.auto_top_up_amount} failed: #{e.message}"
			0
		end

		def notify!
			sale.then { |tx|
				@message.body =
					"Automatic top-up has charged your default " \
					"payment method and added #{tx} to your balance."
			}.catch { |e|
				@message.body =
					"Automatic top-up transaction for " \
					"$#{@customer.auto_top_up_amount} failed: #{e.message}"
			}.then { @customer.stanza_to(@message) }
				tx.total
			}.catch(&method(:failed)).then { |amount|
				@customer.stanza_to(@message)
				amount
			}
		end
	end

	class Locked
		def notify!; end
		def notify!
			EMPromise.resolve(0)
		end
	end
end

M lib/transaction.rb => lib/transaction.rb +4 -0
@@ 57,6 57,10 @@ class Transaction
		end
	end

	def total
		amount + bonus
	end

	def bonus
		return BigDecimal(0) if amount <= 15