From 92cb054d53aaac6864a6a805d9cdd3919f4a38bc Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 17 Oct 2013 13:58:54 -0700 Subject: Some cleanup of code to deal with past due subscriptions. --- billing/app/controllers/billing_admin_controller.rb | 18 ++++++++++++++++-- billing/app/controllers/subscriptions_controller.rb | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'billing/app/controllers') diff --git a/billing/app/controllers/billing_admin_controller.rb b/billing/app/controllers/billing_admin_controller.rb index 419a937..cd6149f 100644 --- a/billing/app/controllers/billing_admin_controller.rb +++ b/billing/app/controllers/billing_admin_controller.rb @@ -2,14 +2,28 @@ class BillingAdminController < BillingBaseController before_filter :authorize_admin def show - @past_due_atleast_90_days = Braintree::Subscription.search do |search| + + br_atleast_90_days = Braintree::Subscription.search do |search| search.days_past_due >= 90 end + @past_due_atleast_90_days = braintree_resource_collection_to_array(br_atleast_90_days) - @all_past_due = Braintree::Subscription.search do |search| + br_all_past_due = Braintree::Subscription.search do |search| search.status.is Braintree::Subscription::Status::PastDue #cannot search by balance. end + @all_past_due = braintree_resource_collection_to_array(br_all_past_due) + + end + + private + + def braintree_resource_collection_to_array(braintree_resource_collection) + array = [] + braintree_resource_collection.each do |object| + array << object + end + array end end diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb index 0a1c733..01aaab4 100644 --- a/billing/app/controllers/subscriptions_controller.rb +++ b/billing/app/controllers/subscriptions_controller.rb @@ -1,7 +1,7 @@ class SubscriptionsController < BillingBaseController before_filter :authorize before_filter :fetch_subscription, :only => [:show, :destroy] - before_filter :only_admin_active_pending, :only => [:destroy] + before_filter :confirm_cancel_subscription, :only => [:destroy] before_filter :confirm_self_or_admin, :only => [:index] before_filter :confirm_no_pending_active_pastdue_subscription, :only => [:new, :create] # for now, admins cannot create or destroy subscriptions for others: @@ -41,8 +41,8 @@ class SubscriptionsController < BillingBaseController end - def only_admin_active_pending - access_denied unless admin? or ['Pending', 'Active'].include? @subscription.status + def confirm_cancel_subscription + access_denied unless view_context.allow_cancel_subscription(@subscription) end def confirm_no_pending_active_pastdue_subscription -- cgit v1.2.3