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, DebitNetwork

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

Returns a new instance of CreditCard.



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

def initialize(gateway, attributes)
  @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.



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

def billing_address
  @billing_address
end

#binObject (readonly)

Returns the value of attribute bin.



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

def bin
  @bin
end

#card_typeObject (readonly)

Returns the value of attribute card_type.



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

def card_type
  @card_type
end

#cardholder_nameObject (readonly)

Returns the value of attribute cardholder_name.



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

def cardholder_name
  @cardholder_name
end

#commercialObject (readonly)

Returns the value of attribute commercial.



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

def commercial
  @commercial
end

#country_of_issuanceObject (readonly)

Returns the value of attribute country_of_issuance.



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

def country_of_issuance
  @country_of_issuance
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#customer_idObject (readonly)

Returns the value of attribute customer_id.



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

def customer_id
  @customer_id
end

#debitObject (readonly)

Returns the value of attribute debit.



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

def debit
  @debit
end

#durbin_regulatedObject (readonly)

Returns the value of attribute durbin_regulated.



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

def durbin_regulated
  @durbin_regulated
end

#expiration_monthObject (readonly)

Returns the value of attribute expiration_month.



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

def expiration_month
  @expiration_month
end

#expiration_yearObject (readonly)

Returns the value of attribute expiration_year.



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

def expiration_year
  @expiration_year
end

#healthcareObject (readonly)

Returns the value of attribute healthcare.



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

def healthcare
  @healthcare
end

#image_urlObject (readonly)

Returns the value of attribute image_url.



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

def image_url
  @image_url
end

#issuing_bankObject (readonly)

Returns the value of attribute issuing_bank.



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

def issuing_bank
  @issuing_bank
end

#last_4Object (readonly)

Returns the value of attribute last_4.



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

def last_4
  @last_4
end

#payrollObject (readonly)

Returns the value of attribute payroll.



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

def payroll
  @payroll
end

#prepaidObject (readonly)

Returns the value of attribute prepaid.



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

def prepaid
  @prepaid
end

#product_idObject (readonly)

Returns the value of attribute product_id.



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

def product_id
  @product_id
end

#subscriptionsObject (readonly)

Returns the value of attribute subscriptions.



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

def subscriptions
  @subscriptions
end

#tokenObject (readonly)

Returns the value of attribute token.



71
72
73
# File 'lib/braintree/credit_card.rb', line 71

def token
  @token
end

#unique_number_identifierObject (readonly)

Returns the value of attribute unique_number_identifier.



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

def unique_number_identifier
  @unique_number_identifier
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#verificationObject (readonly)

Returns the value of attribute verification.



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

def verification
  @verification
end

Class Method Details

._attributesObject



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

def self._attributes
  [
    :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



208
209
210
# File 'lib/braintree/credit_card.rb', line 208

def self._new(*args)
  self.new(*args)
end

.create(*args) ⇒ Object



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

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

.create!(*args) ⇒ Object



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

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

.credit(token, transaction_attributes) ⇒ Object

NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit



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

def self.credit(token, transaction_attributes)
  warn "[DEPRECATED] CreditCard.credit is deprecated. Use Transaction.credit instead"
  Transaction.credit(transaction_attributes.merge(:payment_method_token => token))
end

.credit!(token, transaction_attributes) ⇒ Object

NEXT_MAJOR_VERSION remove this method CreditCard.credit has been deprecated in favor of Transaction.credit



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

def self.credit!(token, transaction_attributes)
  warn "[DEPRECATED] CreditCard.credit is deprecated. Use Transaction.credit instead"
  return_object_or_raise(:transaction) { credit(token, transaction_attributes) }
end

.delete(*args) ⇒ Object



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

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

.expired(*args) ⇒ Object



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

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

.expiring_between(*args) ⇒ Object



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

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

.find(*args) ⇒ Object



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

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

.from_nonce(*args) ⇒ Object



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

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

.sale(token, transaction_attributes) ⇒ Object

NEXT_MAJOR_VERSION remove this method CreditCard.sale has been deprecated in favor of Transaction.sale



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

def self.sale(token, transaction_attributes)
  warn "[DEPRECATED] CreditCard.sale is deprecated. Use Transaction.sale instead"
  Configuration.gateway.transaction.sale(transaction_attributes.merge(:payment_method_token => token))
end

.sale!(token, transaction_attributes) ⇒ Object

NEXT_MAJOR_VERSION remove this method CreditCard.sale has been deprecated in favor of Transaction.sale



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

def self.sale!(token, transaction_attributes)
  warn "[DEPRECATED] CreditCard.sale is deprecated. Use Transaction.sale instead"
  return_object_or_raise(:transaction) { sale(token, transaction_attributes) }
end

.update(*args) ⇒ Object



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

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

.update!(*args) ⇒ Object



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

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

Instance Method Details

#_most_recent_verification(attributes) ⇒ Object



148
149
150
151
# File 'lib/braintree/credit_card.rb', line 148

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

#default?Boolean

Returns:

  • (Boolean)


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

def default?
  @default
end

#expiration_dateObject

Expiration date formatted as MM/YYYY



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

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

#expired?Boolean

Returns:

  • (Boolean)


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

def expired?
  @expired
end

#inspectObject



166
167
168
169
170
171
172
173
# File 'lib/braintree/credit_card.rb', line 166

def inspect
  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)


192
193
194
# File 'lib/braintree/credit_card.rb', line 192

def is_network_tokenized?
  @is_network_tokenized
end

#masked_numberObject



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

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

#nonceObject



179
180
181
# File 'lib/braintree/credit_card.rb', line 179

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

#venmo_sdk?Boolean

NEXT_MAJOR_VERSION can this be removed? Venmo SDK integration is no more Returns true if the card is associated with Venmo SDK NEXT_MAJOR_VERSION Remove this method The old venmo SDK class has been deprecated

Returns:

  • (Boolean)


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

def venmo_sdk?
  warn "[DEPRECATED] The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead."
  @venmo_sdk
end