Sha256: 0cc4ab96fe36ebb19fecc6d4eb589d3a51eb15edb6a610c5b724508361e1b755

Contents?: true

Size: 1.2 KB

Versions: 12

Compression:

Stored size: 1.2 KB

Contents

module PaidUp
  class SubscriptionsController < PaidUpController
    before_filter :authenticate_user!
    before_filter :set_plan, only: [:new, :create]

    def index
      # nothing to do, everything we need is in current_user
    end

    def new
      # nothing to do, @plan set by #set_plan
      if current_user.can_downgrade_to?(@plan) || @plan.amount == 0
        create
      end
    end

    def create
      # @plan set by #set_plan
      current_user.update_attribute(:coupon_code, params[:coupon_code])
      if current_user.subscribe_to_plan(@plan, params[:stripeToken])
        redirect_to subscriptions_path, flash: { notice: :you_are_now_subscribed_to_the_plan.l(plan_name: current_user.plan.title) }
      else
        redirect_to new_plan_subscription_path @plan, flash: { error: current_user.errors.full_messages || :could_not_subscribe_to_plan.l(plan: @plan.title) }
      end
    rescue Stripe::InvalidRequestError => e
      flash[:error] = e.message
      redirect_to subscriptions_path
    rescue Stripe::CardError => e
      flash[:error] = e.message
      redirect_to new_plan_subscription_path
    end

    private
    def set_plan
      @plan = PaidUp::Plan.find(params[:plan_id])
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
paid_up-0.9.13 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.12 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.11 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.10 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.9 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.8 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.7 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.6 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.5 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.4 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.3 app/controllers/paid_up/subscriptions_controller.rb
paid_up-0.9.2 app/controllers/paid_up/subscriptions_controller.rb