Method: Effective::SubscriptionsController#create

Defined in:
app/controllers/effective/subscriptions_controller.rb

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/effective/subscriptions_controller.rb', line 31

def create
  @page_title ||= 'New Subscription'

  # Don't let the user create another Subscription object if it's already created
  @subscription = @customer.subscriptions.where(:stripe_plan_id => subscription_params[:stripe_plan_id]).first_or_initialize

  EffectiveOrders.authorized?(self, :create, @subscription)

  if @subscription.update_attributes(subscription_params) && (current_cart.find(@subscription).present? || current_cart.add(@subscription))
    flash[:success] = "Successfully added subscription to cart"
    redirect_to effective_orders.new_order_path
  else
    purchased_plans = @customer.subscriptions.purchased.map(&:stripe_plan_id)
    @plans = Stripe::Plan.all.reject { |stripe_plan| purchased_plans.include?(stripe_plan.id) }

    flash[:danger] ||= 'Unable to add subscription to cart.  Please try again.'
    render :action => :new
  end
end