-
Notifications
You must be signed in to change notification settings - Fork 22
Customer
lyang edited this page Mar 17, 2013
·
7 revisions
[:company, :custom_fields, :email, :fax, :first_name, :id, :last_name, :options, :phone, :website]
[:company, :custom_fields, :email, :fax, :first_name, :last_name, :options, :phone, :website]
[:created_at, :updated_at]
customer = BraintreeRails::Customer.find('customer_id')
customer.addresses # eager loaded collection from Braintree::Customer.find
# initialize a address ready to be added to the customer
address = customer.addresses.build(:postal_code => '12345')
address.save!
# add an address to the customer
address = customer.addresses.create(:postal_code => '12345')
# find a address from the cached collection instead of firing API call
address = customer.addresses.find('address_id') # Note, this find does not need the extra customer_id
customer = BraintreeRails::Customer.find('customer_id')
customer.credit_cards # eager loaded collection from Braintree::Customer.find
# initialize a credit card ready to be added to the customer
credit_card = customer.credit_cards.build(:number => 'encrypted_by_braintree_js')
credit_card.save!
# add a credit card to the customer
credit_card = customer.credit_cards.create(:number => 'encrypted_by_braintree_js')
# find a credit card from the cached collection instead of firing API call
credit_card = customer.credit_cards.find('credit_card_token')
customer = BraintreeRails::Customer.find('customer_id')
customer.transactions # lazy loaded collection through Braintree::Transaction.search
# initialize a transaction ready to be created using the default credit card of the customer
transaction = customer.transactions.build(:amount => '10.00')
transaction.save!
# initialize a transaction ready to be created for this customer using a new credit card
transaction = customer.transactions.build(:amount => '10.00', :credit_card => {...}, :billing => {...})
# create a transaction using the default card
transaction = customer.transactions.create(:amount => '11.00')
[:id, :format => {:with => /\A[-_a-z0-9]*\z/i}, :length => {:maximum => 36}, :exclusion => {:in => %w(all new)}],
[:first_name, :last_name, :company, :website, :phone, :fax, :length => {:maximum => 255}]
(before|after)_validate
(before|around|after)_save
(before|around|after)_create
(before|around|after)_update
(before|around|after)_destroy
def full_name
"#{first_name} #{last_name}".strip
end
def default_credit_card
credit_cards.find(&:default?)
end