Sha256: 1f900394fbfaa55f9a3b9e309a494b040f72b90cc72e74b6b05d05e2d3c0ccca

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

class PlansController < ApplicationController
  layout Saucy::Layouts.to_proc

  def index
    @plans = Plan.ordered
  end

  def edit
    @plans = Plan.ordered
    @account = current_account
  end

  def update
    @plans = Plan.ordered
    @account = current_account
    from_plan = @account.plan

    if @account.save_customer_and_subscription!(params[:account])
      to_plan = @account.plan
      notify_observers_of_plan_change(from_plan, to_plan)
      redirect_to edit_account_path(@account), :notice => t('.update.notice', :default => "Plan changed successfully")
    else
      render :edit
    end
  end

  private

  def notify_observers_of_plan_change(from_plan, to_plan)
    notify_observers("plan_upgraded",   from_plan, to_plan) if from_plan.price < to_plan.price
    notify_observers("plan_downgraded", from_plan, to_plan) if from_plan.price > to_plan.price
  end

  def notify_observers(event_name, from_plan, to_plan)
    Saucy::Configuration.notify(event_name,
                                :account   => @account,
                                :request   => request,
                                :from_plan => from_plan,
                                :to_plan   => to_plan)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
saucy-0.8.5 app/controllers/plans_controller.rb