From fd09daddda8d9dcbcd4c6b13a8f49a625f6be8ab Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 3 May 2023 10:37:06 -0500 Subject: [PATCH] Show pending status for not yet activated users --- lib/customer.rb | 2 +- lib/customer_info.rb | 2 +- lib/customer_plan.rb | 12 ++++++++++-- lib/customer_repo.rb | 4 +++- schemas | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/customer.rb b/lib/customer.rb index ce37abe..84baa8b 100644 --- a/lib/customer.rb +++ b/lib/customer.rb @@ -25,7 +25,7 @@ class Customer :currency, :merchant_account, :plan_name, :minute_limit, :message_limit, :monthly_overage_limit, :activation_date, :expires_at, :monthly_price, :save_plan!, :auto_top_up_amount, - :extend_plan + :extend_plan, :status def_delegators :@sgx, :deregister!, :register!, :registered?, :set_ogm_url, :fwd, :transcription_enabled def_delegators :@usage, :usage_report, :message_usage, :incr_message_usage, diff --git a/lib/customer_info.rb b/lib/customer_info.rb index b562807..2369e39 100644 --- a/lib/customer_info.rb +++ b/lib/customer_info.rb @@ -73,7 +73,7 @@ class PlanInfo end def status - customer.active? ? "Active" : "Expired" + customer.status.to_s.capitalize end def remaining_included_calling_credit diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index 74865c3..63f2700 100644 --- a/lib/customer_plan.rb +++ b/lib/customer_plan.rb @@ -36,7 +36,7 @@ class CustomerPlan self.for( customer_id, **kwargs.slice( - :plan_name, :expires_at, :parent_customer_id, + :plan_name, :expires_at, :parent_customer_id, :pending, :auto_top_up_amount, :monthly_overage_limit ) ) @@ -48,13 +48,14 @@ class CustomerPlan expires_at: Time.now, auto_top_up_amount: 0, monthly_overage_limit: 0, - parent_customer_id: nil + pending: false, parent_customer_id: nil ) @customer_id = customer_id @plan = plan || OpenStruct.new @expires_at = expires_at @auto_top_up_amount = auto_top_up_amount || 0 @monthly_overage_limit = monthly_overage_limit || 0 + @pending = pending @parent_customer_id = parent_customer_id end @@ -62,6 +63,13 @@ class CustomerPlan plan_name && @expires_at > Time.now end + def status + return :active if active? + return :pending if @pending + + :expired + end + def with_plan_name(plan_name) self.class.new( @customer_id, diff --git a/lib/customer_repo.rb b/lib/customer_repo.rb index e9216e4..cacf650 100644 --- a/lib/customer_repo.rb +++ b/lib/customer_repo.rb @@ -177,7 +177,9 @@ protected end SQL = <<~SQL - SELECT COALESCE(balance,0) AS balance, plan_name, expires_at, parent_customer_id + SELECT + COALESCE(balance,0) AS balance, plan_name, expires_at, + parent_customer_id, pending FROM customer_plans LEFT JOIN balances USING (customer_id) WHERE customer_id=$1 LIMIT 1 SQL diff --git a/schemas b/schemas index dfb88d5..a40dc7b 160000 --- a/schemas +++ b/schemas @@ -1 +1 @@ -Subproject commit dfb88d581ced2cb82cd1bab454de1afafcb9668d +Subproject commit a40dc7b43c222c2d19db87615424f327638192b0 -- 2.45.2