diff --git a/lib/tel_selections.rb b/lib/tel_selections.rb index 7e1f3bb17506b5e39fbbd908e2a9396a01e132bd..22cf73f3d591b3c18a9b8e4385330e022cfeb100 100644 --- a/lib/tel_selections.rb +++ b/lib/tel_selections.rb @@ -223,33 +223,6 @@ class TelSelections end end - def price - 0 - end - - # Creates and inserts transaction charging the customer - # for the phone number. If price <= 0 this is a noop. - # This method never checks customer balance. - # - # @param customer [Customer] the customer to charge - def charge(customer) - return if price <= 0 - - transaction(customer).insert - end - - # @param customer [Customer] the customer to charge - def transaction(customer) - Transaction.new( - customer_id: customer.customer_id, - transaction_id: - "#{customer.customer_id}-bill-#{@tel}-at-#{Time.now.to_i}", - amount: -price, - note: "One-time charge for number: #{formatted_tel}", - ignore_duplicate: false - ) - end - def initialize(tel) @tel = tel end @@ -263,6 +236,12 @@ class TelSelections formatted_tel end + def price + 0 + end + + def charge(*); end + class Option < Tn def initialize(full_number:, city:, state:, **) @tel = "+1#{full_number}" @@ -316,6 +295,35 @@ class TelSelections class LocalInventory < SimpleDelegator attr_reader :price + def initialize(tn, bandwidth_account_id, price: 0) + super(tn) + @bandwidth_account_id = bandwidth_account_id + @price = price || 0 + end + + # Creates and inserts transaction charging the customer + # for the phone number. If price <= 0 this is a noop. + # This method never checks customer balance. + # + # @param customer [Customer] the customer to charge + def charge(customer) + return if price <= 0 + + transaction(customer).insert + end + + # @param customer [Customer] the customer to charge + def transaction(customer) + Transaction.new( + customer_id: customer.customer_id, + transaction_id: + "#{customer.customer_id}-bill-#{@tel}-at-#{Time.now.to_i}", + amount: -price, + note: "One-time charge for number: #{formatted_tel}", + ignore_duplicate: false + ) + end + def self.fetch(tn, db: DB) db.query_defer("SELECT * FROM tel_inventory WHERE tel = $1", [tn]) .then { |rows| @@ -329,12 +337,6 @@ class TelSelections } end - def initialize(tn, bandwidth_account_id, price: 0) - super(tn) - @bandwidth_account_id = bandwidth_account_id - @price = price - end - def pending_value "LocalInventory/#{tel}/#{@bandwidth_account_id}/#{price}" end