Braintree can't charge for sub-cent, so make sure it doesn't try

Stephen Paul Weber created

Change summary

lib/low_balance.rb       | 4 ++--
test/test_low_balance.rb | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)

Detailed changes

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
 

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