Stripe.Customers.listSources not returning anything
Asked Answered
L

1

5

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'
}
Longe answered 20/5, 2020 at 15:35 Comment(0)
L
9

It seems like using this instead works:

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

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

Longe answered 20/5, 2020 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.