Fix transitional account calling

Stephen Paul Weber created

Change summary

lib/call_attempt.rb      | 7 +++++--
lib/call_attempt_repo.rb | 3 ++-
2 files changed, 7 insertions(+), 3 deletions(-)

Detailed changes

lib/call_attempt.rb 🔗

@@ -7,7 +7,8 @@ require_relative "low_balance"
 
 class CallAttempt
 	def self.for(customer:, usage:, **kwargs)
-		credit = [customer.minute_limit.to_d - usage, 0].max + customer.balance
+		credit = [(customer.minute_limit&.to_d || 100) - usage, 0].max +
+		         customer.balance
 		@kinds.each do |kind|
 			ca = kind.call(
 				customer: customer, usage: usage, credit: credit,
@@ -20,7 +21,9 @@ class CallAttempt
 	end
 
 	def self.limits(customer, usage, credit, rate:, **)
-		return {} unless customer && usage && rate && rate.positive?
+		unless customer&.minute_limit && usage && rate && rate.positive?
+			return { limit_remaining: 100, max_minutes: 100 }
+		end
 
 		can_use = customer.minute_limit.to_d + customer.monthly_overage_limit
 		{

lib/call_attempt_repo.rb 🔗

@@ -84,7 +84,8 @@ protected
 	end
 
 	def find_rate(plan_name, other_tel, direction)
-		promise = db.query_one(<<~SQL, plan_name, other_tel, direction)
+		# || CAD temporary for transitional accounts
+		promise = db.query_one(<<~SQL, plan_name || "CAD", other_tel, direction)
 			SELECT rate FROM call_rates
 			WHERE
 				plan_name=$1 AND