Searching for Credit Cards

Single Credit Card

If you want to look up a single credit card using its token, use the find method.

credit_card = Braintree::CreditCard.find("the_token")

To determine if credit_card is a Customer’s default Credit Card:

credit_card.default?

If the credit card cannot be found, it will raise a Braintree::NotFoundError exception.

Transactions

You can find transactions associated to a specific credit card token using the transaction search API.

search_results = Braintree::Transaction.search do |search|
  search.credit_card_token.is "the_token"
end

Expired Cards

You can find all credit cards stored in the vault that are expired.

collection = Braintree::CreditCard.expired

You can also search for credit cards that expire between a date range.

collection = Braintree::CreditCard.expiring_between(
  Time.mktime(2010, 1, 1),
  Time.mktime(2010, 3, 1)
)