Search code examples
javascriptnode.jsstripe-paymentscredit-card

Stripe.Customers.listSources not returning anything


I've created the following code to get all the cards for my customer:

return stripe.customers.listSources(customerId, {
    object: "card",
    limit: 10
}).then(cards => {
    if (cards) {
        res.status(200).send({
            cards: cards.data
        });
        return;
    }
    res
        .status(500)
        .send({ error: "error getting cards" });

})
    .catch(error => {
        console.log(error);
        res.status(500).send({ error: "error getting cards" });
    });

following this documentation:

https://stripe.com/docs/api/cards/list

I've also added test cards to my customer which are visible in the dashboard:

enter image description here

but the API always returns me the following result:

{
  object: 'list',
  data: [],
  has_more: false,
  url: '/v1/customers/<my_cus_id>/sources'
}

Solution

  • It seems like using this instead works:

    stripe.paymentMethods.list(
       { customer: customerId, type: "card" }
    )
    

    https://stripe.com/docs/api/payment_methods/list