diff --git a/lib/low_balance.rb b/lib/low_balance.rb index cf00ec6d169bfe194b1c29a7d88f1f408059a569..e5233db05f039ee206e568186b059661407cdb1a 100644 --- a/lib/low_balance.rb +++ b/lib/low_balance.rb @@ -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 diff --git a/lib/transaction.rb b/lib/transaction.rb index c88aa11c3d42c3906679451ccedb3d40b43a8c9f..5d55f8f5bed41c168815044e60bd66e93451d9c8 100644 --- a/lib/transaction.rb +++ b/lib/transaction.rb @@ -57,6 +57,10 @@ class Transaction end end + def total + amount + bonus + end + def bonus return BigDecimal(0) if amount <= 15