Searching for Transactions

If you want to look up a single transaction using its ID, use the find method.

transaction = braintree.Transaction.find("the_transaction_id")

Otherwise, you can search for transactions using a variety of criteria. For operators available on search fields, see the search fields page. For conciseness, we’re going to show searching on several fields at once, but you can search on as many or as few as you would like in a single search.

All examples assume version 2.5.0 or greater. Click here for an example of searching before version 2.5.0.

Credit Card

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_cardholder_name == "Patrick Smith",
    braintree.TransactionSearch.credit_card_expiration_date == "05/2012",
    braintree.TransactionSearch.credit_card_number == "5105105105105100"
)

Searching on credit card number has a few restrictions. If you search using “starts with” you can only enter up to the first 6 digits. If you search using “ends with” you can only enter the last 4 digits. And you can’t search on “contains.”

Expiration date also has restrictions. “is” and “is not” work, while “starts with,” “ends with,” and “contains” do not.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_number.starts_with("510510")
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_number.ends_with("5100")
)

Customer

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.customer_company == "Braintree",
    braintree.TransactionSearch.customer_email == "smith@example.com",
    braintree.TransactionSearch.customer_fax == "5551231234",
    braintree.TransactionSearch.customer_first_name == "Tom",
    braintree.TransactionSearch.customer_last_name == "Smith",
    braintree.TransactionSearch.customer_phone == "5551231234",
    braintree.TransactionSearch.customer_website == "http://example.com"
)

See search fields for a list of available operators. They allow you to do nice things like this:

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.customer_email.ends_with("example.com")
)

Billing Address

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.billing_first_name == "Paul",
    braintree.TransactionSearch.billing_last_name == "Smith",
    braintree.TransactionSearch.billing_company == "Braintree",
    braintree.TransactionSearch.billing_street_address == "123 Main St",
    braintree.TransactionSearch.billing_extended_address == "Suite 123",
    braintree.TransactionSearch.billing_locality == "Chicago",
    braintree.TransactionSearch.billing_region == "IL",
    braintree.TransactionSearch.billing_postal_code == "12345",
    braintree.TransactionSearch.billing_country_name == "United States of America"
)

Shipping Address

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.shipping_first_name == "Paul",
    braintree.TransactionSearch.shipping_last_name == "Smith",
    braintree.TransactionSearch.shipping_company == "Braintree",
    braintree.TransactionSearch.shipping_street_address == "123 Main St",
    braintree.TransactionSearch.shipping_extended_address == "Suite 123",
    braintree.TransactionSearch.shipping_locality == "Chicago",
    braintree.TransactionSearch.shipping_region == "IL",
    braintree.TransactionSearch.shipping_postal_code == "12345",
    braintree.TransactionSearch.shipping_country_name == "United States of America"
)

Other Top-level Attributes

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.order_id == "myorder",
    braintree.TransactionSearch.processor_authorization_code == "123456"
)

Vault Associations

You can search for transactions associated to a payment method token.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.payment_method_token == "the_token"
)

Or a customer ID.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.customer_id == "the_customer_id"
)

How the transaction was created

You can search for transactions that were created using a token.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.created_using == braintree.Transaction.CreatedUsing.Token
)

Or transactions that were created using full credit card information.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.created_using == braintree.Transaction.CreatedUsing.FullInformation
)

Those are the only two choices for created_using.

Customer Location

Customers in the US.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_customer_location == braintree.CreditCard.CustomerLocation.US
)

Or international customers.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_customer_location == braintree.CreditCard.CustomerLocation.International
)

Merchant Account

A specific one.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.merchant_account_id == "the_merchant_account_id"
)

Or any of several.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.merchant_account_id.in_list("account_1", "account_2")
)

Credit Card Type

A specific one.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_card_type == braintree.CreditCard.CardType.Visa
)

Or any of several.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_card_type == braintree.CreditCard.CardType.Visa
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.credit_card_card_type.in_list(
        braintree.CreditCard.CardType.Visa,
        braintree.CreditCard.CardType.MasterCard
    )
)

Transaction Status

Another one or many search field.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.status == braintree.Transaction.Status.ProcessorDeclined
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.status.in_list(
        braintree.Transaction.Status.ProcessorDeclined,
        braintree.Transaction.Status.GatewayRejected
    )
)

Transaction Source

API, Control Panel, or Recurring Billing.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.source == braintree.Transaction.Source.Api
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.source.in_list(
        braintree.Transaction.Source.Api,
        braintree.Transaction.Source.ControlPanel,
        braintree.Transaction.Source.Recurring
    )
)

Transaction Type

The two types of transactions are sale and credit. Refunds are a special kind of credit, so there are some extra options around them.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.type == braintree.Transaction.Type.Sale
)

This will return all credits, regardless of whether they’re refunds, or standalone credits.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.type == braintree.Transaction.Type.Credit
)

If you only want the refunds:

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.type == braintree.Transaction.Type.Credit,
    braintree.TransactionSearch.refund == True
)

And if you only want the credits that aren’t refunds:

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.type == braintree.Transaction.Type.Credit,
    braintree.TransactionSearch.refund == False
)

Amount

It’s a range field.

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.amount.between("100.00", "200.00")
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.amount >= "100.00"
)

search_results = braintree.Transaction.search(
    braintree.TransactionSearch.amount <= "100.00"
)

Status Changes

You can search for transactions that entered a given status at a certain time. For instance, you can find all transactions which were submitted for settlement in the past 3 days.

You can search on these statuses:

A few examples:

search_results = braintree.Transaction.search(
  braintree.TransactionSearch.created_at.between(
    datetime.datetime(2009, 1, 1),
    datetime.datetime(2011, 1, 1)
  )
)
search_results = braintree.Transaction.search(
  braintree.TransactionSearch.settled_at >= datetime.datetime(2009, 1, 1)
)
search_results = braintree.Transaction.search(
  braintree.TransactionSearch.processor_declined_at >= datetime.datetime(2009, 1, 1)
)

Note: The time value will always be regarded as UTC.

Results will always be returned with time values in UTC.

Searching Prior to Version 2.5.0

Prior to version 2.5.0, literal lists must be passed as arguments to all search methods.

search_results = braintree.Transaction.search([
    braintree.TransactionSearch.merchant_account_id.in_list([
        "account_1",
        "account_2"
    ])
])

See Also