Returns a collection of Braintree_Customer response objects.

For operators available on search fields, see the search fields page.

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::id()->is("the_customer_id")
]);

foreach($collection as $customer) {
    echo $customer->firstName;
}
Parameters
'addressCountryName' text

The country on an address associated with the customer.

'addressExtendedAddress' text

The extended address on an address associated with the customer.

'addressFirstName' text

The first name on an address associated with the customer.

'addressLastName' text

The last name on an address associated with the customer.

'addressLocality' text

The locality (e.g. city) on an address associated with the customer.

'addressPostalCode' text

The postal code on an address associated with the customer.

'addressRegion' text

The region (e.g. state) on an address associated with the customer.

'addressStreetAddress' text

The street address on an address associated with the customer.

'cardholderName' text

The name on a credit card associated with the customer.

'company' text

The customer's company.

'createdAt' range

The date/time the customer was created.

'creditCardExpirationDate' text

The expiration date of a credit card associated with the customer.

'creditCardNumber' text

The number of a credit card associated with the customer.

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.

'email' text

The customer's email.

'fax' text

The customer's fax number.

'firstName' text

The customer's first name.

'id' text

A string value representing an existing customer in your Vault.

'ids' multiple

A list of customer IDs to search for.

'lastName' text

The customer's last name.

'paymentMethodToken' text

The payment method token of a payment method associated with the customer.

'paymentMethodTokenWithDuplicates' text

Same as payment method token, except this will return all customers that have a credit card with the same number as the payment method being searched.

'paypalAccountEmail' text

The email of a PayPal account associated with the customer.

'phone' text

The customer's phone number.

'website' text

The customer's website.

Examples

Customer fields

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::company()->is("Acme Inc."),
    Braintree_CustomerSearch::email()->is("john.doe@example.com"),
    Braintree_CustomerSearch::fax()->is("555-123-1234"),
    Braintree_CustomerSearch::firstName()->is("John"),
    Braintree_CustomerSearch::id()->is("the_customer_id"),
    Braintree_CustomerSearch::lastName()->is("Doe"),
    Braintree_CustomerSearch::phone()->is("555-321-4321"),
    Braintree_CustomerSearch::website()->is("http://www.example.com")
]);

Address fields

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::addressFirstName()->is("John"),
    Braintree_CustomerSearch::addressLastName()->is("Doe"),
    Braintree_CustomerSearch::addressStreetAddress()->is("111 First St.")
    Braintree_CustomerSearch::addressExtendedAddress()->is("Suite #3"),
    Braintree_CustomerSearch::addressLocality()->is("Chicago"),
    Braintree_CustomerSearch::addressRegion()->is("IL"),
    Braintree_CustomerSearch::addressPostalCode()->is("12345"),
    Braintree_CustomerSearch::addressCountryName()->is("USA")
]);

Credit card fields

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::cardholderName()->is("John Doe"),
    Braintree_CustomerSearch::paymentMethodToken()->is("the_payment_method_token")
]);

Credit card number

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."

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::creditCardNumber()->startsWith("411111")
]);

$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::creditCardNumber()->endsWith("1111")
]);

Expiration date

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

PHP
Copy
Copied
$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::creditCardExpirationDate()->is("12/13")
]);

$collection = Braintree_Customer::search([
    Braintree_CustomerSearch::creditCardExpirationDate()->isNot("12/13")
]);

Created at

You can search for customers that were created at a certain time. For instance, you can find all customers which were created in the past 3 days.

An example:

PHP
Copy
Copied
$now = new Datetime();
$past = clone $now;
$past = $past->modify("-1 hour");

$collection = Braintree_Customer::search([
  Braintree_CustomerSearch::createdAt()->between($past, $now)
]);

Payment method token with duplicates

You can search for customers that have duplicated credit card numbers using payment method token as a reference.

An example:

PHP
Copy
Copied
$collection = Braintree_Customer::search([
  Braintree_CustomerSearch::paymentMethodTokenWithDuplicates()->is("paymentMethodToken")
]);

All customers

You can get a list of all customers stored in the Vault. This will return a resource collection of customer objects. Search results are currently capped so this may not work for everybody.

PHP
Copy
Copied
$customers = Braintree_Customer::all();

See also

Still have questions?

If you can’t find an answer, contact our Support team.