Customer
Customer: Search
Returns a collection of Customer response objects.
For operators available on search fields, see the search fields page.
- Python
collection = gateway.customer.search(
braintree.CustomerSearch.id == "the_customer_id"
)
for customer in collection.items:
print customer.first_name
Parameters
'address_region'
text'company'
text'created_at'
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'first_name'
text'id'
text'ids'
multiple'last_name'
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
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.company == "Acme Inc.",
braintree.CustomerSearch.email == "john.doe@example.com",
braintree.CustomerSearch.fax == "555-123-1234",
braintree.CustomerSearch.first_name == "John",
braintree.CustomerSearch.id == "the_customer_id",
braintree.CustomerSearch.last_name == "Doe",
braintree.CustomerSearch.phone == "555-321-4321",
braintree.CustomerSearch.website == "http://www.example.com"
)
Address fields
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.address_first_name == "John",
braintree.CustomerSearch.address_last_name == "Doe",
braintree.CustomerSearch.address_street_address == "111 First St."
braintree.CustomerSearch.address_extended_address == "Suite #3",
braintree.CustomerSearch.address_locality == "Chicago",
braintree.CustomerSearch.address_region == "IL",
braintree.CustomerSearch.address_postal_code == "12345",
braintree.CustomerSearch.address_country_name == "USA"
)
Credit card fields
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.cardholder_name == "John Doe",
braintree.CustomerSearch.payment_method_token == "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."
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.credit_card_number.starts_with("510510")
)
search_results = gateway.customer.search(
braintree.CustomerSearch.credit_card_number.ends_with("5100")
)
Expiration date
Expiration date also has restrictions. "is" and "is not" work, while "starts with," "ends with," and "contains" do not.
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.credit_card_expiration_date == "12/13"
)
search_results = gateway.customer.search(
braintree.CustomerSearch.credit_card_expiration_date != "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:
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.created_at.between(
datetime.datetime(2009, 1, 1),
datetime.datetime(2011, 1, 1)
)
)
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:
- Python
search_results = gateway.customer.search(
braintree.CustomerSearch.payment_method_token_with_duplicates.is("payment_method_token_with_duplicates")
)
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.
- Python
collection = gateway.customer.all()