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

- (CreditCard) initialize(gateway, attributes)

: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

- (Object) billing_address (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

- (Object) bin (readonly)

Returns the value of attribute bin



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

def bin
  @bin
end

- (Object) card_type (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

- (Object) cardholder_name (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

- (Object) commercial (readonly)

Returns the value of attribute commercial



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

def commercial
  @commercial
end

- (Object) country_of_issuance (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

- (Object) created_at (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

- (Object) customer_id (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

- (Object) debit (readonly)

Returns the value of attribute debit



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

def debit
  @debit
end

- (Object) durbin_regulated (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

- (Object) expiration_month (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

- (Object) expiration_year (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

- (Object) healthcare (readonly)

Returns the value of attribute healthcare



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

def healthcare
  @healthcare
end

- (Object) image_url (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

- (Object) issuing_bank (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

- (Object) last_4 (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

- (Object) payroll (readonly)

Returns the value of attribute payroll



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

def payroll
  @payroll
end

- (Object) prepaid (readonly)

Returns the value of attribute prepaid



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

def prepaid
  @prepaid
end

- (Object) subscriptions (readonly)

Returns the value of attribute subscriptions



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

def subscriptions
  @subscriptions
end

- (Object) token (readonly)

Returns the value of attribute token



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

def token
  @token
end

- (Object) unique_number_identifier (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

- (Object) updated_at (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

+ (Object) _attributes

: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

+ (Object) _new(*args)

:nodoc:



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

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

+ (Object) create(attributes)



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

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

+ (Object) create!(attributes)



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

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

+ (Object) create_credit_card_url

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

+ (Object) create_from_transparent_redirect(query_string)

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

+ (Object) credit(token, transaction_attributes)



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

+ (Object) credit!(token, transaction_attributes)



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

+ (Object) delete(token)



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

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

+ (Object) expired(options = {})



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

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

+ (Object) expiring_between(start_date, end_date, options = {})



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

+ (Object) find(token)



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

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

+ (Object) sale(token, transaction_attributes)



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

+ (Object) sale!(token, transaction_attributes)



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

+ (Object) update(token, attributes)



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

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

+ (Object) update!(token, attributes)



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

+ (Object) update_credit_card_url

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

+ (Object) update_from_transparent_redirect(query_string)

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

- (Object) ==(other)

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

- (Object) credit(transaction_attributes)

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

- (Object) credit!(transaction_attributes)

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

- (Boolean) default?

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

Returns:

  • (Boolean)


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

def default?
  @default
end

- (Object) delete

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

- (Object) expiration_date

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

- (Boolean) expired?

Returns true if the credit card is expired.

Returns:

  • (Boolean)


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

def expired?
  @expired
end

- (Object) inspect

: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

- (Object) masked_number



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

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

- (Object) sale(transaction_attributes)

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

- (Object) sale!(transaction_attributes)

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

- (Object) update(attributes)

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

- (Object) update!(attributes)

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

- (Boolean) venmo_sdk?

Returns true if the card is associated with Venmo SDK

Returns:

  • (Boolean)


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

def venmo_sdk?
  @venmo_sdk
end