Returns a collection of Customer response objects.

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

Ruby
Copy
Copied
collection = gateway.customer.search do |search|
  search.id.is "the_customer_id"
end

collection.each do |customer|
  puts customer.first_name
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.
Parameters
:address_country_name text

The country on an address associated with the customer.

:address_extended_address text

The extended address on an address associated with the customer.

:address_first_name text

The first name on an address associated with the customer.

:address_last_name text

The last name on an address associated with the customer.

:address_locality text

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

:address_postal_code text

The postal code on an address associated with the customer.

:address_region text

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

:address_street_address text

The street address on an address associated with the customer.

:cardholder_name text

The name on a credit card associated with the customer.

:company text

The customer's company.

:created_at range

The date/time the customer was created.

:credit_card_expiration_date text

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

:credit_card_number 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.

:first_name 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.

:last_name text

The customer's last name.

:payment_method_token text

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

:payment_method_token_with_duplicates 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.

:paypal_account_email 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

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.company.is "Acme Inc."
  search.email.is "john.doe@example.com"
  search.fax.is "555-123-1234"
  search.first_name.is "John"
  search.id.is "the_customer_id"
  search.last_name.is "Doe"
  search.phone.is "555-321-4321"
  search.website.is "http://www.example.com"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Address fields

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.address_first_name.is "John"
  search.address_last_name.is "Doe"
  search.address_street_address.is "111 First St."
  search.address_extended_address.is "Suite #3"
  search.address_locality.is "Chicago"
  search.address_region.is "IL"
  search.address_postal_code.is "12345"
  search.address_country_name.is "USA"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Credit card fields

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.cardholder_name.is "John Doe"
  search.payment_method_token.is "the_payment_method_token"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.credit_card_number.starts_with "510510"
end

search_results = gateway.customer.search do |search|
  search.credit_card_number.ends_with "5100"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

Expiration date

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

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.credit_card_expiration_date.is "12/13"
end

search_results = gateway.customer.search do |search|
  search.credit_card_expiration_date.is_not "12/13"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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:

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.created_at >= Time.now - 60*60*24 # a day ago
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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:

Ruby
Copy
Copied
search_results = gateway.customer.search do |search|
  search.payment_method_token_with_duplicates.is "payment_method_token"
end
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

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.

Ruby
Copy
Copied
customers = gateway.customer.all
This code snippet now uses gateway instance methods instead of class-level methods. Learn more.

See also

Still have questions?

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