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