actually bill for local numbers

Phillip Davis created

Change summary

lib/tel_selections.rb | 68 +++++++++++++++++++++++---------------------
1 file changed, 35 insertions(+), 33 deletions(-)

Detailed changes

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