summaryrefslogtreecommitdiff
path: root/billing/app/controllers
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2013-10-18 00:18:03 -0700
committerazul <azul@riseup.net>2013-10-18 00:18:03 -0700
commit221532448ba4c435427ad2b5b3eca729b352c354 (patch)
tree1caa069380cb075155e97755d3d94d1274b4a9ea /billing/app/controllers
parentbf3b59e6807c8e4789b97232c7416093b07cccdf (diff)
parent92cb054d53aaac6864a6a805d9cdd3919f4a38bc (diff)
Merge pull request #98 from jessib/feature/billing-past-due-subscriptions
Feature/billing past due subscriptions
Diffstat (limited to 'billing/app/controllers')
-rw-r--r--billing/app/controllers/billing_admin_controller.rb29
-rw-r--r--billing/app/controllers/subscriptions_controller.rb19
2 files changed, 44 insertions, 4 deletions
diff --git a/billing/app/controllers/billing_admin_controller.rb b/billing/app/controllers/billing_admin_controller.rb
new file mode 100644
index 0000000..cd6149f
--- /dev/null
+++ b/billing/app/controllers/billing_admin_controller.rb
@@ -0,0 +1,29 @@
+class BillingAdminController < BillingBaseController
+ before_filter :authorize_admin
+
+ def show
+
+ 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)
+
+ 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 7689f35..01aaab4 100644
--- a/billing/app/controllers/subscriptions_controller.rb
+++ b/billing/app/controllers/subscriptions_controller.rb
@@ -1,7 +1,9 @@
class SubscriptionsController < BillingBaseController
before_filter :authorize
before_filter :fetch_subscription, :only => [:show, :destroy]
- before_filter :confirm_no_active_subscription, :only => [:new, :create]
+ 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:
before_filter :confirm_self, :only => [:new, :create]
@@ -16,6 +18,7 @@ class SubscriptionsController < BillingBaseController
def create
@result = Braintree::Subscription.create( :payment_method_token => params[:payment_method_token], :plan_id => params[:plan_id] )
+ #if you want to test pastdue, can add :price => '2001', :trial_period => true,:trial_duration => 1,:trial_duration_unit => "day" and then wait a day
end
def destroy
@@ -38,10 +41,14 @@ class SubscriptionsController < BillingBaseController
end
- def confirm_no_active_subscription
+ def confirm_cancel_subscription
+ access_denied unless view_context.allow_cancel_subscription(@subscription)
+ end
+
+ def confirm_no_pending_active_pastdue_subscription
@customer = Customer.find_by_user_id(@user.id)
- if subscription = @customer.subscriptions # will return active subscription, if it exists
- redirect_to subscription_path(subscription.id), :notice => 'You already have an active subscription'
+ if subscription = @customer.subscriptions # will return pending, active or pastdue subscription, if it exists
+ redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription'
end
end
@@ -49,4 +56,8 @@ class SubscriptionsController < BillingBaseController
@user == current_user
end
+ def confirm_self_or_admin
+ access_denied unless confirm_self or admin?
+ end
+
end