Class: Braintree::CreditCard

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

Overview

Defined Under Namespace

Modules: CardType, CardTypeIndicator, CustomerLocation

Constant Summary

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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:



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

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) }
end

Instance Attribute Details

#billing_addressObject (readonly)

Returns the value of attribute billing_address



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def billing_address
  @billing_address
end

#binObject (readonly)

Returns the value of attribute bin



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def bin
  @bin
end

#card_typeObject (readonly)

Returns the value of attribute card_type



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def card_type
  @card_type
end

#cardholder_nameObject (readonly)

Returns the value of attribute cardholder_name



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def cardholder_name
  @cardholder_name
end

#commercialObject (readonly)

Returns the value of attribute commercial



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def commercial
  @commercial
end

#country_of_issuanceObject (readonly)

Returns the value of attribute country_of_issuance



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def country_of_issuance
  @country_of_issuance
end

#created_atObject (readonly)

Returns the value of attribute created_at



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def created_at
  @created_at
end

#customer_idObject (readonly)

Returns the value of attribute customer_id



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def customer_id
  @customer_id
end

#debitObject (readonly)

Returns the value of attribute debit



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def debit
  @debit
end

#durbin_regulatedObject (readonly)

Returns the value of attribute durbin_regulated



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def durbin_regulated
  @durbin_regulated
end

#expiration_monthObject (readonly)

Returns the value of attribute expiration_month



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def expiration_month
  @expiration_month
end

#expiration_yearObject (readonly)

Returns the value of attribute expiration_year



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def expiration_year
  @expiration_year
end

#healthcareObject (readonly)

Returns the value of attribute healthcare



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def healthcare
  @healthcare
end

#image_urlObject (readonly)

Returns the value of attribute image_url



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def image_url
  @image_url
end

#issuing_bankObject (readonly)

Returns the value of attribute issuing_bank



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def issuing_bank
  @issuing_bank
end

#last_4Object (readonly)

Returns the value of attribute last_4



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def last_4
  @last_4
end

#payrollObject (readonly)

Returns the value of attribute payroll



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def payroll
  @payroll
end

#prepaidObject (readonly)

Returns the value of attribute prepaid



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def prepaid
  @prepaid
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def subscriptions
  @subscriptions
end

#tokenObject (readonly)

Returns the value of attribute token



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def token
  @token
end

#unique_number_identifierObject (readonly)

Returns the value of attribute unique_number_identifier



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def unique_number_identifier
  @unique_number_identifier
end

#updated_atObject (readonly)

Returns the value of attribute updated_at



38
39
40
# File 'lib/braintree/credit_card.rb', line 38

def updated_at
  @updated_at
end

Class Method Details

._attributesObject

:nodoc:



243
244
245
246
247
248
249
# File 'lib/braintree/credit_card.rb', line 243

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, :commercial, :debit, :durbin_regulated,
    :healthcare, :country_of_issuance, :issuing_bank, :image_url
  ]
end

._new(*args) ⇒ Object

:nodoc:



251
252
253
# File 'lib/braintree/credit_card.rb', line 251

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

.create(attributes) ⇒ Object



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

def self.create(attributes)
  Configuration.gateway.credit_card.create(attributes)
end

.create!(attributes) ⇒ Object



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

def self.create!(attributes)
  return_object_or_raise(:credit_card) { create(attributes) }
end

.create_credit_card_urlObject

Deprecated. Use Braintree::TransparentRedirect.url See www.braintreepayments.com/docs/ruby/credit_cards/create_tr



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

def self.create_credit_card_url
  warn "[DEPRECATED] CreditCard.create_credit_card_url is deprecated. Please use TransparentRedirect.url"
  Configuration.gateway.credit_card.create_credit_card_url
end

.create_from_transparent_redirect(query_string) ⇒ Object

Deprecated. Use Braintree::TransparentRedirect.confirm See www.braintreepayments.com/docs/ruby/credit_cards/create_tr



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

def self.create_from_transparent_redirect(query_string)
  warn "[DEPRECATED] CreditCard.create_from_transparent_redirect is deprecated. Please use TransparentRedirect.confirm"
  Configuration.gateway.credit_card.create_from_transparent_redirect(query_string)
end

.credit(token, transaction_attributes) ⇒ Object



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

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

.credit!(token, transaction_attributes) ⇒ Object



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

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

.delete(token) ⇒ Object



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

def self.delete(token)
  Configuration.gateway.credit_card.delete(token)
end

.expired(options = {}) ⇒ Object



83
84
85
# File 'lib/braintree/credit_card.rb', line 83

def self.expired(options = {})
  Configuration.gateway.credit_card.expired(options)
end

.expiring_between(start_date, end_date, options = {}) ⇒ Object



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

def self.expiring_between(start_date, end_date, options = {})
  Configuration.gateway.credit_card.expiring_between(start_date, end_date, options)
end

.find(token) ⇒ Object



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

def self.find(token)
  Configuration.gateway.credit_card.find(token)
end

.sale(token, transaction_attributes) ⇒ Object



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

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

.sale!(token, transaction_attributes) ⇒ Object



103
104
105
# File 'lib/braintree/credit_card.rb', line 103

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

.update(token, attributes) ⇒ Object



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

def self.update(token, attributes)
  Configuration.gateway.credit_card.update(token, attributes)
end

.update!(token, attributes) ⇒ Object



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

def self.update!(token, attributes)
  return_object_or_raise(:credit_card) { update(token, attributes) }
end

.update_credit_card_urlObject

Deprecated. Use Braintree::TransparentRedirect.url

See www.braintreepayments.com/docs/ruby/credit_cards/update_tr



128
129
130
131
# File 'lib/braintree/credit_card.rb', line 128

def self.update_credit_card_url
  warn "[DEPRECATED] CreditCard.update_credit_card_url is deprecated. Please use TransparentRedirect.url"
  Configuration.gateway.credit_card.update_credit_card_url
end

.update_from_transparent_redirect(query_string) ⇒ Object

Deprecated. Use Braintree::TransparentRedirect.confirm

See www.braintreepayments.com/docs/ruby/credit_cards/update_tr



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

def self.update_from_transparent_redirect(query_string)
  warn "[DEPRECATED] CreditCard.update_via_transparent_redirect_request is deprecated. Please use TransparentRedirect.confirm"
  Configuration.gateway.credit_card.update_from_transparent_redirect(query_string)
end

Instance Method Details

#==(other) ⇒ Object

Returns true if other is a CreditCard with the same token.



234
235
236
237
# File 'lib/braintree/credit_card.rb', line 234

def ==(other)
  return false unless other.is_a?(CreditCard)
  token == other.token
end

#credit(transaction_attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.credit

See www.braintreepayments.com/docs/ruby/transactions/create_from_vault



143
144
145
146
# File 'lib/braintree/credit_card.rb', line 143

def credit(transaction_attributes)
  warn "[DEPRECATED] credit as an instance method is deprecated. Please use CreditCard.credit"
  @gateway.transaction.credit(transaction_attributes.merge(:payment_method_token => token))
end

#credit!(transaction_attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.credit!

See www.braintreepayments.com/docs/ruby/transactions/create_from_vault



151
152
153
154
# File 'lib/braintree/credit_card.rb', line 151

def credit!(transaction_attributes)
  warn "[DEPRECATED] credit! as an instance method is deprecated. Please use CreditCard.credit!"
  return_object_or_raise(:transaction) { credit(transaction_attributes) }
end

#default?Boolean

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



165
166
167
# File 'lib/braintree/credit_card.rb', line 165

def default?
  @default
end

#deleteObject

Deprecated. Use Braintree::CreditCard.delete

www.braintreepayments.com/docs/ruby/credit_cards/delete



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

def delete
  warn "[DEPRECATED] delete as an instance method is deprecated. Please use CreditCard.delete"
  @gateway.credit_card.delete(token)
end

#expiration_dateObject

Expiration date formatted as MM/YYYY



170
171
172
# File 'lib/braintree/credit_card.rb', line 170

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

#expired?Boolean

Returns true if the credit card is expired.



175
176
177
# File 'lib/braintree/credit_card.rb', line 175

def expired?
  @expired
end

#inspectObject

:nodoc:



179
180
181
182
183
184
185
186
# File 'lib/braintree/credit_card.rb', line 179

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

#masked_numberObject



188
189
190
# File 'lib/braintree/credit_card.rb', line 188

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

#sale(transaction_attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.sale

See www.braintreepayments.com/docs/ruby/transactions/create_from_vault



195
196
197
198
# File 'lib/braintree/credit_card.rb', line 195

def sale(transaction_attributes)
  warn "[DEPRECATED] sale as an instance method is deprecated. Please use CreditCard.sale"
  @gateway.transaction.sale(transaction_attributes.merge(:payment_method_token => token))
end

#sale!(transaction_attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.sale!

See www.braintreepayments.com/docs/ruby/transactions/create_from_vault



203
204
205
206
# File 'lib/braintree/credit_card.rb', line 203

def sale!(transaction_attributes)
  warn "[DEPRECATED] sale! as an instance method is deprecated. Please use CreditCard.sale!"
  return_object_or_raise(:transaction) { sale(transaction_attributes) }
end

#update(attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.update

See www.braintreepayments.com/docs/ruby/credit_cards/update



211
212
213
214
215
216
217
218
# File 'lib/braintree/credit_card.rb', line 211

def update(attributes)
  warn "[DEPRECATED] update as an instance method is deprecated. Please use CreditCard.update"
  result = @gateway.credit_card.update(token, attributes)
  if result.success?
    copy_instance_variables_from_object result.credit_card
  end
  result
end

#update!(attributes) ⇒ Object

Deprecated. Use Braintree::CreditCard.update!

See www.braintreepayments.com/docs/ruby/credit_cards/update



223
224
225
226
# File 'lib/braintree/credit_card.rb', line 223

def update!(attributes)
  warn "[DEPRECATED] update! as an instance method is deprecated. Please use CreditCard.update!"
  return_object_or_raise(:credit_card) { update(attributes) }
end

#venmo_sdk?Boolean

Returns true if the card is associated with Venmo SDK



229
230
231
# File 'lib/braintree/credit_card.rb', line 229

def venmo_sdk?
  @venmo_sdk
end