Class: Braintree::Transaction

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

Overview

Direct Known Subclasses

TestTransaction

Defined Under Namespace

Modules: CreatedUsing, EscrowStatus, GatewayRejectionReason, IndustryType, Source, Status, Type Classes: AddressDetails, ApplePayDetails, CreditCardDetails, CustomerDetails, DisbursementDetails, PayPalDetails, 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:



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'lib/braintree/transaction.rb', line 233

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)
  @paypal_details = PayPalDetails.new(@paypal)
  @apple_pay_details = ApplePayDetails.new(@apple_pay)
  disputes.map! { |attrs| Dispute._new(attrs) } if disputes
  @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
  @payment_instrument_type = attributes[:payment_instrument_type]
  @risk_data = RiskData.new(attributes[:risk_data]) if attributes[:risk_data]
end

Instance Attribute Details

#add_onsObject (readonly)

Returns the value of attribute add_ons



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

def add_ons
  @add_ons
end

#additional_processor_responseObject (readonly)

The raw response from the processor.



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

def additional_processor_response
  @additional_processor_response
end

#amountObject (readonly)

Returns the value of attribute amount



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

def amount
  @amount
end

#apple_pay_detailsObject (readonly)

Returns the value of attribute apple_pay_details



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

def apple_pay_details
  @apple_pay_details
end

#avs_error_response_codeObject (readonly)

Returns the value of attribute avs_error_response_code



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

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



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

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



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

def avs_street_address_response_code
  @avs_street_address_response_code
end

#billing_detailsObject (readonly)

Returns the value of attribute billing_details



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

def billing_details
  @billing_details
end

#channelObject (readonly)

Returns the value of attribute channel



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

def channel
  @channel
end

#created_atObject (readonly)

Returns the value of attribute created_at



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

def created_at
  @created_at
end

#credit_card_detailsObject (readonly)

Returns the value of attribute credit_card_details



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

def credit_card_details
  @credit_card_details
end

#currency_iso_codeObject (readonly)

Returns the value of attribute currency_iso_code



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

def currency_iso_code
  @currency_iso_code
end

#custom_fieldsObject (readonly)

Returns the value of attribute custom_fields



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

def custom_fields
  @custom_fields
end

#customer_detailsObject (readonly)

Returns the value of attribute customer_details



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

def customer_details
  @customer_details
end

#cvv_response_codeObject (readonly)

Returns the value of attribute cvv_response_code



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

def cvv_response_code
  @cvv_response_code
end

#descriptorObject (readonly)

Returns the value of attribute descriptor



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

def descriptor
  @descriptor
end

#disbursement_detailsObject (readonly)

Returns the value of attribute disbursement_details



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

def disbursement_details
  @disbursement_details
end

#discountsObject (readonly)

Returns the value of attribute discounts



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

def discounts
  @discounts
end

#disputesObject (readonly)

Returns the value of attribute disputes



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

def disputes
  @disputes
end

#escrow_statusObject (readonly)

Returns the value of attribute escrow_status



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

def escrow_status
  @escrow_status
end

#gateway_rejection_reasonObject (readonly)

Returns the value of attribute gateway_rejection_reason



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

def gateway_rejection_reason
  @gateway_rejection_reason
end

#idObject (readonly)

Returns the value of attribute id



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

def id
  @id
end

#merchant_account_idObject (readonly)

Returns the value of attribute merchant_account_id



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

def 
  @merchant_account_id
end

#order_idObject (readonly)

Returns the value of attribute order_id



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

def order_id
  @order_id
end

#payment_instrument_typeObject (readonly)

Returns the value of attribute payment_instrument_type



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

def payment_instrument_type
  @payment_instrument_type
end

#paypal_detailsObject (readonly)

Returns the value of attribute paypal_details



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

def paypal_details
  @paypal_details
end

#plan_idObject (readonly)

Returns the value of attribute plan_id



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

def plan_id
  @plan_id
end

#processor_authorization_codeObject (readonly)

The authorization code from the processor.



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

def processor_authorization_code
  @processor_authorization_code
end

#processor_response_codeObject (readonly)

The response code from the processor.



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

def processor_response_code
  @processor_response_code
end

#processor_response_textObject (readonly)

The response text from the processor.



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

def processor_response_text
  @processor_response_text
end

#processor_settlement_response_codeObject (readonly)

The settlement response code from the processor.



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

def processor_settlement_response_code
  @processor_settlement_response_code
end

#processor_settlement_response_textObject (readonly)

The settlement response text from the processor.



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

def processor_settlement_response_text
  @processor_settlement_response_text
end

#purchase_order_numberObject (readonly)

Returns the value of attribute purchase_order_number



100
101
102
# File 'lib/braintree/transaction.rb', line 100

def purchase_order_number
  @purchase_order_number
end

#recurringObject (readonly)

Returns the value of attribute recurring



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

def recurring
  @recurring
end

#refund_idsObject (readonly)

Returns the value of attribute refund_ids



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

def refund_ids
  @refund_ids
end

#refunded_transaction_idObject (readonly)

Returns the value of attribute refunded_transaction_id



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

def refunded_transaction_id
  @refunded_transaction_id
end

#risk_dataObject (readonly)

Returns the value of attribute risk_data



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

def risk_data
  @risk_data
end

#service_fee_amountObject (readonly)

Returns the value of attribute service_fee_amount



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

def service_fee_amount
  @service_fee_amount
end

#settlement_batch_idObject (readonly)

Returns the value of attribute settlement_batch_id



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

def settlement_batch_id
  @settlement_batch_id
end

#shipping_detailsObject (readonly)

Returns the value of attribute shipping_details



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

def shipping_details
  @shipping_details
end

#statusObject (readonly)

See Transaction::Status



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

def status
  @status
end

#status_historyObject (readonly)

Returns the value of attribute status_history



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

def status_history
  @status_history
end

#subscription_detailsObject (readonly)

Returns the value of attribute subscription_details



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

def subscription_details
  @subscription_details
end

#subscription_idObject (readonly)

Returns the value of attribute subscription_id



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

def subscription_id
  @subscription_id
end

#tax_amountObject (readonly)

Returns the value of attribute tax_amount



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

def tax_amount
  @tax_amount
end

#tax_exemptObject (readonly)

Returns the value of attribute tax_exempt



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

def tax_exempt
  @tax_exempt
end

#typeObject (readonly)

Will either be “sale” or “credit”



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

def type
  @type
end

#updated_atObject (readonly)

Returns the value of attribute updated_at



112
113
114
# File 'lib/braintree/transaction.rb', line 112

def updated_at
  @updated_at
end

#voice_referral_numberObject (readonly)

Returns the value of attribute voice_referral_number



99
100
101
# File 'lib/braintree/transaction.rb', line 99

def voice_referral_number
  @voice_referral_number
end

Class Method Details

._attributesObject

:nodoc:



388
389
390
# File 'lib/braintree/transaction.rb', line 388

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

._new(*args) ⇒ Object

:nodoc:



383
384
385
# File 'lib/braintree/transaction.rb', line 383

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

.cancel_release(transaction_id) ⇒ Object



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

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

.cancel_release!(transaction_id) ⇒ Object



131
132
133
# File 'lib/braintree/transaction.rb', line 131

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

.clone_transaction(transaction_id, attributes) ⇒ Object



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

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

.clone_transaction!(transaction_id, attributes) ⇒ Object



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

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

.create(attributes) ⇒ Object



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

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

.create!(attributes) ⇒ Object



123
124
125
# File 'lib/braintree/transaction.rb', line 123

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



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

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



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

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



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

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

.credit!(attributes) ⇒ Object



163
164
165
# File 'lib/braintree/transaction.rb', line 163

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

.find(id) ⇒ Object



168
169
170
# File 'lib/braintree/transaction.rb', line 168

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

.hold_in_escrow(id) ⇒ Object



172
173
174
# File 'lib/braintree/transaction.rb', line 172

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

.hold_in_escrow!(id) ⇒ Object



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

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

.refund(id, amount = nil) ⇒ Object



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

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

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



186
187
188
# File 'lib/braintree/transaction.rb', line 186

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

.release_from_escrow(transaction_id) ⇒ Object



205
206
207
# File 'lib/braintree/transaction.rb', line 205

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

.release_from_escrow!(transaction_id) ⇒ Object



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

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

.sale(attributes) ⇒ Object



191
192
193
# File 'lib/braintree/transaction.rb', line 191

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

.sale!(attributes) ⇒ Object



196
197
198
# File 'lib/braintree/transaction.rb', line 196

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

.search(&block) ⇒ Object



201
202
203
# File 'lib/braintree/transaction.rb', line 201

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

.submit_for_settlement(transaction_id, amount = nil) ⇒ Object



214
215
216
# File 'lib/braintree/transaction.rb', line 214

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



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

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



224
225
226
# File 'lib/braintree/transaction.rb', line 224

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

.void!(transaction_id) ⇒ Object



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

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.



258
259
260
261
# File 'lib/braintree/transaction.rb', line 258

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.

Returns:

  • (Boolean)


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

def disbursed?
  @disbursement_details.valid?
end

#inspectObject

:nodoc:



263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/braintree/transaction.rb', line 263

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



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

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



300
301
302
303
# File 'lib/braintree/transaction.rb', line 300

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.

Returns:

  • (Boolean)


291
292
293
# File 'lib/braintree/transaction.rb', line 291

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



308
309
310
311
312
313
314
315
# File 'lib/braintree/transaction.rb', line 308

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



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

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.



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

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.



338
339
340
341
# File 'lib/braintree/transaction.rb', line 338

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.



347
348
349
350
# File 'lib/braintree/transaction.rb', line 347

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.



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

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



364
365
366
367
368
369
370
371
# File 'lib/braintree/transaction.rb', line 364

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



376
377
378
379
# File 'lib/braintree/transaction.rb', line 376

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