Class: Ashmont::Customer

Inherits:
Object
  • Object
show all
Defined in:
lib/ashmont/customer.rb

Direct Known Subclasses

SubscribedCustomer

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

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#tokenObject (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_emailObject



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

def billing_email
  remote_customer.email if persisted?
end

#cardholder_nameObject



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

def cardholder_name
  credit_card.cardholder_name if credit_card
end

#confirm(query_string) ⇒ Object



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

def confirm(query_string)
  handle_result Braintree::TransparentRedirect.confirm(query_string)
end

#country_nameObject



94
95
96
# File 'lib/ashmont/customer.rb', line 94

def country_name
  credit_card.billing_address.country_name if credit_card
end

#credit_cardObject



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

def credit_card
  credit_cards[0]
end

#credit_cardsObject



18
19
20
21
22
23
24
# File 'lib/ashmont/customer.rb', line 18

def credit_cards
  if persisted?
    remote_customer.credit_cards
  else
    []
  end
end

#deleteObject



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

def delete
  Braintree::Customer.delete(@token)
end

#expiration_monthObject



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

def expiration_month
  credit_card.expiration_month if credit_card
end

#expiration_yearObject



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

def expiration_year
  credit_card.expiration_year if credit_card
end

#extended_addressObject



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

def extended_address
  credit_card.billing_address.extended_address if credit_card
end

#has_billing_info?Boolean

Returns:

  • (Boolean)


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

def has_billing_info?
  credit_card.present?
end

#last_4Object



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

def last_4
  credit_card.last_4 if credit_card
end

#localityObject



82
83
84
# File 'lib/ashmont/customer.rb', line 82

def locality
  credit_card.billing_address.locality if credit_card
end

#payment_method_tokenObject



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

def payment_method_token
  credit_card.token if credit_card
end

#paypal_accountObject



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

def 
  paypal_accounts[0]
end

#paypal_accountsObject



30
31
32
33
34
35
36
# File 'lib/ashmont/customer.rb', line 30

def paypal_accounts
  if persisted?
    remote_customer.paypal_accounts
  else
    []
  end
end

#postal_codeObject



90
91
92
# File 'lib/ashmont/customer.rb', line 90

def postal_code
  credit_card.billing_address.postal_code if credit_card
end

#regionObject



86
87
88
# File 'lib/ashmont/customer.rb', line 86

def region
  credit_card.billing_address.region if credit_card
end

#save(attributes) ⇒ Object



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

def save(attributes)
  handle_result create_or_update(attributes)
end

#street_addressObject



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

def street_address
  credit_card.billing_address.street_address if credit_card
end