Searching for Transactions

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

Transaction transaction = gateway.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.

Credit Card

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardCardholderName().is("Patrick Smith").
    creditCardExpirationDate().is("05/2012").
    creditCardNumber().is("5105105105105100");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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.

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardNumber().startsWith("510510");

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardNumber().endsWith("5100");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Customer

TransactionSearchRequest request = new TransactionSearchRequest().
    customerCompany().is("Braintree").
    customerEmail().is("smith@example.com").
    customerFax().is("5551231234").
    customerFirstName().is("Tom").
    customerLastName().is("Smith").
    customerPhone().is("5551231234").
    customerWebsite().is("http://example.com");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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

TransactionSearchRequest request = new TransactionSearchRequest().
    customerEmail().endsWith("example.com");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Billing Address

TransactionSearchRequest request = new TransactionSearchRequest().
    billingFirstName().is("Paul").
    billingLastName().is("Smith").
    billingCompany().is("Braintree").
    billingStreetAddress().is("123 Main St").
    billingExtendedAddress().is("Suite 123").
    billingLocality().is("Chicago").
    billingRegion().is("Illinois").
    billingPostalCode().is("12345").
    billingCountryName().is("United States of America");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Shipping Address

TransactionSearchRequest request = new TransactionSearchRequest().
    shippingFirstName().is("Paul").
    shippingLastName().is("Smith").
    shippingCompany().is("Braintree").
    shippingStreetAddress().is("123 Main St").
    shippingExtendedAddress().is("Suite 123").
    shippingLocality().is("Chicago").
    shippingRegion().is("Illinois").
    shippingPostalCode().is("12345").
    shippingCountryName().is("United States of America");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Other Top-level Attributes

TransactionSearchRequest request = new TransactionSearchRequest().
    orderId().is("myorder").
    processorAuthorizationCode().is("123456");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Vault Associations

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

TransactionSearchRequest request = new TransactionSearchRequest().
    paymentMethodToken().is("the_token");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Or a customer ID.

TransactionSearchRequest request = new TransactionSearchRequest().
    customerId().is("the_customer_id");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

How the transaction was created

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

TransactionSearchRequest request = new TransactionSearchRequest().
    createdUsing().is(Transaction.CreatedUsing.TOKEN);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Or transactions that were created using full credit card information.

TransactionSearchRequest request = new TransactionSearchRequest().
    createdUsing().is(Transaction.CreatedUsing.FULL_INFORMATION);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Those are the only two choices for created_using.

Customer Location

Customers in the US.

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardCustomerLocation().is(CreditCard.CustomerLocation.US);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Or international customers.

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardCustomerLocation().is(CreditCard.CustomerLocation.INTERNATIONAL);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Merchant Account

A specific one.

TransactionSearchRequest request = new TransactionSearchRequest().
var request = new TransactionSearchRequest().
    CreditCardCustomerLocation.Is(CreditCardCustomerLocation.INTERNATIONAL);

ResourceCollection<Transaction> collection = gateway.Transaction.Search(request);
    merchantAccountId().is("the_merchant_account_id");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Or any of several.

TransactionSearchRequest request = new TransactionSearchRequest().
    merchantAccountId().in("account_1", "account_2");

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Credit Card Type

A specific one.

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardCardType().is(CreditCard.CardType.VISA);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Or any of several.

TransactionSearchRequest request = new TransactionSearchRequest().
    creditCardCardType().in(
        CreditCard.CardType.VISA, CreditCard.CardType.MASTER_CARD
    );

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Transaction Status

Another one or many search field.

TransactionSearchRequest request = new TransactionSearchRequest().
    status().is(Transaction.Status.AUTHORIZED);

TransactionSearchRequest request = new TransactionSearchRequest().
      status().in(
          Transaction.Status.AUTHORIZED, Transaction.Status.SUBMITTED_FOR_SETTLEMENT
      );

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Transaction Source

API, Control Panel, or Recurring Billing.

TransactionSearchRequest request = new TransactionSearchRequest().
    source().is(Transaction.Source.API);

TransactionSearchRequest request = new TransactionSearchRequest().
      source().in(
          Transaction.Source.API, Transaction.Source.CONTROL_PANEL
      );

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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.

TransactionSearchRequest request = new TransactionSearchRequest().
    type().is(Transaction.Type.SALE);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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

TransactionSearchRequest request = new TransactionSearchRequest().
    type().is(Transaction.Type.CREDIT);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

If you only want the refunds:

TransactionSearchRequest request = new TransactionSearchRequest().
    type().is(Transaction.Type.CREDIT).
    refund().is(true);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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

TransactionSearchRequest request = new TransactionSearchRequest().
    type().is(Transaction.Type.CREDIT).
    refund().is(false);

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

Amount

It’s a range field.

TransactionSearchRequest request = new TransactionSearchRequest().
    amount().between(new BigDecimal("100.00"), new BigDecimal("200.00"));

TransactionSearchRequest request = new TransactionSearchRequest().
    amount().greaterThanOrEqualTo(new BigDecimal("100.00"));

TransactionSearchRequest request = new TransactionSearchRequest().
    amount().lessThanOrEqualTo(new BigDecimal("200.00"));

ResourceCollection<Transaction> collection = gateway.transaction().search(request);

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:

TransactionSearchRequest searchRequest = new TransactionSearchRequest().
    createdAt().lessThanOrEqual(Calendar.getInstance());

ResourceCollection<Transaction> collection = gateway.transaction().search(searchRequest);
TransactionSearchRequest searchRequest = new TransactionSearchRequest().
    settledAt().lessThanOrEqual(Calendar.getInstance());

ResourceCollection<Transaction> collection = gateway.transaction().search(searchRequest);
TransactionSearchRequest searchRequest = new TransactionSearchRequest().
    processorDeclinedAt().lessThanOrEqual(Calendar.getInstance());

ResourceCollection<Transaction> collection = gateway.transaction().search(searchRequest);

Note: Timezones specified in the time value will be respected in the search.

Results will always be returned with time values in UTC.

See Also