Sha256: 5ce3abcc7ad1a599b0fc8334763a9830c6a739c0e96fc621aecd3a5685d5d230

Contents?: true

Size: 1017 Bytes

Versions: 7

Compression:

Stored size: 1017 Bytes

Contents

class DiscoApp::SubscriptionsController < ApplicationController

  include DiscoApp::Concerns::AuthenticatedController

  skip_before_action :check_current_subscription

  def new
    @subscription = DiscoApp::Subscription.new
  end

  def create
    # Get the selected plan. If it's not available or couldn't be found,
    # redirect back to the plan selection page.
    plan = DiscoApp::Plan.available.find_by(id: subscription_params[:plan])

    redirect_to(action: :new) && return unless plan

    # Subscribe the current shop to the selected plan. Pass along any cookied
    # plan code and source code.
    subscription = DiscoApp::SubscriptionService.subscribe(
      @shop,
      plan,
      cookies[DiscoApp::CODE_COOKIE_KEY],
      cookies[DiscoApp::SOURCE_COOKIE_KEY]
    )

    if subscription.nil?
      redirect_to action: :new
    else
      redirect_to main_app.root_path
    end
  end

  private

    def subscription_params
      params.require(:subscription).permit(:plan, :plan_code)
    end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
disco_app-0.17.0 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.0 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.2 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.3 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.6 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.4 app/controllers/disco_app/subscriptions_controller.rb
disco_app-0.18.1 app/controllers/disco_app/subscriptions_controller.rb