From 274677be9df4fa3f5332beed5c311e39a7a5d9ac Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 31 May 2023 15:16:43 -0500 Subject: [PATCH] Braintree can't charge for sub-cent, so make sure it doesn't try --- lib/low_balance.rb | 4 ++-- test/test_low_balance.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/low_balance.rb b/lib/low_balance.rb index 8bb9c12..dd116ea 100644 --- a/lib/low_balance.rb +++ b/lib/low_balance.rb @@ -95,7 +95,7 @@ class LowBalance def top_up_amount [ - (@target + @margin) - @customer.balance, + ((@target + @margin) - @customer.balance).round(2), @customer.auto_top_up_amount ].max end @@ -116,7 +116,7 @@ class LowBalance ) @message.body = "Automatic top-up transaction for " \ - "$#{top_up_amount} failed: #{e.message}" + "$#{'%.2f' % top_up_amount} failed: #{e.message}" 0 end diff --git a/test/test_low_balance.rb b/test/test_low_balance.rb index 45f52e7..26755ae 100644 --- a/test/test_low_balance.rb +++ b/test/test_low_balance.rb @@ -246,7 +246,7 @@ class LowBalanceTest < Minitest::Test nil, [Matching.new { |m| assert_equal( - "Automatic top-up transaction for $100 failed: test", + "Automatic top-up transaction for $100.00 failed: test", m.body ) }] @@ -254,7 +254,7 @@ class LowBalanceTest < Minitest::Test LowBalance::AutoTopUp::CreditCardSale.expect( :create, EMPromise.reject(RuntimeError.new("test")), - [@customer], amount: 100 + [@customer], amount: 100.to_d ) @auto_top_up.notify!.sync assert_mock @customer -- 2.38.5