diff --git a/lib/registration.rb b/lib/registration.rb index cd2306540e3287ee39705a4df5a706e0208b9f73..8d0e4b94cf5c89047dba5afdb21134b3931d6caf 100644 --- a/lib/registration.rb +++ b/lib/registration.rb @@ -259,10 +259,16 @@ class Registration @kinds ||= {} end - def self.for(iq, customer, tel, finish: Finish, maybe_bill: MaybeBill) + def self.for( + iq, customer, tel, + finish: Finish, maybe_bill: MaybeBill, + price: CONFIG[:activation_amount] + tel.price + ) kinds.fetch(iq.form.field("activation_method")&.value&.to_s&.to_sym) { raise "Invalid activation method" - }.call(customer, tel, finish: finish, maybe_bill: maybe_bill) + }.call( + customer, tel, finish: finish, maybe_bill: maybe_bill, price: price + ) end class CryptoPaymentMethod @@ -278,11 +284,14 @@ class Registration raise NotImplementedError, "Subclass must implement" end - def initialize(customer, tel, maybe_bill: MaybeBill, **) + def initialize( + customer, tel, + price: CONFIG[:activation_amount] + tel.price, ** + ) @customer = customer @customer_id = customer.customer_id @tel = tel - @maybe_bill = maybe_bill + @price = price end def save @@ -294,7 +303,7 @@ class Registration def form(rate, addr) FormTemplate.render( reg_form_name, - amount: @maybe_bill.price(@tel) / rate, + amount: @price / rate, addr: addr ) end @@ -385,12 +394,6 @@ class Registration yield customer end end - - # @return [Float] The price of the number + activation fee - # @param [TelSelection::ChooseTel::Tn] tel The phone number to charge - def self.price(tel) - CONFIG[:activation_amount] + tel.price - end end class JustCharge @@ -399,21 +402,21 @@ class Registration end def call; end - - def self.price(tel) - tel.price - end end class CreditCard Payment.kinds[:credit_card] = method(:new) - def initialize(customer, tel, finish: Finish, maybe_bill: MaybeBill) + def initialize( + customer, tel, + finish: Finish, maybe_bill: MaybeBill, + price: CONFIG[:activation_amount] + tel.price + ) @customer = customer @tel = tel @finish = finish @maybe_bill = maybe_bill.new(customer, tel, finish: finish) - @price = maybe_bill.price(tel) + @price = price end def oob(reply) @@ -519,17 +522,20 @@ class Registration class Mail Payment.kinds[:mail] = method(:new) - def initialize(customer, tel, maybe_bill: MaybeBill, **) + def initialize( + customer, tel, + price: CONFIG[:activation_amount] + tel.price, ** + ) @customer = customer @tel = tel - @maybe_bill = maybe_bill + @price = price end def form FormTemplate.render( "registration/mail", currency: @customer.currency, - price: @maybe_bill.price(@tel), + price: @price, **onboarding_extras ) end @@ -613,7 +619,8 @@ class Registration }.then { |iq| Payment.for( iq, @customer, @tel, - maybe_bill: ::Registration::Payment::JustCharge + maybe_bill: ::Registration::Payment::JustCharge, + price: @tel.price ) }.then(&:write) end