Show pending status for not yet activated users

Stephen Paul Weber created

Change summary

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(-)

Detailed changes

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,

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

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,

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

schemas 🔗

@@ -1 +1 @@
-Subproject commit dfb88d581ced2cb82cd1bab454de1afafcb9668d
+Subproject commit a40dc7b43c222c2d19db87615424f327638192b0