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.1.7 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.6 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.5 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.4 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.3 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.2 app/controllers/wbase/subscriptions_controller.rb
wbase-0.1.0 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.15 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.14 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.13 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.12 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.11 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.10 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.9 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.8 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.7 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.6 app/controllers/wbase/subscriptions_controller.rb
wbase-0.0.5 app/controllers/wbase/subscriptions_controller.rb