Class: Braintree::CreditCard

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

Overview

Defined Under Namespace

Modules: CardType, CustomerLocation

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:



122
123
124
125
126
127
# File 'lib/braintree/credit_card.rb', line 122

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



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def billing_address
  @billing_address
end

- (Object) bin (readonly)

Returns the value of attribute bin



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def bin
  @bin
end

- (Object) card_type (readonly)

Returns the value of attribute card_type



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def card_type
  @card_type
end

- (Object) cardholder_name (readonly)

Returns the value of attribute cardholder_name



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def cardholder_name
  @cardholder_name
end

- (Object) created_at (readonly)

Returns the value of attribute created_at



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def created_at
  @created_at
end

- (Object) customer_id (readonly)

Returns the value of attribute customer_id



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def customer_id
  @customer_id
end

- (Object) expiration_month (readonly)

Returns the value of attribute expiration_month



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def expiration_month
  @expiration_month
end

- (Object) expiration_year (readonly)

Returns the value of attribute expiration_year



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def expiration_year
  @expiration_year
end

- (Object) last_4 (readonly)

Returns the value of attribute last_4



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def last_4
  @last_4
end

- (Object) subscriptions (readonly)

Returns the value of attribute subscriptions



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def subscriptions
  @subscriptions
end

- (Object) token (readonly)

Returns the value of attribute token



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def token
  @token
end

- (Object) updated_at (readonly)

Returns the value of attribute updated_at



29
30
31
# File 'lib/braintree/credit_card.rb', line 29

def updated_at
  @updated_at
end

Class Method Details

+ (Object) _attributes

:nodoc:



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

def self._attributes # :nodoc:
  [
    :billing_address, :bin, :card_type, :cardholder_name, :created_at, :customer_id, :expiration_month,
    :expiration_year, :last_4, :token, :updated_at
  ]
end

+ (Object) _new(*args)

:nodoc:



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

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

+ (Object) create(attributes)



33
34
35
# File 'lib/braintree/credit_card.rb', line 33

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

+ (Object) create!(attributes)



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

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



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

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



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

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)



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

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

+ (Object) credit!(token, transaction_attributes)



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

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

+ (Object) delete(token)



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

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

+ (Object) expired(options = {})



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

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

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



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

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

+ (Object) find(token)



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

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

+ (Object) sale(token, transaction_attributes)



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

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

+ (Object) sale!(token, transaction_attributes)



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

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

+ (Object) update(token, attributes)



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

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

+ (Object) update!(token, attributes)



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

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



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

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



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

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.



218
219
220
221
# File 'lib/braintree/credit_card.rb', line 218

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



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

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



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

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)


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

def default?
  @default
end

- (Object) delete

Deprecated. Use Braintree::CreditCard.delete

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



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

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



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

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

- (Boolean) expired?

Returns true if the credit card is expired.

Returns:

  • (Boolean)


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

def expired?
  @expired
end

- (Object) inspect

:nodoc:



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

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



177
178
179
# File 'lib/braintree/credit_card.rb', line 177

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



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

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



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

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



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

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



212
213
214
215
# File 'lib/braintree/credit_card.rb', line 212

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