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

:nodoc:


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

def initialize(gateway, attributes) # :nodoc:
  @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 }
  @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

#tax_identifiersObject (readonly)

Returns the value of attribute tax_identifiers.


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

def tax_identifiers
  @tax_identifiers
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.


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

def updated_at
  @updated_at
end

#us_bank_accountsObject (readonly)

Returns the value of attribute us_bank_accounts.


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

def us_bank_accounts
  @us_bank_accounts
end

#venmo_accountsObject (readonly)

Returns the value of attribute venmo_accounts.


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

def venmo_accounts
  @venmo_accounts
end

#visa_checkout_cardsObject (readonly)

Returns the value of attribute visa_checkout_cards.


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

def visa_checkout_cards
  @visa_checkout_cards
end

#websiteObject (readonly)

Returns the value of attribute website.


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

def website
  @website
end

Class Method Details

._attributesObject

:nodoc:


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

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

._new(*args) ⇒ Object

:nodoc:


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

def self._new(*args) # :nodoc:
  self.new(*args)
end

._now_timestampObject

:nodoc:


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

def self._now_timestamp # :nodoc:
  Time.now.to_i
end

.allObject


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

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

.create(*args) ⇒ Object


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

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

.create!(*args) ⇒ Object


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

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

.credit(customer_id, transaction_attributes) ⇒ Object


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

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

.credit!(customer_id, transaction_attributes) ⇒ Object


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

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

.delete(*args) ⇒ Object


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

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

.find(*args) ⇒ Object


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

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

.sale(customer_id, transaction_attributes) ⇒ Object


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

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

.sale!(customer_id, transaction_attributes) ⇒ Object


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

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

.search(&block) ⇒ Object


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

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

.transactions(*args) ⇒ Object

Returns a ResourceCollection of transactions for the customer with the given customer_id.


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


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

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

#credit!(transaction_attributes) ⇒ Object


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

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

#default_payment_methodObject

Returns the customer's default payment method.


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

:nodoc:


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

def inspect # :nodoc:
  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

Returns the customer's payment methods


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

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

#transactions(options = {}) ⇒ Object

Returns a ResourceCollection of transactions for the customer.


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

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