Sha256: ec703d93e2baab231d2e92c08bf0a697eaeb8e898ef9b74e8190b92b3e6873d9

Contents?: true

Size: 1.13 KB

Versions: 38

Compression:

Stored size: 1.13 KB

Contents

require_dependency "wbase/application_controller"

module Wbase
  class SubscriptionsController < ApplicationController
    before_action :require_login!
    layout 'wbase/auth'

    def new
      if current_user.trial?
        redirect_to '/'
        return
      end

      if params[:plan]
        current_user.selected_plan = params[:plan]
        current_user.save
      end
    end

    def create
      # Does the user have a subscription?
      # - if so see if it matches the planid that was passed
      service = StartSubscription.new(current_user, subscription_params)
      service.call
      if service.valid?
        login(service.user)
        AdminMailer.new_subscription(service.user).deliver_later
        ActivateDripSubscriberJob.perform_later(service.user)
        redirect_to '/subscribed'
      else
        flash.now[:errors] = service.errors
        render :new
      end
    end

    private

    def subscription_params
      params
        .require(:subscription)
        .permit(
          :plan_id,
          :stripe_id,
          :credit_card_token,
          :card_type,
          :last_four
        )
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wbase-0.3.9 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.8 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.7 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.6 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.5 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.4 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.3 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.2 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.1 app/controllers/wbase/subscriptions_controller.rb
wbase-0.3.0 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.9 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.8 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.7 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.6 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.5 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.4 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.3 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.2 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.1 app/controllers/wbase/subscriptions_controller.rb
wbase-0.2.0 app/controllers/wbase/subscriptions_controller.rb