diff --git a/lib/customer.rb b/lib/customer.rb index ce37abe26c8d549f885177ee1e93313c13337bdb..84baa8bfea84cc2d5ca8903d31d1881eb77d3e91 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 b5628072ea91daab77e1e63ed2f9058fa2b0cbdd..2369e39e3a797739db5651289bcf672e140bcd3f 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 74865c3287809f05b27e9db17cff9aa880d63821..63f2700703ca867c54dc589211180305868adb6d 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 e9216e4fe86fdec063d1e3ce0f4385b0c22da9da..cacf650756c96abd3efae215ac3bf1c08bf2af11 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 dfb88d581ced2cb82cd1bab454de1afafcb9668d..a40dc7b43c222c2d19db87615424f327638192b0 160000 --- a/schemas +++ b/schemas @@ -1 +1 @@ -Subproject commit dfb88d581ced2cb82cd1bab454de1afafcb9668d +Subproject commit a40dc7b43c222c2d19db87615424f327638192b0