Change summary
lib/low_balance.rb | 22 ++++++++++++++++------
lib/transaction.rb | 4 ++++
2 files changed, 20 insertions(+), 6 deletions(-)
Detailed changes
@@ -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
@@ -57,6 +57,10 @@ class Transaction
end
end
+ def total
+ amount + bonus
+ end
+
def bonus
return BigDecimal(0) if amount <= 15