Sha256: 974503bd26b0804493a3d5ac2912ad95c5d258b2314b50383a85dece052680d5

Contents?: true

Size: 999 Bytes

Versions: 4

Compression:

Stored size: 999 Bytes

Contents

module BraintreeRails
  class Customer
    include Model

    define_attributes(
      :create => [:company, :custom_fields, :email, :fax, :first_name, :id, :last_name, :options, :phone, :website],
      :update => [:company, :custom_fields, :email, :fax, :first_name, :last_name, :options, :phone, :website],
      :readonly => [:created_at, :updated_at],
      :as_association => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]
    )

    has_many :addresses,    :class => Addresses
    has_many :transactions, :class => Transactions
    has_many :credit_cards, :class => CreditCards

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

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
braintree-rails-1.2.2 lib/braintree_rails/customer.rb
braintree-rails-1.2.1 lib/braintree_rails/customer.rb
braintree-rails-1.2.0 lib/braintree_rails/customer.rb
braintree-rails-1.1.0 lib/braintree_rails/customer.rb