Class: Braintree::Customer

Inherits:
Object
  • Object
show all
Includes:
BaseModule, Util::IdEquality
Defined in:
lib/braintree/customer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::IdEquality

#==

Methods included from BaseModule

included

Methods included from BaseModule::Methods

#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class

Constructor Details

#initialize(gateway, attributes) ⇒ Customer

Returns a new instance of Customer.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/braintree/customer.rb', line 82

def initialize(gateway, attributes)
  @gateway = gateway
  set_instance_variables_from_hash(attributes)
  @credit_cards = (@credit_cards || []).map { |pm| CreditCard._new gateway, pm }
  @paypal_accounts = (@paypal_accounts || []).map { |pm| PayPalAccount._new gateway, pm }
  @apple_pay_cards = (@apple_pay_cards || []).map { |pm| ApplePayCard._new gateway, pm }
  @google_pay_cards = (@google_pay_cards || []).map { |pm| GooglePayCard._new gateway, pm }
  @venmo_accounts = (@venmo_accounts || []).map { |pm| VenmoAccount._new gateway, pm }
  @us_bank_accounts = (@us_bank_accounts || []).map { |pm| UsBankAccount._new gateway, pm }
  @visa_checkout_cards = (@visa_checkout_cards|| []).map { |pm| VisaCheckoutCard._new gateway, pm }
  @sepa_direct_debit_accounts = (@sepa_debit_accounts || []).map { |pm| SepaDirectDebitAccount._new gateway, pm }
  @samsung_pay_cards = (@samsung_pay_cards|| []).map { |pm| SamsungPayCard._new gateway, pm }
  @addresses = (@addresses || []).map { |addr| Address._new gateway, addr }
  @tax_identifiers = (@tax_identifiers || []).map { |addr| TaxIdentifier._new gateway, addr }
  @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
end

Instance Attribute Details

#addressesObject (readonly)

Returns the value of attribute addresses.



6
7
8
# File 'lib/braintree/customer.rb', line 6

def addresses
  @addresses
end

#apple_pay_cardsObject (readonly)

Returns the value of attribute apple_pay_cards.



7
8
9
# File 'lib/braintree/customer.rb', line 7

def apple_pay_cards
  @apple_pay_cards
end

#companyObject (readonly)

Returns the value of attribute company.



8
9
10
# File 'lib/braintree/customer.rb', line 8

def company
  @company
end

#created_atObject (readonly)

Returns the value of attribute created_at.



9
10
11
# File 'lib/braintree/customer.rb', line 9

def created_at
  @created_at
end

#credit_cardsObject (readonly)

Returns the value of attribute credit_cards.



10
11
12
# File 'lib/braintree/customer.rb', line 10

def credit_cards
  @credit_cards
end

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields.



11
12
13
# File 'lib/braintree/customer.rb', line 11

def custom_fields
  @custom_fields
end

#emailObject (readonly)

Returns the value of attribute email.



12
13
14
# File 'lib/braintree/customer.rb', line 12

def email
  @email
end

#faxObject (readonly)

Returns the value of attribute fax.



13
14
15
# File 'lib/braintree/customer.rb', line 13

def fax
  @fax
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



14
15
16
# File 'lib/braintree/customer.rb', line 14

def first_name
  @first_name
end

#google_pay_cardsObject (readonly)

Returns the value of attribute google_pay_cards.



15
16
17
# File 'lib/braintree/customer.rb', line 15

def google_pay_cards
  @google_pay_cards
end

#graphql_idObject (readonly)

Returns the value of attribute graphql_id.



16
17
18
# File 'lib/braintree/customer.rb', line 16

def graphql_id
  @graphql_id
end

#idObject (readonly)

Returns the value of attribute id.



17
18
19
# File 'lib/braintree/customer.rb', line 17

def id
  @id
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



18
19
20
# File 'lib/braintree/customer.rb', line 18

def last_name
  @last_name
end

#paypal_accountsObject (readonly)

Returns the value of attribute paypal_accounts.



19
20
21
# File 'lib/braintree/customer.rb', line 19

def paypal_accounts
  @paypal_accounts
end

#phoneObject (readonly)

Returns the value of attribute phone.



20
21
22
# File 'lib/braintree/customer.rb', line 20

def phone
  @phone
end

#samsung_pay_cardsObject (readonly)

Returns the value of attribute samsung_pay_cards.



21
22
23
# File 'lib/braintree/customer.rb', line 21

def samsung_pay_cards
  @samsung_pay_cards
end

#sepa_direct_debit_accountsObject (readonly)

Returns the value of attribute sepa_direct_debit_accounts.



22
23
24
# File 'lib/braintree/customer.rb', line 22

def sepa_direct_debit_accounts
  @sepa_direct_debit_accounts
end

#tax_identifiersObject (readonly)

Returns the value of attribute tax_identifiers.



23
24
25
# File 'lib/braintree/customer.rb', line 23

def tax_identifiers
  @tax_identifiers
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



24
25
26
# File 'lib/braintree/customer.rb', line 24

def updated_at
  @updated_at
end

#us_bank_accountsObject (readonly)

Returns the value of attribute us_bank_accounts.



25
26
27
# File 'lib/braintree/customer.rb', line 25

def us_bank_accounts
  @us_bank_accounts
end

#venmo_accountsObject (readonly)

Returns the value of attribute venmo_accounts.



26
27
28
# File 'lib/braintree/customer.rb', line 26

def venmo_accounts
  @venmo_accounts
end

#visa_checkout_cardsObject (readonly)

Returns the value of attribute visa_checkout_cards.



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

def visa_checkout_cards
  @visa_checkout_cards
end

#websiteObject (readonly)

Returns the value of attribute website.



28
29
30
# File 'lib/braintree/customer.rb', line 28

def website
  @website
end

Class Method Details

._attributesObject



149
150
151
152
153
154
# File 'lib/braintree/customer.rb', line 149

def self._attributes
  [
    :addresses, :company, :credit_cards, :email, :fax, :first_name, :id, :last_name, :phone, :website,
    :created_at, :updated_at, :tax_identifiers
  ]
end

._new(*args) ⇒ Object



145
146
147
# File 'lib/braintree/customer.rb', line 145

def self._new(*args)
  self.new(*args)
end

._now_timestampObject



156
157
158
# File 'lib/braintree/customer.rb', line 156

def self._now_timestamp
  Time.now.to_i
end

.allObject



30
31
32
# File 'lib/braintree/customer.rb', line 30

def self.all
  Configuration.gateway.customer.all
end

.create(*args) ⇒ Object



34
35
36
# File 'lib/braintree/customer.rb', line 34

def self.create(*args)
  Configuration.gateway.customer.create(*args)
end

.create!(*args) ⇒ Object



38
39
40
# File 'lib/braintree/customer.rb', line 38

def self.create!(*args)
  Configuration.gateway.customer.create!(*args)
end

.credit(customer_id, transaction_attributes) ⇒ Object



42
43
44
# File 'lib/braintree/customer.rb', line 42

def self.credit(customer_id, transaction_attributes)
  Transaction.credit(transaction_attributes.merge(:customer_id => customer_id))
end

.credit!(customer_id, transaction_attributes) ⇒ Object



46
47
48
# File 'lib/braintree/customer.rb', line 46

def self.credit!(customer_id, transaction_attributes)
   return_object_or_raise(:transaction) { credit(customer_id, transaction_attributes) }
end

.delete(*args) ⇒ Object



50
51
52
# File 'lib/braintree/customer.rb', line 50

def self.delete(*args)
  Configuration.gateway.customer.delete(*args)
end

.find(*args) ⇒ Object



54
55
56
# File 'lib/braintree/customer.rb', line 54

def self.find(*args)
  Configuration.gateway.customer.find(*args)
end

.sale(customer_id, transaction_attributes) ⇒ Object



58
59
60
# File 'lib/braintree/customer.rb', line 58

def self.sale(customer_id, transaction_attributes)
  Transaction.sale(transaction_attributes.merge(:customer_id => customer_id))
end

.sale!(customer_id, transaction_attributes) ⇒ Object



62
63
64
# File 'lib/braintree/customer.rb', line 62

def self.sale!(customer_id, transaction_attributes)
  return_object_or_raise(:transaction) { sale(customer_id, transaction_attributes) }
end

.search(&block) ⇒ Object



66
67
68
# File 'lib/braintree/customer.rb', line 66

def self.search(&block)
  Configuration.gateway.customer.search(&block)
end

.transactions(*args) ⇒ Object



70
71
72
# File 'lib/braintree/customer.rb', line 70

def self.transactions(*args)
  Configuration.gateway.customer.transactions(*args)
end

.update(*args) ⇒ Object



74
75
76
# File 'lib/braintree/customer.rb', line 74

def self.update(*args)
  Configuration.gateway.customer.update(*args)
end

.update!(*args) ⇒ Object



78
79
80
# File 'lib/braintree/customer.rb', line 78

def self.update!(*args)
  Configuration.gateway.customer.update!(*args)
end

Instance Method Details

#credit(transaction_attributes) ⇒ Object



99
100
101
# File 'lib/braintree/customer.rb', line 99

def credit(transaction_attributes)
  @gateway.transaction.credit(transaction_attributes.merge(:customer_id => id))
end

#credit!(transaction_attributes) ⇒ Object



103
104
105
# File 'lib/braintree/customer.rb', line 103

def credit!(transaction_attributes)
  return_object_or_raise(:transaction) { credit(transaction_attributes) }
end

#default_payment_methodObject



107
108
109
# File 'lib/braintree/customer.rb', line 107

def default_payment_method
  payment_methods.find { |payment_instrument| payment_instrument.default? }
end

#deleteObject



111
112
113
# File 'lib/braintree/customer.rb', line 111

def delete
  @gateway.customer.delete(id)
end

#inspectObject



127
128
129
130
131
132
133
134
135
# File 'lib/braintree/customer.rb', line 127

def inspect
  first = [:id]
  last = [:addresses, :credit_cards, :paypal_accounts, :tax_identifiers]
  order = first + (self.class._attributes - first - last) + last
  nice_attributes = order.map do |attr|
    "#{attr}: #{send(attr).inspect}"
  end
  "#<#{self.class} #{nice_attributes.join(', ')}>"
end

#payment_methodsObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/braintree/customer.rb', line 115

def payment_methods
  @credit_cards +
    @paypal_accounts +
    @apple_pay_cards +
    @google_pay_cards +
    @venmo_accounts +
    @us_bank_accounts +
    @visa_checkout_cards +
    @samsung_pay_cards +
    @sepa_direct_debit_accounts
end

#transactions(options = {}) ⇒ Object



137
138
139
# File 'lib/braintree/customer.rb', line 137

def transactions(options = {})
  @gateway.customer.transactions(id, options)
end