Class: Ashmont::Customer
- Inherits:
-
Object
- Object
- Ashmont::Customer
- Defined in:
- lib/ashmont/customer.rb
Direct Known Subclasses
Constant Summary collapse
- CREDIT_CARD_ATTRIBUTES =
[:cardholder_name, :number, :cvv, :expiration_month, :expiration_year].freeze
- ADDRESS_ATTRIBUTES =
[:street_address, :extended_address, :locality, :region, :postal_code, :country_name].freeze
- BILLING_ATTRIBUTES =
(CREDIT_CARD_ATTRIBUTES + ADDRESS_ATTRIBUTES).freeze
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #billing_email ⇒ Object
- #cardholder_name ⇒ Object
- #confirm(query_string) ⇒ Object
- #country_name ⇒ Object
- #credit_card ⇒ Object
- #credit_cards ⇒ Object
- #delete ⇒ Object
- #expiration_month ⇒ Object
- #expiration_year ⇒ Object
- #extended_address ⇒ Object
- #has_billing_info? ⇒ Boolean
-
#initialize(token = nil) ⇒ Customer
constructor
A new instance of Customer.
- #last_4 ⇒ Object
- #locality ⇒ Object
- #payment_method_token ⇒ Object
- #paypal_account ⇒ Object
- #paypal_accounts ⇒ Object
- #postal_code ⇒ Object
- #primary_payment_account ⇒ Object
- #primary_payment_method ⇒ Object
- #region ⇒ Object
- #save(attributes) ⇒ Object
- #street_address ⇒ Object
Constructor Details
#initialize(token = nil) ⇒ Customer
Returns a new instance of Customer.
9 10 11 12 |
# File 'lib/ashmont/customer.rb', line 9 def initialize(token = nil) @token = token @errors = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
7 8 9 |
# File 'lib/ashmont/customer.rb', line 7 def errors @errors end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/ashmont/customer.rb', line 7 def token @token end |
Instance Method Details
#billing_email ⇒ Object
64 65 66 |
# File 'lib/ashmont/customer.rb', line 64 def billing_email remote_customer.email if persisted? end |
#cardholder_name ⇒ Object
80 81 82 |
# File 'lib/ashmont/customer.rb', line 80 def cardholder_name credit_card.cardholder_name if credit_card end |
#confirm(query_string) ⇒ Object
116 117 118 |
# File 'lib/ashmont/customer.rb', line 116 def confirm(query_string) handle_result Braintree::TransparentRedirect.confirm(query_string) end |
#country_name ⇒ Object
112 113 114 |
# File 'lib/ashmont/customer.rb', line 112 def country_name credit_card.billing_address.country_name if credit_card end |
#credit_card ⇒ Object
14 15 16 17 18 |
# File 'lib/ashmont/customer.rb', line 14 def credit_card # old way credit_cards[0] # primary_payment_account # too general end |
#credit_cards ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/ashmont/customer.rb', line 20 def credit_cards if persisted? remote_customer.credit_cards else [] end end |
#delete ⇒ Object
72 73 74 |
# File 'lib/ashmont/customer.rb', line 72 def delete Braintree::Customer.delete(@token) end |
#expiration_month ⇒ Object
84 85 86 |
# File 'lib/ashmont/customer.rb', line 84 def expiration_month credit_card.expiration_month if credit_card end |
#expiration_year ⇒ Object
88 89 90 |
# File 'lib/ashmont/customer.rb', line 88 def expiration_year credit_card.expiration_year if credit_card end |
#extended_address ⇒ Object
96 97 98 |
# File 'lib/ashmont/customer.rb', line 96 def extended_address credit_card.billing_address.extended_address if credit_card end |
#has_billing_info? ⇒ Boolean
56 57 58 |
# File 'lib/ashmont/customer.rb', line 56 def has_billing_info? credit_card.present? end |
#last_4 ⇒ Object
76 77 78 |
# File 'lib/ashmont/customer.rb', line 76 def last_4 credit_card.last_4 if credit_card end |
#locality ⇒ Object
100 101 102 |
# File 'lib/ashmont/customer.rb', line 100 def locality credit_card.billing_address.locality if credit_card end |
#payment_method_token ⇒ Object
60 61 62 |
# File 'lib/ashmont/customer.rb', line 60 def payment_method_token credit_card.token if credit_card end |
#paypal_account ⇒ Object
29 30 31 |
# File 'lib/ashmont/customer.rb', line 29 def paypal_account paypal_accounts[0] end |
#paypal_accounts ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ashmont/customer.rb', line 32 def paypal_accounts if persisted? remote_customer.paypal_accounts else [] end end |
#postal_code ⇒ Object
108 109 110 |
# File 'lib/ashmont/customer.rb', line 108 def postal_code credit_card.billing_address.postal_code if credit_card end |
#primary_payment_account ⇒ Object
52 53 54 |
# File 'lib/ashmont/customer.rb', line 52 def primary_payment_account primary_payment_method[0] end |
#primary_payment_method ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ashmont/customer.rb', line 40 def primary_payment_method #currently, usually there is only one payment method, paypal or credit_card if persisted? payment_methods = { credit_cards.count => :credit_cards, paypal_accounts.count => :paypal_accounts } chosen_method = (payment_methods[payment_methods.keys.max]) remote_customer.send(chosen_method) else [] end end |
#region ⇒ Object
104 105 106 |
# File 'lib/ashmont/customer.rb', line 104 def region credit_card.billing_address.region if credit_card end |
#save(attributes) ⇒ Object
68 69 70 |
# File 'lib/ashmont/customer.rb', line 68 def save(attributes) handle_result create_or_update(attributes) end |
#street_address ⇒ Object
92 93 94 |
# File 'lib/ashmont/customer.rb', line 92 def street_address credit_card.billing_address.street_address if credit_card end |