Class: Braintree::Transaction

Inherits:
Object
  • Object
show all
Includes:
BaseModule
Defined in:
lib/braintree/transaction.rb,
lib/braintree/transaction/status_details.rb,
lib/braintree/transaction/address_details.rb,
lib/braintree/transaction/customer_details.rb,
lib/braintree/transaction/credit_card_details.rb,
lib/braintree/transaction/disbursement_details.rb,
lib/braintree/transaction/subscription_details.rb

Overview

Defined Under Namespace

Modules: CreatedUsing, EscrowStatus, GatewayRejectionReason, Source, Status, Type Classes: AddressDetails, CreditCardDetails, CustomerDetails, DisbursementDetails, StatusDetails, SubscriptionDetails

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

:nodoc:



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/braintree/transaction.rb', line 212

def initialize(gateway, attributes) # :nodoc:
  @gateway = gateway
  set_instance_variables_from_hash(attributes)
  @amount = Util.to_big_decimal(amount)
  @credit_card_details = CreditCardDetails.new(@credit_card)
  @service_fee_amount = Util.to_big_decimal(service_fee_amount)
  @subscription_details = SubscriptionDetails.new(@subscription)
  @customer_details = CustomerDetails.new(@customer)
  @billing_details = AddressDetails.new(@billing)
  @disbursement_details = DisbursementDetails.new(@disbursement_details)
  @shipping_details = AddressDetails.new(@shipping)
  @status_history = attributes[:status_history] ? attributes[:status_history].map { |s| StatusDetails.new(s) } : []
  @tax_amount = Util.to_big_decimal(tax_amount)
  @descriptor = Descriptor.new(@descriptor)
  @custom_fields = attributes[:custom_fields].is_a?(Hash) ? attributes[:custom_fields] : {}
  add_ons.map! { |attrs| AddOn._new(attrs) } if add_ons
  discounts.map! { |attrs| Discount._new(attrs) } if discounts
end

Instance Attribute Details

#add_onsObject (readonly)

Returns the value of attribute add_ons



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

def add_ons
  @add_ons
end

#amountObject (readonly)

Returns the value of attribute amount



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

def amount
  @amount
end

#avs_error_response_codeObject (readonly)

Returns the value of attribute avs_error_response_code



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

def avs_error_response_code
  @avs_error_response_code
end

#avs_postal_code_response_codeObject (readonly)

Returns the value of attribute avs_postal_code_response_code



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

def avs_postal_code_response_code
  @avs_postal_code_response_code
end

#avs_street_address_response_codeObject (readonly)

Returns the value of attribute avs_street_address_response_code



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

def avs_street_address_response_code
  @avs_street_address_response_code
end

#billing_detailsObject (readonly)

Returns the value of attribute billing_details



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

def billing_details
  @billing_details
end

#channelObject (readonly)

Returns the value of attribute channel



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

def channel
  @channel
end

#created_atObject (readonly)

Returns the value of attribute created_at



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

def created_at
  @created_at
end

#credit_card_detailsObject (readonly)

Returns the value of attribute credit_card_details



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

def credit_card_details
  @credit_card_details
end

#currency_iso_codeObject (readonly)

Returns the value of attribute currency_iso_code



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

def currency_iso_code
  @currency_iso_code
end

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields



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

def custom_fields
  @custom_fields
end

#customer_detailsObject (readonly)

Returns the value of attribute customer_details



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

def customer_details
  @customer_details
end

#cvv_response_codeObject (readonly)

Returns the value of attribute cvv_response_code



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

def cvv_response_code
  @cvv_response_code
end

#descriptorObject (readonly)

Returns the value of attribute descriptor



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

def descriptor
  @descriptor
end

#disbursement_detailsObject (readonly)

Returns the value of attribute disbursement_details



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

def disbursement_details
  @disbursement_details
end

#discountsObject (readonly)

Returns the value of attribute discounts



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

def discounts
  @discounts
end

#escrow_statusObject (readonly)

Returns the value of attribute escrow_status



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

def escrow_status
  @escrow_status
end

#gateway_rejection_reasonObject (readonly)

Returns the value of attribute gateway_rejection_reason



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

def gateway_rejection_reason
  @gateway_rejection_reason
end

#idObject (readonly)

Returns the value of attribute id



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

def id
  @id
end

#merchant_account_idObject (readonly)

Returns the value of attribute merchant_account_id



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

def 
  @merchant_account_id
end

#order_idObject (readonly)

Returns the value of attribute order_id



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

def order_id
  @order_id
end

#plan_idObject (readonly)

Returns the value of attribute plan_id



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

def plan_id
  @plan_id
end

#processor_authorization_codeObject (readonly)

The authorization code from the processor.



75
76
77
# File 'lib/braintree/transaction.rb', line 75

def processor_authorization_code
  @processor_authorization_code
end

#processor_response_codeObject (readonly)

The response code from the processor.



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

def processor_response_code
  @processor_response_code
end

#processor_response_textObject (readonly)

The response text from the processor.



79
80
81
# File 'lib/braintree/transaction.rb', line 79

def processor_response_text
  @processor_response_text
end

#purchase_order_numberObject (readonly)

Returns the value of attribute purchase_order_number



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

def purchase_order_number
  @purchase_order_number
end

#recurringObject (readonly)

Returns the value of attribute recurring



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

def recurring
  @recurring
end

#refund_idsObject (readonly)

Returns the value of attribute refund_ids



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

def refund_ids
  @refund_ids
end

#refunded_transaction_idObject (readonly)

Returns the value of attribute refunded_transaction_id



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

def refunded_transaction_id
  @refunded_transaction_id
end

#service_fee_amountObject (readonly)

Returns the value of attribute service_fee_amount



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

def service_fee_amount
  @service_fee_amount
end

#settlement_batch_idObject (readonly)

Returns the value of attribute settlement_batch_id



84
85
86
# File 'lib/braintree/transaction.rb', line 84

def settlement_batch_id
  @settlement_batch_id
end

#shipping_detailsObject (readonly)

Returns the value of attribute shipping_details



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

def shipping_details
  @shipping_details
end

#statusObject (readonly)

See Transaction::Status



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

def status
  @status
end

#status_historyObject (readonly)

Returns the value of attribute status_history



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

def status_history
  @status_history
end

#subscription_detailsObject (readonly)

Returns the value of attribute subscription_details



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

def subscription_details
  @subscription_details
end

#subscription_idObject (readonly)

Returns the value of attribute subscription_id



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

def subscription_id
  @subscription_id
end

#tax_amountObject (readonly)

Returns the value of attribute tax_amount



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

def tax_amount
  @tax_amount
end

#tax_exemptObject (readonly)

Returns the value of attribute tax_exempt



90
91
92
# File 'lib/braintree/transaction.rb', line 90

def tax_exempt
  @tax_exempt
end

#typeObject (readonly)

Will either be “sale” or “credit”



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

def type
  @type
end

#updated_atObject (readonly)

Returns the value of attribute updated_at



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

def updated_at
  @updated_at
end

#voice_referral_numberObject (readonly)

Returns the value of attribute voice_referral_number



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

def voice_referral_number
  @voice_referral_number
end

Class Method Details

._attributesObject

:nodoc:



362
363
364
# File 'lib/braintree/transaction.rb', line 362

def self._attributes # :nodoc:
  [:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :subscription_details, :type, :updated_at]
end

._new(*args) ⇒ Object

:nodoc:



357
358
359
# File 'lib/braintree/transaction.rb', line 357

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

.cancel_release(transaction_id) ⇒ Object



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

def self.cancel_release(transaction_id)
  Configuration.gateway.transaction.cancel_release(transaction_id)
end

.cancel_release!(transaction_id) ⇒ Object



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

def self.cancel_release!(transaction_id)
  return_object_or_raise(:transaction) { cancel_release(transaction_id) }
end

.clone_transaction(transaction_id, attributes) ⇒ Object



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

def self.clone_transaction(transaction_id, attributes)
  Configuration.gateway.transaction.clone_transaction(transaction_id, attributes)
end

.clone_transaction!(transaction_id, attributes) ⇒ Object



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

def self.clone_transaction!(transaction_id, attributes)
  return_object_or_raise(:transaction) { clone_transaction(transaction_id, attributes) }
end

.create(attributes) ⇒ Object



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

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

.create!(attributes) ⇒ Object



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

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

.create_from_transparent_redirect(query_string) ⇒ Object

Deprecated. Use Braintree::TransparentRedirect.confirm

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



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

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

.create_transaction_urlObject

Deprecated. Use Braintree::TransparentRedirect.url

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



133
134
135
136
# File 'lib/braintree/transaction.rb', line 133

def self.create_transaction_url
  warn "[DEPRECATED] Transaction.create_transaction_url is deprecated. Please use TransparentRedirect.url"
  Configuration.gateway.transaction.create_transaction_url
end

.credit(attributes) ⇒ Object



138
139
140
# File 'lib/braintree/transaction.rb', line 138

def self.credit(attributes)
  Configuration.gateway.transaction.credit(attributes)
end

.credit!(attributes) ⇒ Object



142
143
144
# File 'lib/braintree/transaction.rb', line 142

def self.credit!(attributes)
  return_object_or_raise(:transaction) { credit(attributes) }
end

.find(id) ⇒ Object



147
148
149
# File 'lib/braintree/transaction.rb', line 147

def self.find(id)
  Configuration.gateway.transaction.find(id)
end

.hold_in_escrow(id) ⇒ Object



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

def self.hold_in_escrow(id)
  Configuration.gateway.transaction.hold_in_escrow(id)
end

.hold_in_escrow!(id) ⇒ Object



155
156
157
# File 'lib/braintree/transaction.rb', line 155

def self.hold_in_escrow!(id)
  return_object_or_raise(:transaction) { hold_in_escrow(id) }
end

.refund(id, amount = nil) ⇒ Object



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

def self.refund(id, amount = nil)
  Configuration.gateway.transaction.refund(id, amount)
end

.refund!(id, amount = nil) ⇒ Object



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

def self.refund!(id, amount = nil)
  return_object_or_raise(:transaction) { refund(id, amount) }
end

.release_from_escrow(transaction_id) ⇒ Object



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

def self.release_from_escrow(transaction_id)
  Configuration.gateway.transaction.release_from_escrow(transaction_id)
end

.release_from_escrow!(transaction_id) ⇒ Object



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

def self.release_from_escrow!(transaction_id)
  return_object_or_raise(:transaction) { release_from_escrow(transaction_id) }
end

.sale(attributes) ⇒ Object



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

def self.sale(attributes)
  Configuration.gateway.transaction.sale(attributes)
end

.sale!(attributes) ⇒ Object



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

def self.sale!(attributes)
  return_object_or_raise(:transaction) { sale(attributes) }
end

.search(&block) ⇒ Object



180
181
182
# File 'lib/braintree/transaction.rb', line 180

def self.search(&block)
  Configuration.gateway.transaction.search(&block)
end

.submit_for_settlement(transaction_id, amount = nil) ⇒ Object



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

def self.submit_for_settlement(transaction_id, amount = nil)
  Configuration.gateway.transaction.submit_for_settlement(transaction_id, amount)
end

.submit_for_settlement!(transaction_id, amount = nil) ⇒ Object



198
199
200
# File 'lib/braintree/transaction.rb', line 198

def self.submit_for_settlement!(transaction_id, amount = nil)
  return_object_or_raise(:transaction) { submit_for_settlement(transaction_id, amount) }
end

.void(transaction_id) ⇒ Object



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

def self.void(transaction_id)
  Configuration.gateway.transaction.void(transaction_id)
end

.void!(transaction_id) ⇒ Object



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

def self.void!(transaction_id)
  return_object_or_raise(:transaction) { void(transaction_id) }
end

Instance Method Details

#==(other) ⇒ Object

True if other is a Braintree::Transaction with the same id.



232
233
234
235
# File 'lib/braintree/transaction.rb', line 232

def ==(other)
  return false unless other.is_a?(Transaction)
  id == other.id
end

#disbursed?Boolean

Returns true if the transaction has been disbursed. False otherwise.



270
271
272
# File 'lib/braintree/transaction.rb', line 270

def disbursed?
  @disbursement_details.valid?
end

#inspectObject

:nodoc:



237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/braintree/transaction.rb', line 237

def inspect # :nodoc:
  first = [:id, :type, :amount, :status]
  order = first + (self.class._attributes - first)
  nice_attributes = order.map do |attr|
    if attr == :amount
      self.amount ? "amount: #{self.amount.to_s("F").inspect}" : "amount: nil"
    else
      "#{attr}: #{send(attr).inspect}"
    end
  end
  "#<#{self.class} #{nice_attributes.join(', ')}>"
end

#refund(amount = nil) ⇒ Object

Deprecated. Use Braintree::Transaction.refund

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



253
254
255
256
257
258
259
260
261
262
# File 'lib/braintree/transaction.rb', line 253

def refund(amount = nil)
  warn "[DEPRECATED] refund as an instance method is deprecated. Please use Transaction.refund"
  result = @gateway.transaction.refund(id, amount)

  if result.success?
    SuccessfulResult.new(:new_transaction => result.transaction)
  else
    result
  end
end

#refund_idObject



274
275
276
277
# File 'lib/braintree/transaction.rb', line 274

def refund_id
  warn "[DEPRECATED] Transaction.refund_id is deprecated. Please use Transaction.refund_ids"
  @refund_id
end

#refunded?Boolean

Returns true if the transaction has been refunded. False otherwise.



265
266
267
# File 'lib/braintree/transaction.rb', line 265

def refunded?
  !@refund_id.nil?
end

#submit_for_settlement(amount = nil) ⇒ Object

Deprecated. Use Braintree::Transaction.submit_for_settlement

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



282
283
284
285
286
287
288
289
# File 'lib/braintree/transaction.rb', line 282

def submit_for_settlement(amount = nil)
  warn "[DEPRECATED] submit_for_settlement as an instance method is deprecated. Please use Transaction.submit_for_settlement"
  result = @gateway.transaction.submit_for_settlement(id, amount)
  if result.success?
    copy_instance_variables_from_object result.transaction
  end
  result
end

#submit_for_settlement!(amount = nil) ⇒ Object

Deprecated. Use Braintree::Transaction.submit_for_settlement!

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



294
295
296
297
# File 'lib/braintree/transaction.rb', line 294

def submit_for_settlement!(amount = nil)
  warn "[DEPRECATED] submit_for_settlement! as an instance method is deprecated. Please use Transaction.submit_for_settlement!"
  return_object_or_raise(:transaction) { submit_for_settlement(amount) }
end

#vault_billing_addressObject

If this transaction was stored in the vault, or created from vault records, vault_billing_address will return the associated Braintree::Address. Because the vault billing address can be updated after the transaction was created, the attributes on vault_billing_address may not match the attributes on billing_details.



303
304
305
306
# File 'lib/braintree/transaction.rb', line 303

def vault_billing_address
  return nil if billing_details.id.nil?
  @gateway.address.find(customer_details.id, billing_details.id)
end

#vault_credit_cardObject

If this transaction was stored in the vault, or created from vault records, vault_credit_card will return the associated Braintree::CreditCard. Because the vault credit card can be updated after the transaction was created, the attributes on vault_credit_card may not match the attributes on credit_card_details.



312
313
314
315
# File 'lib/braintree/transaction.rb', line 312

def vault_credit_card
  return nil if credit_card_details.token.nil?
  @gateway.credit_card.find(credit_card_details.token)
end

#vault_customerObject

If this transaction was stored in the vault, or created from vault records, vault_customer will return the associated Braintree::Customer. Because the vault customer can be updated after the transaction was created, the attributes on vault_customer may not match the attributes on customer_details.



321
322
323
324
# File 'lib/braintree/transaction.rb', line 321

def vault_customer
  return nil if customer_details.id.nil?
  @gateway.customer.find(customer_details.id)
end

#vault_shipping_addressObject

If this transaction was stored in the vault, or created from vault records, vault_shipping_address will return the associated Braintree::Address. Because the vault shipping address can be updated after the transaction was created, the attributes on vault_shipping_address may not match the attributes on shipping_details.



330
331
332
333
# File 'lib/braintree/transaction.rb', line 330

def vault_shipping_address
  return nil if shipping_details.id.nil?
  @gateway.address.find(customer_details.id, shipping_details.id)
end

#voidObject

Deprecated. Use Braintree::Transaction.void

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



338
339
340
341
342
343
344
345
# File 'lib/braintree/transaction.rb', line 338

def void
  warn "[DEPRECATED] void as an instance method is deprecated. Please use Transaction.void"
  result = @gateway.transaction.void(id)
  if result.success?
    copy_instance_variables_from_object result.transaction
  end
  result
end

#void!Object

Deprecated. Use Braintree::Transaction.void!

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



350
351
352
353
# File 'lib/braintree/transaction.rb', line 350

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