Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe API returns no source although there are some according to dashboard

My stripe account is in test mode.

I request all sources (with cards) for a given customer using:

curl "https://api.stripe.com/v1/customers/cus_FWzlniSobJD2yO/sources" \
    -u sk_test_SECRET_KEY: \
    -G

I get the following response:

{
  "object": "list",
  "data": [

  ],
  "has_more": false,
  "url": "/v1/customers/cus_FWzlniSobJD2yO/sources"
}

You can see that 'data', that should contain the customer's payment sources, is empty.

The cards have been saved from the front with stripe.js using:

stripe.handleCardPayment(intentClientSecret, cardElement, {
    payment_method_data: {
        billing_details: {name: 'Firstname Lastname'}
    },
    save_payment_method: true
});

Cards appearing in customer's details in my dashboard: Cards appearing in customer details

like image 397
S. Pellegrino Avatar asked Jul 31 '19 23:07

S. Pellegrino


1 Answers

Although the cards are listed in the dashboard and the documentation says the request in OP should allow you to retrieve all cards, cards attached to a customer through "save_payment_methods" are not part of his "sources" but of his "payment_methods". Both are different APIs serving the same purpose, the latest being the newest and recommended way of doing things.

They are accessible through:

curl "https://api.stripe.com/v1/payment_methods?customer=cus_FWzlniSobJD2yO&type=card" \
  -u sk_test_SECRET_KEY: \
  -G
like image 93
S. Pellegrino Avatar answered Jan 04 '23 00:01

S. Pellegrino