From 0702e2e82fad580c34e624bb7014fa8a2969ea32 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 30 Jan 2024 14:24:10 -0500 Subject: [PATCH] Fix transitional account calling --- lib/call_attempt.rb | 7 +++++-- lib/call_attempt_repo.rb | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/call_attempt.rb b/lib/call_attempt.rb index 645a656a550f041c7e6d699544f1297acb64f31c..97cf7c36d74afd7ca4a3592808fb95a96252fb29 100644 --- a/lib/call_attempt.rb +++ b/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 { diff --git a/lib/call_attempt_repo.rb b/lib/call_attempt_repo.rb index ab1a6b402f192d2475c1949718197fb5c2d7038c..0c9b268ee8aeba8341cde3a09a7cd1329b260a7a 100644 --- a/lib/call_attempt_repo.rb +++ b/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