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_token');
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
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardCardholderName()->is("Tom Smith"),
Braintree_TransactionSearch::creditCardExpirationDate()->is("05/2012"),
Braintree_TransactionSearch::creditCardNumber()->is(Braintree_Test_CreditCardNumbers::$visa)
));
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.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardNumber()->startsWith("411111")
));
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardNumber()->endsWith("1111")
));
Customer
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::customerCompany()->is("Braintree"),
Braintree_TransactionSearch::customerEmail()->is("smith@example.com"),
Braintree_TransactionSearch::customerFax()->is("5551231234"),
Braintree_TransactionSearch::customerFirstName()->is("Tom"),
Braintree_TransactionSearch::customerLastName()->is("Smith"),
Braintree_TransactionSearch::customerPhone()->is("5551231234"),
Braintree_TransactionSearch::customerWebsite()->is("http://example.com"),
));
See search fields for a list of available operators. They allow you to do nice things like this:
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardCardholderName()->endsWith('m smith')
));
Billing Address
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::billingCompany()->is("Braintree"),
Braintree_TransactionSearch::billingCountryName()->is("United States of America"),
Braintree_TransactionSearch::billingExtendedAddress()->is("Suite 123"),
Braintree_TransactionSearch::billingFirstName()->is($firstName),
Braintree_TransactionSearch::billingLastName()->is("Smith"),
Braintree_TransactionSearch::billingLocality()->is("Chicago"),
Braintree_TransactionSearch::billingPostalCode()->is("12345"),
Braintree_TransactionSearch::billingRegion()->is("IL"),
Braintree_TransactionSearch::billingStreetAddress()->is("123 Main St"),
));
Shipping Address
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::shippingCompany()->is("Braintree P.S."),
Braintree_TransactionSearch::shippingCountryName()->is("Mexico"),
Braintree_TransactionSearch::shippingExtendedAddress()->is("Apt 456"),
Braintree_TransactionSearch::shippingFirstName()->is("Thomas"),
Braintree_TransactionSearch::shippingLastName()->is("Smithy"),
Braintree_TransactionSearch::shippingLocality()->is("Braintree"),
Braintree_TransactionSearch::shippingPostalCode()->is("54321"),
Braintree_TransactionSearch::shippingRegion()->is("MA"),
Braintree_TransactionSearch::shippingStreetAddress()->is("456 Road"),
));
Other Top-level Attributes
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::orderId()->is("myorder"),
Braintree_TransactionSearch::processorAuthorizationCode()->is($transaction->processorAuthorizationCode),
));
Vault Associations
You can search for transactions associated to a payment method token.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::paymentMethodToken()->is('the_token'),
));
Or a customer ID.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::customerId()->is('the_customer_id'),
));
How the transaction was created
You can search for transactions that were created using a token.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::createdUsing()->is(Braintree_Transaction::TOKEN)
));
Or transactions that were created using full credit card information.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::createdUsing()->is(Braintree_Transaction::FULL_INFORMATION)
));
Those are the only two choices for created_using.
Customer Location
Customers in the US.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardCustomerLocation()->is(Braintree_CreditCard::US)
));
Or international customers.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardCustomerLocation()->is(Braintree_CreditCard::INTERNATIONAL)
));
Merchant Account
A specific one.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::merchantAccountId()->is('my_merchant_account')
));
Or any of several.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::merchantAccountId()->in(
array('account_1', 'account_2')
)
));
Credit Card Type
A specific one.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::creditCardCardType()->is(Braintree_CreditCard::VISA)
));
Or any of several.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::id()->is($transaction->id),
Braintree_TransactionSearch::creditCardCardType()->in(
array(
Braintree_CreditCard::VISA,
Braintree_CreditCard::MASTER_CARD
)
)
));
Transaction Status
Another one or many search field.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::id()->is($transaction->id),
Braintree_TransactionSearch::status()->in(
array(
Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT,
Braintree_Transaction::SETTLED
)
)
));
Transaction Source
API, Control Panel, or Recurring Billing.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::id()->is($transaction->id),
Braintree_TransactionSearch::source()->in(
array(
Braintree_Transaction::API,
Braintree_Transaction::RECURRING,
Braintree_Transaction::CONTROL_PANEL
)
)
));
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.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::type()->is(Braintree_Transaction::SALE)
));
This will return all credits, regardless of whether they’re refunds, or standalone credits.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::type()->is(Braintree_Transaction::CREDIT)
));
If you only want the refunds:
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::type()->is(Braintree_Transaction::CREDIT),
Braintree_TransactionSearch::refund()->is(True)
));
And if you only want the credits that aren’t refunds:
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::type()->is(Braintree_Transaction::CREDIT),
Braintree_TransactionSearch::refund()->is(False)
));
Amount
It’s a range field.
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::amount()->between('100.00', '200.00')
));
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::amount()->greaterThanOrEqualTo('100.00')
));
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::amount()->lessThanOrEqualTo('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:
createdAtauthorizedAtsubmittedForSettlementAtsettledAtvoidedAtprocessorDeclinedAtgatewayRejectedAtfailedAt
A few examples:
$now = new Datetime();
$past = clone $now;
$past = $past->modify("-1 hour");
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::createdAt()->between($past, $now)
));
$now = new Datetime();
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::settledAt()->lessThanOrEqualTo($now)
));
$past = new Datetime();
$past = $past->modify("-1 hour");
$collection = Braintree_Transaction::search(array(
Braintree_TransactionSearch::processorDeclinedAt()->greaterThanOrEqualTo($past)
));
Note: Timezones specified in the time value will be respected in the search.
Results will always be returned with time values in UTC.