6

There is a way to get a list of all cards:

gateway.creditCard.expiringBetween(year1900, year2100, function (err, result) {...})

and then call paymentMethod.find for each individual card. But I would like to get all payment methods associated with a customer, in one call, is this possible?

punund
  • 4,321
  • 3
  • 34
  • 45
  • I work at Braintree. Generally, you shouldn't need to get all payment methods in the Braintree vault (is that what you're trying to do?). What's your use case? – agf Nov 03 '14 at 17:10
  • No, I was trying to get all the payment methods for specific customer. – punund Nov 03 '14 at 20:08

2 Answers2

9

I work at Braintree. If you have more questions, you can always get in touch with our support team.

A customer is serialized with all of its payment methods.

So, get the customer and then get the credit cards and paypal accounts from it:

gateway.customer.find("theCustomerId", function(err, customer) {
    var payment_methods = customer.creditCards.concat(customer.paypalAccounts);
});
agf
  • 171,228
  • 44
  • 289
  • 238
  • 2
    @RobFox Please don't make edits that don't substantially improve an answer. I understand you just got edit privileges and are excited to use them, but the same rules apply as before you got them -- only make significant edits. – agf Aug 12 '16 at 16:55
  • hey can you do this in a React frontend app? Or is this just for the backend? – rom Feb 25 '23 at 19:08
  • 1
    @rom I no longer work at Braintree but AFAIK you need to do this from the backend; if you want to avoid having to do that you might be able to use the drop-in UI and not need to fetch payment methods yourself. https://developer.paypal.com/braintree/docs/start/drop-in – agf Feb 27 '23 at 15:13
2

I figured that. gateway.customer.find returns an object with property creditCards, just wasn't obvious from the documentation.

punund
  • 4,321
  • 3
  • 34
  • 45