Class: Braintree::Customer
- Inherits:
-
Object
- Object
- Braintree::Customer
- Includes:
- BaseModule, Util::IdEquality
- Defined in:
- lib/braintree/customer.rb
Instance Attribute Summary collapse
-
#addresses ⇒ Object
readonly
Returns the value of attribute addresses.
-
#apple_pay_cards ⇒ Object
readonly
Returns the value of attribute apple_pay_cards.
-
#company ⇒ Object
readonly
Returns the value of attribute company.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#credit_cards ⇒ Object
readonly
Returns the value of attribute credit_cards.
-
#custom_fields ⇒ Object
readonly
Returns the value of attribute custom_fields.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#fax ⇒ Object
readonly
Returns the value of attribute fax.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#google_pay_cards ⇒ Object
readonly
Returns the value of attribute google_pay_cards.
-
#graphql_id ⇒ Object
readonly
Returns the value of attribute graphql_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#international_phone ⇒ Object
readonly
Returns the value of attribute international_phone.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#paypal_accounts ⇒ Object
readonly
Returns the value of attribute paypal_accounts.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
-
#samsung_pay_cards ⇒ Object
readonly
Returns the value of attribute samsung_pay_cards.
-
#sepa_direct_debit_accounts ⇒ Object
readonly
Returns the value of attribute sepa_direct_debit_accounts.
-
#tax_identifiers ⇒ Object
readonly
Returns the value of attribute tax_identifiers.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
-
#us_bank_accounts ⇒ Object
readonly
Returns the value of attribute us_bank_accounts.
-
#venmo_accounts ⇒ Object
readonly
Returns the value of attribute venmo_accounts.
-
#visa_checkout_cards ⇒ Object
readonly
Returns the value of attribute visa_checkout_cards.
-
#website ⇒ Object
readonly
Returns the value of attribute website.
Class Method Summary collapse
- ._attributes ⇒ Object
- ._new(*args) ⇒ Object
- ._now_timestamp ⇒ Object
- .all ⇒ Object
- .create(*args) ⇒ Object
- .create!(*args) ⇒ Object
- .credit(customer_id, transaction_attributes) ⇒ Object
- .credit!(customer_id, transaction_attributes) ⇒ Object
- .delete(*args) ⇒ Object
- .find(*args) ⇒ Object
- .sale(customer_id, transaction_attributes) ⇒ Object
- .sale!(customer_id, transaction_attributes) ⇒ Object
- .search(&block) ⇒ Object
- .transactions(*args) ⇒ Object
- .update(*args) ⇒ Object
- .update!(*args) ⇒ Object
Instance Method Summary collapse
- #credit(transaction_attributes) ⇒ Object
- #credit!(transaction_attributes) ⇒ Object
- #default_payment_method ⇒ Object
- #delete ⇒ Object
-
#initialize(gateway, attributes) ⇒ Customer
constructor
A new instance of Customer.
- #inspect ⇒ Object
- #payment_methods ⇒ Object
- #transactions(options = {}) ⇒ Object
Methods included from Util::IdEquality
Methods included from BaseModule
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.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/braintree/customer.rb', line 83 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
#addresses ⇒ Object (readonly)
Returns the value of attribute addresses.
6 7 8 |
# File 'lib/braintree/customer.rb', line 6 def addresses @addresses end |
#apple_pay_cards ⇒ Object (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 |
#company ⇒ Object (readonly)
Returns the value of attribute company.
8 9 10 |
# File 'lib/braintree/customer.rb', line 8 def company @company end |
#created_at ⇒ Object (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_cards ⇒ Object (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_fields ⇒ Object (readonly)
Returns the value of attribute custom_fields.
11 12 13 |
# File 'lib/braintree/customer.rb', line 11 def custom_fields @custom_fields end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
12 13 14 |
# File 'lib/braintree/customer.rb', line 12 def email @email end |
#fax ⇒ Object (readonly)
Returns the value of attribute fax.
13 14 15 |
# File 'lib/braintree/customer.rb', line 13 def fax @fax end |
#first_name ⇒ Object (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_cards ⇒ Object (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_id ⇒ Object (readonly)
Returns the value of attribute graphql_id.
16 17 18 |
# File 'lib/braintree/customer.rb', line 16 def graphql_id @graphql_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/braintree/customer.rb', line 17 def id @id end |
#international_phone ⇒ Object (readonly)
Returns the value of attribute international_phone.
18 19 20 |
# File 'lib/braintree/customer.rb', line 18 def international_phone @international_phone end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
19 20 21 |
# File 'lib/braintree/customer.rb', line 19 def last_name @last_name end |
#paypal_accounts ⇒ Object (readonly)
Returns the value of attribute paypal_accounts.
20 21 22 |
# File 'lib/braintree/customer.rb', line 20 def paypal_accounts @paypal_accounts end |
#phone ⇒ Object (readonly)
Returns the value of attribute phone.
21 22 23 |
# File 'lib/braintree/customer.rb', line 21 def phone @phone end |
#samsung_pay_cards ⇒ Object (readonly)
Returns the value of attribute samsung_pay_cards.
22 23 24 |
# File 'lib/braintree/customer.rb', line 22 def samsung_pay_cards @samsung_pay_cards end |
#sepa_direct_debit_accounts ⇒ Object (readonly)
Returns the value of attribute sepa_direct_debit_accounts.
23 24 25 |
# File 'lib/braintree/customer.rb', line 23 def sepa_direct_debit_accounts @sepa_direct_debit_accounts end |
#tax_identifiers ⇒ Object (readonly)
Returns the value of attribute tax_identifiers.
24 25 26 |
# File 'lib/braintree/customer.rb', line 24 def tax_identifiers @tax_identifiers end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
25 26 27 |
# File 'lib/braintree/customer.rb', line 25 def updated_at @updated_at end |
#us_bank_accounts ⇒ Object (readonly)
Returns the value of attribute us_bank_accounts.
26 27 28 |
# File 'lib/braintree/customer.rb', line 26 def us_bank_accounts @us_bank_accounts end |
#venmo_accounts ⇒ Object (readonly)
Returns the value of attribute venmo_accounts.
27 28 29 |
# File 'lib/braintree/customer.rb', line 27 def venmo_accounts @venmo_accounts end |
#visa_checkout_cards ⇒ Object (readonly)
Returns the value of attribute visa_checkout_cards.
28 29 30 |
# File 'lib/braintree/customer.rb', line 28 def visa_checkout_cards @visa_checkout_cards end |
#website ⇒ Object (readonly)
Returns the value of attribute website.
29 30 31 |
# File 'lib/braintree/customer.rb', line 29 def website @website end |
Class Method Details
._attributes ⇒ Object
150 151 152 153 154 155 |
# File 'lib/braintree/customer.rb', line 150 def self._attributes [ :addresses, :company, :credit_cards, :email, :fax, :first_name, :id, :international_phone, :last_name, :phone, :website, :created_at, :updated_at, :tax_identifiers ] end |
._new(*args) ⇒ Object
146 147 148 |
# File 'lib/braintree/customer.rb', line 146 def self._new(*args) self.new(*args) end |
._now_timestamp ⇒ Object
157 158 159 |
# File 'lib/braintree/customer.rb', line 157 def self. Time.now.to_i end |
.all ⇒ Object
31 32 33 |
# File 'lib/braintree/customer.rb', line 31 def self.all Configuration.gateway.customer.all end |
.create(*args) ⇒ Object
35 36 37 |
# File 'lib/braintree/customer.rb', line 35 def self.create(*args) Configuration.gateway.customer.create(*args) end |
.create!(*args) ⇒ Object
39 40 41 |
# File 'lib/braintree/customer.rb', line 39 def self.create!(*args) Configuration.gateway.customer.create!(*args) end |
.credit(customer_id, transaction_attributes) ⇒ Object
43 44 45 |
# File 'lib/braintree/customer.rb', line 43 def self.credit(customer_id, transaction_attributes) Transaction.credit(transaction_attributes.merge(:customer_id => customer_id)) end |
.credit!(customer_id, transaction_attributes) ⇒ Object
47 48 49 |
# File 'lib/braintree/customer.rb', line 47 def self.credit!(customer_id, transaction_attributes) return_object_or_raise(:transaction) { credit(customer_id, transaction_attributes) } end |
.delete(*args) ⇒ Object
51 52 53 |
# File 'lib/braintree/customer.rb', line 51 def self.delete(*args) Configuration.gateway.customer.delete(*args) end |
.find(*args) ⇒ Object
55 56 57 |
# File 'lib/braintree/customer.rb', line 55 def self.find(*args) Configuration.gateway.customer.find(*args) end |
.sale(customer_id, transaction_attributes) ⇒ Object
59 60 61 |
# File 'lib/braintree/customer.rb', line 59 def self.sale(customer_id, transaction_attributes) Transaction.sale(transaction_attributes.merge(:customer_id => customer_id)) end |
.sale!(customer_id, transaction_attributes) ⇒ Object
63 64 65 |
# File 'lib/braintree/customer.rb', line 63 def self.sale!(customer_id, transaction_attributes) return_object_or_raise(:transaction) { sale(customer_id, transaction_attributes) } end |
.search(&block) ⇒ Object
67 68 69 |
# File 'lib/braintree/customer.rb', line 67 def self.search(&block) Configuration.gateway.customer.search(&block) end |
.transactions(*args) ⇒ Object
71 72 73 |
# File 'lib/braintree/customer.rb', line 71 def self.transactions(*args) Configuration.gateway.customer.transactions(*args) end |
.update(*args) ⇒ Object
75 76 77 |
# File 'lib/braintree/customer.rb', line 75 def self.update(*args) Configuration.gateway.customer.update(*args) end |
.update!(*args) ⇒ Object
79 80 81 |
# File 'lib/braintree/customer.rb', line 79 def self.update!(*args) Configuration.gateway.customer.update!(*args) end |
Instance Method Details
#credit(transaction_attributes) ⇒ Object
100 101 102 |
# File 'lib/braintree/customer.rb', line 100 def credit(transaction_attributes) @gateway.transaction.credit(transaction_attributes.merge(:customer_id => id)) end |
#credit!(transaction_attributes) ⇒ Object
104 105 106 |
# File 'lib/braintree/customer.rb', line 104 def credit!(transaction_attributes) return_object_or_raise(:transaction) { credit(transaction_attributes) } end |
#default_payment_method ⇒ Object
108 109 110 |
# File 'lib/braintree/customer.rb', line 108 def default_payment_method payment_methods.find { |payment_instrument| payment_instrument.default? } end |
#delete ⇒ Object
112 113 114 |
# File 'lib/braintree/customer.rb', line 112 def delete @gateway.customer.delete(id) end |
#inspect ⇒ Object
128 129 130 131 132 133 134 135 136 |
# File 'lib/braintree/customer.rb', line 128 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_methods ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# 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 + @sepa_direct_debit_accounts end |
#transactions(options = {}) ⇒ Object
138 139 140 |
# File 'lib/braintree/customer.rb', line 138 def transactions( = {}) @gateway.customer.transactions(id, ) end |