Search code examples
node.jsbraintreebraintree-sandbox

Braintree Node.js - get expired credit cards


I need to get a list of expiring credit cards.

Looking thru the docs, I found this: https://developers.braintreepayments.com/reference/request/credit-card/expiring-between/node

Docs say: Returns a collection of CreditCard objects that expire between the specified dates.

So I created a sample code for this.

gateway.creditCard.expiringBetween(before, after, (err, result) => {
    if (err) {
      console.log('I have an error', { err });
    }
    console.log('results', { result });
  });

The result I'm getting is the following:

results { result:
   SearchResponse {
     pagingFunction:
      CreditCardGateway { gateway: [BraintreeGateway], config: [Config] },
     ids: [ 'jx7sds', 'grp387' ],
     pageSize: 50,
     stream:
      SearchResponseStream {
        _readableState: [ReadableState],
        readable: true,
        domain: [Domain],
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        searchResponse: [Circular],
        currentItem: 0,
        currentOffset: 0,
        bufferedResults: [] },
     success: true } }

I see I'm getting an array of Credit Card Ids.

If I iterate over those Ids and do a gateway.creditCard.find I can find information for those Credit Cards.

However, I'm confused by the docs stating that I should be getting the Credit Card objects in the initial response.

It looks like an overkill to go and find each CC individually when I should have gotten them in the first place. I must be doing something wrong.

Since I've seen some BT devs here at SO I thought I might ask the community.

Has someone done this before and could share some code snippet or point me in the right direction? Thanks in advance!


Solution

  • I just asked Braintree support if the doc is correct and got the following anwer:

    You are correct that the result returns an array of the payment method tokens (IDs). Thanks for the call out. We will discuss this further with our documentation team.

    They also said that iterating over the ids is the way to go.