Change summary
lib/registration.rb | 12 +++---------
lib/sim_kind.rb | 7 +++++++
lib/sim_order.rb | 1 -
test/test_registration.rb | 4 ++--
4 files changed, 12 insertions(+), 12 deletions(-)
Detailed changes
@@ -81,14 +81,8 @@ class Registration
class DataOnly
def self.for(customer, sim_kind)
- cfg = sim_kind.cfg(customer.currency)
- log.debug(
- "DataOnly#for",
- cfg: cfg,
- customer_balance: customer.balance,
- customer_currency: customer.currency
- )
- unless cfg && customer.balance >= cfg[:price]
+ price = sim_kind.price_dollars(customer.currency)
+ unless price && customer.balance >= price
return PayForSim.new(customer, sim_kind)
end
@@ -827,7 +821,7 @@ class Registration
end
end
- def initialize(customer, tel, error: nil, old: nil, db:)
+ def initialize(customer, tel, db:, error: nil, old: nil)
@customer = customer
@tel = tel
@error = error
@@ -21,4 +21,11 @@ class SIMKind
def cfg(currency)
CONFIG.dig(:sims, @variant.to_sym, currency)
end
+
+ def price_dollars(currency)
+ cfg = cfg(currency)
+ return nil unless cfg
+
+ cfg[:price] / 100.to_d
+ end
end
@@ -38,7 +38,6 @@ class SIMOrder
def self.for(customer, price:, **kwargs)
price = price.to_i / 100.to_d
- log.debug("SIMOrder.for", balance: customer.balance, price: price)
return new(customer, price: price, **kwargs) if customer.balance >= price
LowBalance::AutoTopUp.for(customer, price).then do |top_up|
@@ -2223,7 +2223,7 @@ class RegistrationTest < Minitest::Test
class DataOnlyTest < Minitest::Test
def setup
- @customer = customer(plan_name: "test_usd").with_balance(1000)
+ @customer = customer(plan_name: "test_usd").with_balance(5)
@sim_kind = SIMKind.new("sim")
end
@@ -2374,7 +2374,7 @@ class RegistrationTest < Minitest::Test
{ var: "activation_method", value: "credit_card" }
]
- reloaded_customer = @customer.with_balance(100).with_plan("test_usd")
+ reloaded_customer = @customer.with_balance(4).with_plan("test_usd")
result = execute_command do |exe|
payment = Minitest::Mock.new