Customer
Customer: Search
Returns a collection of Customer response objects.
For operators available on search fields, see the search fields page.
- PHP
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::id()->is("the_customer_id")
]);
foreach($collection as $customer) {
echo $customer->firstName;
}
Parameters
'addressRegion'
text'cardholderName'
text'company'
text'createdAt'
rangeThe 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'fax'
text'firstName'
text'id'
text'ids'
multiple'lastName'
textSame 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.
'phone'
text'website'
textExamples
Customer fields
- PHP
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::company()->is("Acme Inc."),
BraintreeCustomerSearch::email()->is("john.doe@example.com"),
BraintreeCustomerSearch::fax()->is("555-123-1234"),
BraintreeCustomerSearch::firstName()->is("John"),
BraintreeCustomerSearch::id()->is("the_customer_id"),
BraintreeCustomerSearch::lastName()->is("Doe"),
BraintreeCustomerSearch::phone()->is("555-321-4321"),
BraintreeCustomerSearch::website()->is("http://www.example.com")
]);
Address fields
- PHP
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::addressFirstName()->is("John"),
BraintreeCustomerSearch::addressLastName()->is("Doe"),
BraintreeCustomerSearch::addressStreetAddress()->is("111 First St.")
BraintreeCustomerSearch::addressExtendedAddress()->is("Suite #3"),
BraintreeCustomerSearch::addressLocality()->is("Chicago"),
BraintreeCustomerSearch::addressRegion()->is("IL"),
BraintreeCustomerSearch::addressPostalCode()->is("12345"),
BraintreeCustomerSearch::addressCountryName()->is("USA")
]);
Credit card fields
- PHP
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::cardholderName()->is("John Doe"),
BraintreeCustomerSearch::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
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::creditCardNumber()->startsWith("411111")
]);
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::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
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::creditCardExpirationDate()->is("12/13")
]);
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::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
$now = new Datetime();
$past = clone $now;
$past = $past->modify("-1 hour");
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::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
$collection = $gateway->customer()->search([
BraintreeCustomerSearch::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
$customers = $gateway->customer()->all();