Sha256: 3966cc9e556b30e6f11cc1067f4a100fbbeb69fae29424a7e54d562592f76dee

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

require_dependency "tang/application_controller"

module Tang
  class Account::CardsController < Account::ApplicationController
    before_action :set_card, only: [:show, :destroy]

    def show
      @can_delete_card = current_customer.stripe_id.present? && 
          current_customer.subscription.nil? &&
          @card.present?
    end

    def new
      @card = Card.new(
        customer: current_customer
      )
    end

    def create
      @card = SaveCard.call(
        current_customer,
        params[:stripe_token]
      )

      if @card.errors.blank?
        redirect_to account_card_path, notice: 'Card was successfully created.'
      else
        render :new
      end
    end

    def update
      @card = SaveCard.call(
        current_customer,
        params[:stripe_token]
      )

      if @card.errors.blank?
        redirect_to account_card_path, notice: 'Card was successfully created.'
      else
        render :new
      end
    end

    def destroy
      if current_customer.subscription.nil?
        @card.destroy 
        redirect_to account_card_url, notice: 'Card was successfully removed.'
      else
        redirect_to account_card_url, notice: 'You cannot remove your card with an active subscription.'        
      end
    end

    private

    def set_card
      logger.debug "SET CARD CALLED"
      @card = current_customer.card
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tang-0.2.2 app/controllers/tang/account/cards_controller.rb
tang-0.2.1 app/controllers/tang/account/cards_controller.rb
tang-0.2.0 app/controllers/tang/account/cards_controller.rb
tang-0.1.0 app/controllers/tang/account/cards_controller.rb
tang-0.0.9 app/controllers/tang/account/cards_controller.rb