Class: Account::CardsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/tang/account/cards_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/tang/account/cards_controller.rb', line 19

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

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

#destroyObject



45
46
47
48
49
50
51
52
# File 'app/controllers/tang/account/cards_controller.rb', line 45

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

#newObject



13
14
15
16
17
# File 'app/controllers/tang/account/cards_controller.rb', line 13

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

#showObject



7
8
9
10
11
# File 'app/controllers/tang/account/cards_controller.rb', line 7

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

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/tang/account/cards_controller.rb', line 32

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

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