summaryrefslogtreecommitdiff
path: root/billing/app/controllers
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-04-15 12:13:33 -0700
committerAzul <azul@leap.se>2013-07-17 10:47:12 +0200
commit2829e7020abcf6d2f708fbc7dfb3db98ad174255 (patch)
tree4d389dbb892211bdb3f0305403a45c38e9d5a1c7 /billing/app/controllers
parent29f1de49083d57895bdf8f999448678934fbeffc (diff)
Displaying of user's subscription. Still not committed to whether user can have multiple subscriptions at a time or not.
Diffstat (limited to 'billing/app/controllers')
-rw-r--r--billing/app/controllers/customer_controller.rb2
-rw-r--r--billing/app/controllers/subscriptions_controller.rb12
2 files changed, 11 insertions, 3 deletions
diff --git a/billing/app/controllers/customer_controller.rb b/billing/app/controllers/customer_controller.rb
index a16e3fe..4192f4c 100644
--- a/billing/app/controllers/customer_controller.rb
+++ b/billing/app/controllers/customer_controller.rb
@@ -19,7 +19,7 @@ class CustomerController < BillingBaseController
@tr_data = Braintree::TransparentRedirect.
update_customer_data(:redirect_url => confirm_customer_url,
:customer_id => params[:id])
- @subscriptions = @braintree_data.credit_cards.map(&:subscriptions).flatten
+ @subscriptions = customer.active_subscriptions(@braintree_data)
else
# TODO: will want to have case for admins, presumably
access_denied
diff --git a/billing/app/controllers/subscriptions_controller.rb b/billing/app/controllers/subscriptions_controller.rb
index 38b17b4..af20faf 100644
--- a/billing/app/controllers/subscriptions_controller.rb
+++ b/billing/app/controllers/subscriptions_controller.rb
@@ -5,9 +5,17 @@ class SubscriptionsController < ApplicationController
# don't show link to subscribe if they are already subscribed?
customer = Customer.find_by_user_id(current_user.id)
- @payment_method_token = customer.default_credit_card.token
- @plans = Braintree::Plan.all
+ if subscription = customer.single_subscription
+ redirect_to subscription_path(subscription.id)
+ else
+ credit_card = customer.default_credit_card #safe to assume default?
+ @payment_method_token = credit_card.token
+ @plans = Braintree::Plan.all
+ end
+ end
+ def show
+ @subscription = Braintree::Subscription.find params[:id]
end