Class: Braintree::CreditCard

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

Defined Under Namespace

Modules: CardType, CardTypeIndicator, CustomerLocation

Constant Summary collapse

Commercial =
Debit = DurbinRegulated = Healthcare = Payroll = Prepaid = ProductId =
IssuingBank = CountryOfIssuance = CardTypeIndicator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::TokenEquality

#==

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) ⇒ CreditCard

:nodoc:


117
118
119
120
121
122
123
# File 'lib/braintree/credit_card.rb', line 117

def initialize(gateway, attributes) # :nodoc:
  @gateway = gateway
  set_instance_variables_from_hash(attributes)
  @billing_address = attributes[:billing_address] ? Address._new(@gateway, attributes[:billing_address]) : nil
  @subscriptions = (@subscriptions || []).map { |subscription_hash| Subscription._new(@gateway, subscription_hash) }
  @verification = _most_recent_verification(attributes)
end

Instance Attribute Details

#billing_addressObject (readonly)

Returns the value of attribute billing_address.


40
41
42
# File 'lib/braintree/credit_card.rb', line 40

def billing_address
  @billing_address
end

#binObject (readonly)

Returns the value of attribute bin.


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

def bin
  @bin
end

#card_typeObject (readonly)

Returns the value of attribute card_type.


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

def card_type
  @card_type
end

#cardholder_nameObject (readonly)

Returns the value of attribute cardholder_name.


43
44
45
# File 'lib/braintree/credit_card.rb', line 43

def cardholder_name
  @cardholder_name
end

#commercialObject (readonly)

Returns the value of attribute commercial.


44
45
46
# File 'lib/braintree/credit_card.rb', line 44

def commercial
  @commercial
end

#country_of_issuanceObject (readonly)

Returns the value of attribute country_of_issuance.


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

def country_of_issuance
  @country_of_issuance
end

#created_atObject (readonly)

Returns the value of attribute created_at.


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

def created_at
  @created_at
end

#customer_idObject (readonly)

Returns the value of attribute customer_id.


47
48
49
# File 'lib/braintree/credit_card.rb', line 47

def customer_id
  @customer_id
end

#debitObject (readonly)

Returns the value of attribute debit.


48
49
50
# File 'lib/braintree/credit_card.rb', line 48

def debit
  @debit
end

#durbin_regulatedObject (readonly)

Returns the value of attribute durbin_regulated.


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

def durbin_regulated
  @durbin_regulated
end

#expiration_monthObject (readonly)

Returns the value of attribute expiration_month.


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

def expiration_month
  @expiration_month
end

#expiration_yearObject (readonly)

Returns the value of attribute expiration_year.


51
52
53
# File 'lib/braintree/credit_card.rb', line 51

def expiration_year
  @expiration_year
end

#healthcareObject (readonly)

Returns the value of attribute healthcare.


52
53
54
# File 'lib/braintree/credit_card.rb', line 52

def healthcare
  @healthcare
end

#image_urlObject (readonly)

Returns the value of attribute image_url.


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

def image_url
  @image_url
end

#issuing_bankObject (readonly)

Returns the value of attribute issuing_bank.


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

def issuing_bank
  @issuing_bank
end

#last_4Object (readonly)

Returns the value of attribute last_4.


55
56
57
# File 'lib/braintree/credit_card.rb', line 55

def last_4
  @last_4
end

#payrollObject (readonly)

Returns the value of attribute payroll.


56
57
58
# File 'lib/braintree/credit_card.rb', line 56

def payroll
  @payroll
end

#prepaidObject (readonly)

Returns the value of attribute prepaid.


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

def prepaid
  @prepaid
end

#product_idObject (readonly)

Returns the value of attribute product_id.


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

def product_id
  @product_id
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.


59
60
61
# File 'lib/braintree/credit_card.rb', line 59

def subscriptions
  @subscriptions
end

#tokenObject (readonly)

Returns the value of attribute token.


60
61
62
# File 'lib/braintree/credit_card.rb', line 60

def token
  @token
end

#unique_number_identifierObject (readonly)

Returns the value of attribute unique_number_identifier.


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

def unique_number_identifier
  @unique_number_identifier
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.


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

def updated_at
  @updated_at
end

#verificationObject (readonly)

Returns the value of attribute verification.


63
64
65
# File 'lib/braintree/credit_card.rb', line 63

def verification
  @verification
end

Class Method Details

._attributesObject

:nodoc:


175
176
177
178
179
180
181
# File 'lib/braintree/credit_card.rb', line 175

def self._attributes # :nodoc:
  [
    :billing_address, :bin, :card_type, :cardholder_name, :created_at, :customer_id, :expiration_month,
    :expiration_year, :last_4, :token, :updated_at, :prepaid, :payroll, :product_id, :commercial, :debit, :durbin_regulated,
    :healthcare, :country_of_issuance, :issuing_bank, :image_url, :is_network_tokenized?
  ]
end

._new(*args) ⇒ Object

:nodoc:


183
184
185
# File 'lib/braintree/credit_card.rb', line 183

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

.create(*args) ⇒ Object


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

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

.create!(*args) ⇒ Object


69
70
71
# File 'lib/braintree/credit_card.rb', line 69

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

.credit(token, transaction_attributes) ⇒ Object


73
74
75
# File 'lib/braintree/credit_card.rb', line 73

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

.credit!(token, transaction_attributes) ⇒ Object


77
78
79
# File 'lib/braintree/credit_card.rb', line 77

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

.delete(*args) ⇒ Object


81
82
83
# File 'lib/braintree/credit_card.rb', line 81

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

.expired(*args) ⇒ Object


85
86
87
# File 'lib/braintree/credit_card.rb', line 85

def self.expired(*args)
  Configuration.gateway.credit_card.expired(*args)
end

.expiring_between(*args) ⇒ Object


89
90
91
# File 'lib/braintree/credit_card.rb', line 89

def self.expiring_between(*args)
  Configuration.gateway.credit_card.expiring_between(*args)
end

.find(*args) ⇒ Object


93
94
95
# File 'lib/braintree/credit_card.rb', line 93

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

.from_nonce(*args) ⇒ Object


97
98
99
# File 'lib/braintree/credit_card.rb', line 97

def self.from_nonce(*args)
  Configuration.gateway.credit_card.from_nonce(*args)
end

.sale(token, transaction_attributes) ⇒ Object


101
102
103
# File 'lib/braintree/credit_card.rb', line 101

def self.sale(token, transaction_attributes)
  Configuration.gateway.transaction.sale(transaction_attributes.merge(:payment_method_token => token))
end

.sale!(token, transaction_attributes) ⇒ Object


105
106
107
# File 'lib/braintree/credit_card.rb', line 105

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

.update(*args) ⇒ Object


109
110
111
# File 'lib/braintree/credit_card.rb', line 109

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

.update!(*args) ⇒ Object


113
114
115
# File 'lib/braintree/credit_card.rb', line 113

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

Instance Method Details

#_most_recent_verification(attributes) ⇒ Object


125
126
127
128
# File 'lib/braintree/credit_card.rb', line 125

def _most_recent_verification(attributes)
  verification = (attributes[:verifications] || []).sort_by { |verification| verification[:created_at] }.reverse.first
  CreditCardVerification._new(verification) if verification
end

#default?Boolean

Returns true if this credit card is the customer's default payment method.

Returns:

  • (Boolean)

131
132
133
# File 'lib/braintree/credit_card.rb', line 131

def default?
  @default
end

#expiration_dateObject

Expiration date formatted as MM/YYYY


136
137
138
# File 'lib/braintree/credit_card.rb', line 136

def expiration_date
  "#{expiration_month}/#{expiration_year}"
end

#expired?Boolean

Returns true if the credit card is expired.

Returns:

  • (Boolean)

141
142
143
# File 'lib/braintree/credit_card.rb', line 141

def expired?
  @expired
end

#inspectObject

:nodoc:


145
146
147
148
149
150
151
152
# File 'lib/braintree/credit_card.rb', line 145

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

#is_network_tokenized?Boolean

Returns:

  • (Boolean)

167
168
169
# File 'lib/braintree/credit_card.rb', line 167

def is_network_tokenized?
  @is_network_tokenized
end

#masked_numberObject


154
155
156
# File 'lib/braintree/credit_card.rb', line 154

def masked_number
  "#{bin}******#{last_4}"
end

#nonceObject


158
159
160
# File 'lib/braintree/credit_card.rb', line 158

def nonce
  @nonce ||= PaymentMethodNonce.create(token)
end

#venmo_sdk?Boolean

Returns true if the card is associated with Venmo SDK

Returns:

  • (Boolean)

163
164
165
# File 'lib/braintree/credit_card.rb', line 163

def venmo_sdk?
  @venmo_sdk
end