Sha256: a344b374453dafb59bf70f55b4882ddff6c2041cc113ba9e00b23242f1b2a406

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

module Spree
  module Admin
    class PlansController < Spree::Admin::BaseController
      before_action :load_recurring
      before_action :find_plan, :only => [:edit, :destroy, :update]

      def index
        @plans = Spree::Plan.undeleted.order('id desc')
      end

      def new
        @plan = @recurring.plans.build
      end

      def create
        @plan = @recurring.plans.build(plan_params)
        if @plan.save_and_manage_api
          flash[:notice] = 'Plan created successfully.'
          redirect_to edit_admin_recurring_plan_path(@recurring, @plan)
        else
          render :new
        end
      end

      def update
        if @plan.save_and_manage_api(plan_params(:update))
          flash[:notice] = 'Plan updated successfully.'
          redirect_to edit_admin_recurring_plan_path(@recurring, @plan)
        else
          render :edit
        end
      end
      
      def destroy
        @plan.restrictive_destroy_with_api
      end

      private

      def load_recurring
        unless @recurring = Spree::Recurring.undeleted.where(id: params[:recurring_id]).first
          flash[:error] = "Recurring not found."
          redirect_to admin_recurrings_path
        end
      end

      def plan_params(action=:create)
        if action == :create
          params.require(:plan).permit(:name, :trial_period_days, :interval, :currency, :amount, :active, :interval_count, :default)
        else
          params.require(:plan).permit(:name, :active, :default)
        end
      end

      def find_plan
        unless @plan = @recurring.plans.undeleted.where(id: params[:id]).first
          flash[:error] = "Plan not found."
          redirect_to admin_recurring_plans_path(@recurring)
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
spree_account_recurring-2.0.0 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.3.1 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.2.1 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.3.0 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.2.0 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.5 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.7 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.4 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.6 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.5 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.3 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.2 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.4 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.3 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.2 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.1 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.1.0 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.1 app/controllers/spree/admin/plans_controller.rb
spree_account_recurring-1.0.0 app/controllers/spree/admin/plans_controller.rb