Class: BraintreeRails::Customer

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/braintree_rails/customer.rb

Instance Method Summary collapse

Methods included from Model

included

Instance Method Details

#add_errors(validation_errors) ⇒ Object



31
32
33
34
# File 'lib/braintree_rails/customer.rb', line 31

def add_errors(validation_errors)
  credit_card.add_errors(extract_errors(validation_errors)) if credit_card
  super(validation_errors)
end

#attributes_for(action) ⇒ Object



36
37
38
# File 'lib/braintree_rails/customer.rb', line 36

def attributes_for(action)
  super.merge(credit_card_attributes(action))
end

#credit_card_attributes(action) ⇒ Object



44
45
46
# File 'lib/braintree_rails/customer.rb', line 44

def credit_card_attributes(action)
  credit_card.present? ? {:credit_card => credit_card.attributes_for(action).except(:customer_id, :token)} : {}
end

#default_credit_cardObject



40
41
42
# File 'lib/braintree_rails/customer.rb', line 40

def default_credit_card
  credit_cards.find(&:default?)
end

#ensure_model(model) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/braintree_rails/customer.rb', line 17

def ensure_model(model)
  if Braintree::Transaction::CustomerDetails === model
    assign_attributes(extract_values(model))
    self.persisted = model.id.present?
    model
  else
    super
  end
end

#full_nameObject



27
28
29
# File 'lib/braintree_rails/customer.rb', line 27

def full_name
  "#{first_name} #{last_name}".strip
end