Customer: Search
Returns a collection of Customer response objects.
For operators available on search fields, see the search fields page.
- Node
const stream = gateway.customer.search((search) => {
  search.id().is("the_customer_id");
}, (err, response) => {
  response.each((err, customer) => {
    console.log(customer.firstName);
  });
});Parameters
addressFirstNametextaddressLastNametextaddressLocalitytextaddressRegiontextcardholderNametextcompanytextcreatedAtrangecreditCardNumbertextThe 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.
emailtextfaxtextfirstNametextidtextidsmultiplelastNametextSame 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.
phonetextwebsitetextExamples
Customer fields
- Node
const stream = gateway.customer.search((search) => {
  search.company().is("Acme Inc.");
  search.email().is("[email protected]");
  search.fax().is("555-123-1234");
  search.firstName().is("John");
  search.id().is("theCustomerId");
  search.lastName().is("Doe");
  search.phone().is("555-321-4321");
  search.website().is("http://www.example.com");
});Address fields
- Node
const stream = gateway.customer.search((search) => {
  search.addressFirstName().is("John");
  search.addressLastName().is("Doe");
  search.addressStreetAddress().is("111 First St.");
  search.addressExtendedAddress().is("Suite #3");
  search.addressLocality().is("Chicago");
  search.addressRegion().is("IL");
  search.addressPostalCode().is("12345");
  search.addressCountryName().is("USA");
});Credit card fields
- Node
const stream = gateway.customer.search((search) => {
  search.cardholderName().is("John Doe");
  search.paymentMethodToken().is("thePaymentMethodToken");
});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."
- Node
const stream = gateway.customer.search((search) => {
  search.creditCardNumber().startsWith("510510");
});- Node
const stream = gateway.customer.search((search) => {
  search.creditCardNumber().endsWith("5100");
});Expiration date
Expiration date also has restrictions. "is" and "is not" work, while "starts with," "ends with," and "contains" do not.
- Node
const stream = gateway.customer.search((search) => {
  search.creditCardExpirationDate().is("12/13");
});- Node
const stream = gateway.customer.search((search) => {
  search.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:
- Node
const today = new Date();
const yesterday = new Date();
yesterday.setDate(today.getDate() - 1);
const stream = gateway.customer.search((search) => {
  search.createdAt().min(yesterday);
});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:
- Node
const stream = gateway.customer.search((search) => {
  search.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.
- Node
// this call is not implemented in node