Skip to content
lyang edited this page Mar 17, 2013 · 2 revisions

Transaction only supports create. After creation, you can only change its status through each specific method.

Attributes

Create

[
  :amount, :billing, :channel, :custom_fields, :customer_id, :descriptor, :merchant_account_id,
  :options, :order_id, :payment_method_token, :purchase_order_number, :recurring, :shipping,
  :tax_amount, :tax_exempt, :type, :venmo_sdk_payment_method_code
]

Readonly

[
  :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code, :billing_details,
  :channel, :created_at, :credit_card, :credit_card_details, :currency_iso_code, :customer, :customer_details,
  :cvv_response_code, :plan_id, :purchase_order_number, :refund_ids, :refunded_transaction_id, :settlement_batch_id,
  :shipping_details, :status, :status_history, :subscription_details, :updated_at
]

Associations

AddOns (readonly collection)

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.add_ons # eager loaded collection

Discounts (readonly collection)

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.discounts # eager loaded collection

Customer

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.customer # Loaded from customer_details

CreditCard

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.credit_card # Loaded from credit_card_details

Subscription

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.subscription # Loaded from subscription_id

Billing (BraintreeRails::Address)

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.billing # Loaded from billing_details

Shipping (BraintreeRails::Address)

transaction = BraintreeRails::Transaction.find('transaction_id')
transaction.shipping # Loaded from shipping_details

Default Validations

[:amount, :presence => true, :numericality => {:greater_than_or_equal_to => 0}, :if => :new_record?],
[:type, :presence => true, :inclusion => {:in => %w(sale credit)}, :if => :new_record?],
[:status, :inclusion => {:in => [Braintree::Transaction::Status::Authorized]}, :on => :submit_for_settlement],
[:status, :inclusion => {:in => [Braintree::Transaction::Status::Settled, Braintree::Transaction::Status::Settling]}, :on => :refund],
[:status, :inclusion => {:in => [Braintree::Transaction::Status::Authorized, Braintree::Transaction::Status::SubmittedForSettlement]}, :on => :void]

A little more explanation

Transactions are not updatable. You can only change its status through the following methods:

  • submit_for_settlement
  • refund
  • void

Those method specific validations are only run when their corresponding method are called.

Association validations

In addition to the above, credit card validations will also kick in when creating transactions

  • must_have_credit_card
      if transaction.credit_card.blank?
        validate_customer_have_default_credit_card(transaction)
      elsif transaction.credit_card.new_record?
        validate_new_credit_card(transaction)
      end

Default Callbacks

(before|after)_validate
(before|around|after)_save
(before|around|after)_create
(before|around|after)_update
(before|around|after)_destroy

Additional callbacks

(before|around|after)_submit_for_settlement
(before|around|after)_void
(before|around|after)_refund

Convenient Methods

None

Supported REST APIs

Create

Transaction#submit_for_settlement

Transaction#void

Transaction#refund