Class: BraintreeTransparentRedirectSlice::CreditCards

Inherits:
Application
  • Object
show all
Defined in:
app/controllers/credit_cards.rb

Instance Method Summary collapse

Methods included from Merb::BraintreeTransparentRedirectSlice::CreditCardsHelper

#braintree_date_reformatter, #fetch_credit_card

Instance Method Details

#destroy(id) ⇒ Object



49
50
51
52
53
# File 'app/controllers/credit_cards.rb', line 49

def destroy(id)
  fetch_credit_card(id)
  @gateway_request = Braintree::GatewayRequest.new
  render
end

#edit(id) ⇒ Object



28
29
30
31
32
33
# File 'app/controllers/credit_cards.rb', line 28

def edit(id)
  fetch_credit_card(id)
  @credit_card_info = @credit_card.info
  @gateway_request = Braintree::GatewayRequest.new
  render
end

#edit_response(id) ⇒ Object



35
36
37
38
39
40
41
42
# File 'app/controllers/credit_cards.rb', line 35

def edit_response(id)
  @gateway_response = Braintree::GatewayResponse.validate(params)
  if error = @gateway_response.error
    redirect(slice_url(:edit_credit_card, id), :message => {:notice => error})
  else
    redirect(slice_url(:credit_cards), :message => {:notice => 'Successfully updated your info in the vault.'})
  end
end

#indexObject



2
3
4
# File 'app/controllers/credit_cards.rb', line 2

def index
  render
end

#newObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/credit_cards.rb', line 6

def new
  @credit_card = CreditCard.new
  @credit_card_info = @credit_card.info

  unless message[:transaction_id].nil?
    @credit_card_info = Braintree::TransactionInfo.new(message[:transaction_id])
  end

  @gateway_request = Braintree::GatewayRequest.new(:orderid => Digest::SHA1.hexdigest(Time.now.to_s))
  render
end

#new_responseObject



18
19
20
21
22
23
24
25
26
# File 'app/controllers/credit_cards.rb', line 18

def new_response
  @gateway_response = Braintree::GatewayResponse.validate(params)
  if error = @gateway_response.error
    redirect(slice_url(:new_credit_card), :message => {:notice => error, :transaction_id => params[:transactionid]})
  else
    session.user.credit_cards.create(:token => @gateway_response.customer_vault_id)
    redirect(slice_url(:credit_cards), :message => {:notice => 'Successfully stored your card info securely.'})
  end
end

#show(id) ⇒ Object



44
45
46
47
# File 'app/controllers/credit_cards.rb', line 44

def show(id)
  fetch_credit_card(id)
  render
end