Class: Account::SubscriptionsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Account::SubscriptionsController
- Defined in:
- app/controllers/tang/account/subscriptions_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/tang/account/subscriptions_controller.rb', line 33 def create plan = Plan.find(subscription_params[:plan]) @subscription = CreateSubscription.call( plan, current_customer, params[:stripe_token] ) if @subscription.errors.blank? flash[:upgrade] = 'true' if @subscription.upgraded redirect_to account_subscription_path, notice: 'Subscription was successfully created.' else render :new end end |
#destroy ⇒ Object
70 71 72 73 74 |
# File 'app/controllers/tang/account/subscriptions_controller.rb', line 70 def destroy # @subscription.destroy @subscription.cancel! redirect_to account_subscription_path, notice: 'Subscription was successfully cancelled.' end |
#new ⇒ Object
25 26 27 28 29 30 31 |
# File 'app/controllers/tang/account/subscriptions_controller.rb', line 25 def new plan = Plan.find(params[:plan]) @subscription = Subscription.new( plan: plan, customer: current_customer ) end |
#show ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/controllers/tang/account/subscriptions_controller.rb', line 7 def show if !current_customer.stripe_enabled? render :not_stripe and return end @plans = Plan.where(interval: 'month').order(:order) if @subscription.present? && @subscription.plan.present? @next_plan = @plans.where("tang_plans.order > ?", @subscription.plan.order).first @previous_plan = @plans.where("tang_plans.order < ?", @subscription.plan.order).last else @next_plan = @plans.first @previous_plan = nil end @receipts = current_customer.charges.order(created: :desc).limit(5) end |
#update ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/tang/account/subscriptions_controller.rb', line 49 def update if @subscription.nil? redirect_to account_subscription_path, notice: 'Sorry, we could not find your subscription.' and return end plan = Plan.find(params[:plan]) @subscription = ChangeSubscription.call( @subscription, plan ) if @subscription.errors.blank? flash[:upgrade] = 'true' if @subscription.upgraded redirect_to account_subscription_path, notice: 'Subscription was successfully changed.' else @plans = Plan.order(:order) @next_plan = @plans.where("tang_plans.order > ?", @subscription.plan.order).first @previous_plan = @plans.where("tang_plans.order < ?", @subscription.plan.order).last render :show end end |