Class: SubscriptionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- SubscriptionsController
- Defined in:
- app/controllers/subscriptions_controller.rb
Instance Method Summary collapse
- #cancel ⇒ Object
-
#credit_card ⇒ Object
could put these in separate controllers, but keeping it simple for now.
- #edit ⇒ Object
- #history ⇒ Object
- #show ⇒ Object
- #store_credit_card ⇒ Object
- #update ⇒ Object
Instance Method Details
#cancel ⇒ Object
44 45 46 47 48 |
# File 'app/controllers/subscriptions_controller.rb', line 44 def cancel @subscription.cancel flash[:notice] = 'Your subscription has been canceled. You still have limited access to this site.' redirect_to subscription_path(:current) end |
#credit_card ⇒ Object
could put these in separate controllers, but keeping it simple for now
51 52 53 |
# File 'app/controllers/subscriptions_controller.rb', line 51 def credit_card @profile = @subscription.profile end |
#edit ⇒ Object
8 9 10 11 |
# File 'app/controllers/subscriptions_controller.rb', line 8 def edit # to change plans @allowed_plans = @subscription.allowed_plans end |
#history ⇒ Object
75 76 77 |
# File 'app/controllers/subscriptions_controller.rb', line 75 def history @transactions = @subscription.transactions end |
#show ⇒ Object
5 6 |
# File 'app/controllers/subscriptions_controller.rb', line 5 def show end |
#store_credit_card ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/controllers/subscriptions_controller.rb', line 55 def store_credit_card @subscription.profile.credit_card = params[:profile][:credit_card] @subscription.profile.request_ip = request.remote_ip if @subscription.profile.save #debugger case result = @subscription.renew when false flash[:notice] = "An error occured trying to charge your credit card. Please update your card information." when Money flash[:notice] = "Thank you for your payment. Your credit card has been charged #{result.format}" else flash[:notice] = "Credit card info successfully updated. No charges have been made at this time." end return redirect_to subscription_path(:current) else @profile = @subscription.profile render :action => 'credit_card' end end |
#update ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/controllers/subscriptions_controller.rb', line 13 def update # find the plan plan = SubscriptionPlan.find params[:subscription][:plan] if plan.nil? flash[:notice] = "Plan not available" # make sure its an allowed plan elsif exceeded = @subscription.exceeds_plan?( plan ) flash[:notice] = "You cannot change to plan #{plan.name}. Resources exceeded" flash[:notice] << ": #{exceeded.keys.join(', ')}" if exceeded.is_a?(Hash) # perform the change # note, use #change_plan, dont just assign it elsif @subscription.change_plan(plan) flash[:notice] = "Successfully changed plans. " # after change_plan, call renew case result = @subscription.renew when false flash[:notice] << "An error occured trying to charge your credit card. Please update your card information." when Money flash[:notice] << "Thank you for your payment. Your credit card has been charged #{result.format}" end return redirect_to subscription_path(:current) end # failed above for some reason @allowed_plans = @subscription.allowed_plans render :action => 'edit' end |