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

- (Transaction) initialize(gateway, attributes)

: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

- (Object) add_ons (readonly)

Returns the value of attribute add_ons



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

def add_ons
  @add_ons
end

- (Object) amount (readonly)

Returns the value of attribute amount



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

def amount
  @amount
end

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

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

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

- (Object) billing_details (readonly)

Returns the value of attribute billing_details



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

def billing_details
  @billing_details
end

- (Object) channel (readonly)

Returns the value of attribute channel



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

def channel
  @channel
end

- (Object) created_at (readonly)

Returns the value of attribute created_at



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

def created_at
  @created_at
end

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

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

- (Object) custom_fields (readonly)

Returns the value of attribute custom_fields



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

def custom_fields
  @custom_fields
end

- (Object) customer_details (readonly)

Returns the value of attribute customer_details



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

def customer_details
  @customer_details
end

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

- (Object) descriptor (readonly)

Returns the value of attribute descriptor



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

def descriptor
  @descriptor
end

- (Object) disbursement_details (readonly)

Returns the value of attribute disbursement_details



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

def disbursement_details
  @disbursement_details
end

- (Object) discounts (readonly)

Returns the value of attribute discounts



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

def discounts
  @discounts
end

- (Object) escrow_status (readonly)

Returns the value of attribute escrow_status



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

def escrow_status
  @escrow_status
end

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

- (Object) id (readonly)

Returns the value of attribute id



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

def id
  @id
end

- (Object) merchant_account_id (readonly)

Returns the value of attribute merchant_account_id



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

def 
  @merchant_account_id
end

- (Object) order_id (readonly)

Returns the value of attribute order_id



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

def order_id
  @order_id
end

- (Object) plan_id (readonly)

Returns the value of attribute plan_id



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

def plan_id
  @plan_id
end

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

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

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

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

- (Object) recurring (readonly)

Returns the value of attribute recurring



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

def recurring
  @recurring
end

- (Object) refund_ids (readonly)

Returns the value of attribute refund_ids



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

def refund_ids
  @refund_ids
end

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

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

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

- (Object) shipping_details (readonly)

Returns the value of attribute shipping_details



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

def shipping_details
  @shipping_details
end

- (Object) status (readonly)

See Transaction::Status



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

def status
  @status
end

- (Object) status_history (readonly)

Returns the value of attribute status_history



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

def status_history
  @status_history
end

- (Object) subscription_details (readonly)

Returns the value of attribute subscription_details



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

def subscription_details
  @subscription_details
end

- (Object) subscription_id (readonly)

Returns the value of attribute subscription_id



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

def subscription_id
  @subscription_id
end

- (Object) tax_amount (readonly)

Returns the value of attribute tax_amount



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

def tax_amount
  @tax_amount
end

- (Object) tax_exempt (readonly)

Returns the value of attribute tax_exempt



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

def tax_exempt
  @tax_exempt
end

- (Object) type (readonly)

Will either be “sale” or “credit”



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

def type
  @type
end

- (Object) updated_at (readonly)

Returns the value of attribute updated_at



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

def updated_at
  @updated_at
end

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

+ (Object) _attributes

: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

+ (Object) _new(*args)

:nodoc:



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

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

+ (Object) cancel_release(transaction_id)



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

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

+ (Object) cancel_release!(transaction_id)



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

+ (Object) clone_transaction(transaction_id, attributes)



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

+ (Object) clone_transaction!(transaction_id, attributes)



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

+ (Object) create(attributes)



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

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

+ (Object) create!(attributes)



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

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

+ (Object) create_from_transparent_redirect(query_string)

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

+ (Object) create_transaction_url

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

+ (Object) credit(attributes)



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

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

+ (Object) credit!(attributes)



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

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

+ (Object) find(id)



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

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

+ (Object) hold_in_escrow(id)



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

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

+ (Object) hold_in_escrow!(id)



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

+ (Object) refund(id, amount = nil)



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

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

+ (Object) refund!(id, amount = nil)



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

+ (Object) release_from_escrow(transaction_id)



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

+ (Object) release_from_escrow!(transaction_id)



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

+ (Object) sale(attributes)



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

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

+ (Object) sale!(attributes)



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

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

+ (Object) search(&block)



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

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

+ (Object) submit_for_settlement(transaction_id, amount = nil)



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

+ (Object) submit_for_settlement!(transaction_id, amount = nil)



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

+ (Object) void(transaction_id)



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

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

+ (Object) void!(transaction_id)



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

- (Object) ==(other)

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

- (Boolean) disbursed?

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

Returns:

  • (Boolean)


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

def disbursed?
  @disbursement_details.valid?
end

- (Object) inspect

: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

- (Object) refund(amount = nil)

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

- (Object) refund_id



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

- (Boolean) refunded?

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

Returns:

  • (Boolean)


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

def refunded?
  !@refund_id.nil?
end

- (Object) submit_for_settlement(amount = nil)

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

- (Object) submit_for_settlement!(amount = nil)

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

- (Object) vault_billing_address

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

- (Object) vault_credit_card

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

- (Object) vault_customer

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

- (Object) vault_shipping_address

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

- (Object) void

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

- (Object) void!

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