Class: Braintree::Transaction


Creating a Transaction

At minimum, an amount, credit card number, and credit card expiration date are required. Minimalistic example:

 Braintree::Transaction.sale!(
   :amount => "100.00",
   :credit_card => {
     :number => "5105105105105100",
     :expiration_date => "05/2012"
   }
 )

Full example:

 Braintree::Transaction.sale!(
   :amount => "100.00",
   :order_id => "123",
   :credit_card => {
     # if :token is omitted, the gateway will generate a token
     :token => "credit_card_123",
     :number => "5105105105105100",
     :expiration_date => "05/2011",
     :cvv => "123"
   },
   :customer => {
     # if :id is omitted, the gateway will generate an id
     :id => "customer_123",
     :first_name => "Dan",
     :last_name => "Smith",
     :company => "Braintree Payment Solutions",
     :email => "dan@example.com",
     :phone => "419-555-1234",
     :fax => "419-555-1235",
     :website => "http://braintreepaymentsolutions.com"
   },
   :billing => {
     :first_name => "Carl",
     :last_name => "Jones",
     :company => "Braintree",
     :street_address => "123 E Main St",
     :extended_address => "Suite 403",
     :locality => "Chicago",
     :region => "IL",
     :postal_code => "60622",
     :country_name => "United States of America"
   },
   :shipping => {
     :first_name => "Andrew",
     :last_name => "Mason",
     :company => "Braintree",
     :street_address => "456 W Main St",
     :extended_address => "Apt 2F",
     :locality => "Bartlett",
     :region => "IL",
     :postal_code => "60103",
     :country_name => "United States of America"
   },
   :custom_fields => {
     :birthdate => "11/13/1954"
   }
 )

Storing in the Vault

The customer and credit card information used for a transaction can be stored in the vault by setting transaction[options][store_in_vault] to true.

  transaction = Braintree::Transaction.sale!(
    :customer => {
      :first_name => "Adam",
      :last_name => "Williams"
    },
    :credit_card => {
      :number => "5105105105105100",
      :expiration_date => "05/2012"
    },
    :options => {
      :store_in_vault => true
    }
  )
  transaction.customer_details.id
  # => "865534"
  transaction.credit_card_details.token
  # => "6b6m"

To also store the billing address in the vault, pass the add_billing_address_to_payment_method option.

  Braintree::Transaction.sale!(
    # ...
    :options => {
      :store_in_vault => true
      :add_billing_address_to_payment_method => true
    }
  )

Submitting for Settlement

This can only be done when the transction‘s status is authorized. If amount is not specified, the full authorized amount will be settled. If you would like to settle less than the full authorized amount, pass the desired amount. You cannot settle more than the authorized amount.

A transaction can be submitted for settlement when created by setting transaction[options][submit_for_settlement] to true.

  transaction = Braintree::Transaction.sale!(
    :amount => "100.00",
    :credit_card => {
      :number => "5105105105105100",
      :expiration_date => "05/2012"
    },
    :options => {
      :submit_for_settlement => true
    }
  )

More Information

For more detailed documentation on Transactions, see www.braintreepaymentsolutions.com/gateway/transaction-api


Attributes
[R] amount
[R] avs_error_response_code
[R] avs_postal_code_response_code
[R] avs_street_address_response_code
[R] billing_details
[R] created_at
[R] credit_card_details
[R] currency_iso_code
[R] custom_fields
[R] customer_details
[R] cvv_response_code
[R] gateway_rejection_reason
[R] id
[R] merchant_account_id
[R] order_id
[R] processor_authorization_code The authorization code from the processor.
[R] processor_response_code The response code from the processor.
[R] processor_response_text The response text from the processor.
[R] refund_id
[R] refunded_transaction_id
[R] shipping_details
[R] status See Transaction::Status
[R] status_history
[R] subscription_id
[R] type Will either be "sale" or "credit"
[R] updated_at

Public Class Methods
_fetch_transactions(search, ids)
create(attributes)
create!(attributes)
create_from_transparent_redirect(query_string)
create_transaction_url()

The URL to use to create transactions via transparent redirect.

credit(attributes)

Creates a credit transaction.

credit!(attributes)
find(id)

Finds the transaction with the given id. Raises a Braintree::NotFoundError if the transaction cannot be found.

sale(attributes)

Creates a sale transaction.

sale!(attributes)
search(&block)

Returns a ResourceCollection of transactions matching the search query. If query is a string, the search will be a basic search. If query is a hash, the search will be an advanced search. See: www.braintreepaymentsolutions.com/gateway/transaction-api#searching

submit_for_settlement(transaction_id, amount = nil)

Submits transaction with transaction_id for settlement.

submit_for_settlement!(transaction_id, amount = nil)
void(transaction_id)

Voids the transaction with the given transaction_id

void!(transaction_id)

Public Instance Methods
==(other)

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

refund(amount = nil)

Creates a credit transaction that refunds this transaction.

refunded?()

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

submit_for_settlement(amount = nil)

Submits the transaction for settlement.

submit_for_settlement!(amount = nil)
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.

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.

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.

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.

void()

Voids the transaction.

void!()

© Copyright 2009 Braintree Payment Solutions. All Rights Reserved.