Transaction
Transaction: Search
Returns a collection of Transaction response objects.
For operators available on search fields, see the search fields page.
- PHP
$collection = $gateway->transaction()->search([
Braintree\TransactionSearch::customerId()->is('the_customer_id'),
]);
foreach($collection as $transaction) {
echo $transaction->amount;
}
Parameters
'amount'
rangexx
or x.xx
.'authorizedAt'
range'billingCompany'
text'billingRegion'
text'createdAt'
range'createdUsing'
multipleThe data used to create the transaction. Possible values:
Braintree\Transaction::TOKEN
Braintree\Transaction::FULL_INFORMATION
'creditCardCardType'
multipleThe type of credit card used in the transaction. Possible values:
"American Express"
"Discover"
"Maestro"
"JCB"
"MasterCard"
"UnionPay"
"Visa"
'creditCardCustomerLocation'
multipleThe location of the customer in the transaction. Possible values:
international
us
The number of the card used in the transaction.
Card number search is restricted: starts with searches up to the first 6 digits, ends with searches last 4 digits, and contains is not allowed.
The unique identifier of the card number. See the transaction response reference for more details.
'currency'
text'customerEmail'
text'customerFax'
text'customerId'
text'customerPhone'
text'debitNetwork'
multiple'disbursementDate'
rangeOnly available for certain account types; contact us for details.
The date the transaction was disbursed to your bank account. This field does not include a time value.
'disputeDate'
rangeOnly available for certain account types; contact us for details.
The date the transaction was disputed. This field does not include a time value.
'failedAt'
range'gatewayRejectedAt'
range'id'
text'ids'
multiple'merchantAccountId'
multipleThe merchant account IDs associated with transactions.
A fragment of the merchant account ID to search for.
'contains'
text'endsWith'
text'is'
text'isNot'
text'startsWith'
text'orderId'
text'paymentInstrumentType'
multiple'refund'
multipleWhether or not the transaction is a refund. The value may be either true or false. This parameter must be used in conjunction with type
.
'settledAt'
range'shippingRegion'
text'source'
multipleHow a transaction was created. Possible values:
API
CONTROL_PANEL
RECURRING
- OAuth application client ID of the transaction facilitator
'status'
multipleThe list of statuses to search for. Possible statuses:
AUTHORIZING
AUTHORIZED
AUTHORIZATION_EXPIRED
SUBMITTED_FOR_SETTLEMENT
SETTLING
SETTLEMENT_PENDING
SETTLEMENT_DECLINED
SETTLED
VOIDED
PROCESSOR_DECLINED
GATEWAY_REJECTED
FAILED
'type'
multiplePossible values:
SALE
CREDIT
'user'
multiple'voidedAt'
rangeExamples
Credit card
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::creditCardCardholderName()->is("Tom Smith"),
BraintreeTransactionSearch::creditCardExpirationDate()->is("05/2012"),
BraintreeTransactionSearch::creditCardNumber()->endsWith("1111"),
]);
Searching On Customer Details
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::customerCompany()->is("Braintree"),
BraintreeTransactionSearch::customerEmail()->is("smith@example.com"),
BraintreeTransactionSearch::customerFax()->is("5551231234"),
BraintreeTransactionSearch::customerFirstName()->is("Tom"),
BraintreeTransactionSearch::customerLastName()->is("Smith"),
BraintreeTransactionSearch::customerPhone()->is("5551231234"),
BraintreeTransactionSearch::customerWebsite()->is("http://example.com"),
]);
See search fields for a list of available operators. They allow you to do nice things like this:
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::creditCardCardholderName()->endsWith('m smith')
]);
Billing address
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::billingCompany()->is("Braintree"),
BraintreeTransactionSearch::billingCountryName()->is("United States of America"),
BraintreeTransactionSearch::billingExtendedAddress()->is("Suite 123"),
BraintreeTransactionSearch::billingFirstName()->is($firstName),
BraintreeTransactionSearch::billingLastName()->is("Smith"),
BraintreeTransactionSearch::billingLocality()->is("Chicago"),
BraintreeTransactionSearch::billingPostalCode()->is("12345"),
BraintreeTransactionSearch::billingRegion()->is("IL"),
BraintreeTransactionSearch::billingStreetAddress()->is("123 Main St"),
]);
Shipping address
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::shippingCompany()->is("Braintree P.S."),
BraintreeTransactionSearch::shippingCountryName()->is("Mexico"),
BraintreeTransactionSearch::shippingExtendedAddress()->is("Apt 456"),
BraintreeTransactionSearch::shippingFirstName()->is("Thomas"),
BraintreeTransactionSearch::shippingLastName()->is("Smithy"),
BraintreeTransactionSearch::shippingLocality()->is("Braintree"),
BraintreeTransactionSearch::shippingPostalCode()->is("54321"),
BraintreeTransactionSearch::shippingRegion()->is("MA"),
BraintreeTransactionSearch::shippingStreetAddress()->is("456 Road"),
]);
Other top-level attributes
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::orderId()->is("myorder"),
BraintreeTransactionSearch::processorAuthorizationCode()->is($transaction->processorAuthorizationCode),
]);
Vault associations
You can search for transactions associated to a payment method token.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::paymentMethodToken()->is('the_token'),
]);
How the transaction was created
You can search for transactions that were created using a token.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::createdUsing()->is(BraintreeTransaction::TOKEN)
]);
Or transactions that were created using full credit card information.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::createdUsing()->is(BraintreeTransaction::FULL_INFORMATION)
]);
Those are the only two choices for created_using.
Customer location
Customers in the US.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::creditCardCustomerLocation()->is(BraintreeCreditCard::US)
]);
Or international customers.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::creditCardCustomerLocation()->is(BraintreeCreditCard::INTERNATIONAL)
]);
Merchant account
A specific one.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::merchantAccountId()->is('my_merchant_account')
]);
Or any of several.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::merchantAccountId()->in(
['account_1', 'account_2']
)
]);
Credit card type
A specific one.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::creditCardCardType()->is(BraintreeCreditCard::VISA)
]);
Or any of several.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::id()->is($transaction->id),
BraintreeTransactionSearch::creditCardCardType()->in(
[
BraintreeCreditCard::VISA,
BraintreeCreditCard::MASTER_CARD,
BraintreeCreditCard::DISCOVER
]
)
]);
Transaction status
Another one or many search field.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::id()->is($transaction->id),
BraintreeTransactionSearch::status()->in(
[
BraintreeTransaction::SUBMITTED_FOR_SETTLEMENT,
BraintreeTransaction::SETTLED
]
)
]);
Transaction source
API, Control Panel, or Recurring Billing.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::id()->is($transaction->id),
BraintreeTransactionSearch::source()->in(
[
BraintreeTransaction::API,
BraintreeTransaction::RECURRING,
BraintreeTransaction::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.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::type()->is(BraintreeTransaction::SALE)
]);
This will return all credits, regardless of whether they're refunds, or standalone credits.
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::type()->is(BraintreeTransaction::CREDIT)
]);
If you only want the refunds:
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::type()->is(BraintreeTransaction::CREDIT),
BraintreeTransactionSearch::refund()->is(True)
]);
And if you only want the credits that aren't refunds:
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::type()->is(BraintreeTransaction::CREDIT),
BraintreeTransactionSearch::refund()->is(False)
]);
Amount
It's a range field .
- PHP
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::amount()->between('100.00', '200.00')
]);
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::amount()->greaterThanOrEqualTo('100.00')
]);
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::amount()->lessThanOrEqualTo('100.00')
]);
Status changes
You can search for transactions that entered a given status at a certain date and time. For instance, you can find all transactions which were submitted for settlement in the past 3 days.
You can search on these statuses:
- createdAt
- authorizedAt
- submittedForSettlementAt
- settledAt
- voidedAt
- processorDeclinedAt
- gatewayRejectedAt
- failedAt
- authorizationExpiredAt
A few examples:
- PHP
$now = new Datetime();
$past = clone $now;
$past = $past->modify("-1 hour");
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::createdAt()->between($past, $now)
]);
- PHP
$now = new Datetime();
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::settledAt()->lessThanOrEqualTo($now)
]);
- PHP
$past = new Datetime();
$past = $past->modify("-1 hour");
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::processorDeclinedAt()->greaterThanOrEqualTo($past)
]);
Dispute date range
- PHP
$now = new Datetime();
$collection = $gateway->transaction()->search([
BraintreeTransactionSearch::disputeDate()->lessThanOrEqualTo($now)
]);