summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjessib <jessib@riseup.net>2013-10-08 14:33:02 -0700
committerjessib <jessib@riseup.net>2013-10-08 14:33:02 -0700
commit4e471f6b35c012d2825f6be19e24ecd5fef8d636 (patch)
tree0b420eba4e89094e0f1407aa09094d40b068fa5b
parent8b378d916caeaf7fd4b1da2aea45eab4b0ccbb39 (diff)
Consider pending & past due subscriptions as 'active' in the sense that they should prevent one from adding a new subscription.
-rw-r--r--billing/app/controllers/subscriptions_controller.rb6
-rw-r--r--billing/app/models/customer.rb6
-rw-r--r--billing/app/views/customer/show.html.haml2
-rw-r--r--billing/app/views/subscriptions/index.html.haml8
-rw-r--r--billing/app/views/subscriptions/show.html.haml2
-rw-r--r--billing/config/locales/en.yml3
6 files changed, 14 insertions, 13 deletions
diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb
index 7689f35..4758adb 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 :confirm_no_active_subscription, :only => [:new, :create]
+ 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]
@@ -38,10 +38,10 @@ class SubscriptionsController < BillingBaseController
end
- def confirm_no_active_subscription
+ 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'
+ redirect_to user_subscription_path(@user, subscription.id), :notice => 'You already have a subscription'
end
end
diff --git a/billing/app/models/customer.rb b/billing/app/models/customer.rb
index f01c300..1acc7a5 100644
--- a/billing/app/models/customer.rb
+++ b/billing/app/models/customer.rb
@@ -40,19 +40,19 @@ class Customer < CouchRest::Model::Base
end
# based on 2nd parameter, either returns the single active subscription (or nil if there isn't one), or an array of all subsciptions
- def subscriptions(braintree_data=nil, only_active=true)
+ def subscriptions(braintree_data=nil, only_pending_active_pastdue=true)
self.with_braintree_data!
return unless has_payment_info?
subscriptions = []
self.default_credit_card.subscriptions.each do |sub|
- if only_active and sub.status == 'Active'
+ if only_pending_active_pastdue and ['Pending', 'Active','Past Due'].include? sub.status
return sub
else
subscriptions << sub
end
end
- only_active ? nil : subscriptions
+ only_pending_active_pastdue ? nil : subscriptions
end
end
diff --git a/billing/app/views/customer/show.html.haml b/billing/app/views/customer/show.html.haml
index 243bd3b..562dc4b 100644
--- a/billing/app/views/customer/show.html.haml
+++ b/billing/app/views/customer/show.html.haml
@@ -18,7 +18,7 @@
= render :partial => "subscriptions/subscription_details", :locals => {:subscription => @active_subscription}
- else
%p
- = t(:no_active_subscription)
+ = t(:no_relevant_subscription)
- if current_user == @user
%p
.form-actions
diff --git a/billing/app/views/subscriptions/index.html.haml b/billing/app/views/subscriptions/index.html.haml
index 87771e5..3d4e8fd 100644
--- a/billing/app/views/subscriptions/index.html.haml
+++ b/billing/app/views/subscriptions/index.html.haml
@@ -1,8 +1,8 @@
%h2=t :all_subscriptions
-- active = false
+- pending_active_pastdue = false
- @subscriptions.each do |s|
- - if s.status == 'Active'
- - active = true
+ - if ['Pending', 'Active','Past Due'].include? s.status
+ - pending_active_pastdue = true
= render :partial => "subscription_details", :locals => {:subscription => s}
-- if !active and @user == current_user
+- if !pending_active_pastdue and @user == current_user
= link_to 'subscribe to plan', new_subscription_path, :class => :btn \ No newline at end of file
diff --git a/billing/app/views/subscriptions/show.html.haml b/billing/app/views/subscriptions/show.html.haml
index 39f4d1a..b258e47 100644
--- a/billing/app/views/subscriptions/show.html.haml
+++ b/billing/app/views/subscriptions/show.html.haml
@@ -3,4 +3,4 @@
Current
Subscription
= render :partial => "subscription_details", :locals => {:subscription => @subscription}
-= link_to t(:cancel_subscription), user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn btn-danger' if @subscription.status == 'Active' # permission check or should that just be on show?
+= link_to t(:cancel_subscription), user_subscription_path(@user, @subscription.id), :confirm => t(:are_you_sure), :method => :delete, :class => 'btn btn-danger' if ['Active', 'Pending'].include? @subscription.status # permission check or should that just be on show? # should you be able to cancel pending subscription?
diff --git a/billing/config/locales/en.yml b/billing/config/locales/en.yml
index 5245b17..952cfd6 100644
--- a/billing/config/locales/en.yml
+++ b/billing/config/locales/en.yml
@@ -2,4 +2,5 @@ en:
create_new_customer: "Create a new Braintree Customer"
must_create_customer: "You must store a customer in braintree before subscribing to a plan"
subscribe: "Subscribe"
- save_customer_info: "Save Customer Information" \ No newline at end of file
+ save_customer_info: "Save Customer Information"
+ no_relevant_subscription: "No subscription which is Active, Pending, or Past Due" \ No newline at end of file