Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Default Payment Source (default card) for Stripe Customer?

I created a POC with a customer/credit card in Stripe and I logged into my dashboard within Stripe and was able to see this customer has a default source (the test credit card I added) associated correctly. It shows this card is the default source.

When I run this .Net code:

 var customerService = new CustomerService();
 var stripeCustomer = await customerService.GetAsync(customerId);

To get that customer, it returns everything correctly except his source. All of the fields I had hoped I can find it from are empty! I want to know his default payment source so I can show it on the front end with a little icon to indicate it's default.

DefaultSource, DefaultSourceId, and Sources properties are all blank/null.

Is there a way to have Stripe return it, or do I need to do something else? I tried the 'expand' property for the GetAsync method but that threw an error saying the above properties are not expandable (i.e. I can't ask Stripe to expand/return Source).

Any ideas what I can do?

FYI I also tried this:

  var paymentMethodService = new PaymentMethodService();
  var cards = await paymentMethodService.ListAsync(new PaymentMethodListOptions  {   Customer = customerId, Type = "card"});

and there doesn't seem to be a property anywhere that says the card is default (although it does correctly return all cards). I believe Stripe documentation states the Customer is the holder of the default source, not the card object. What gives?

Thanks in advance!

like image 492
NullHypothesis Avatar asked Dec 21 '25 00:12

NullHypothesis


1 Answers

It looks like you're using Payment Methods, since your payment method list call has the results you expect, which means the customer likely doesn't have any sources. You can try that again with the properly pluralized expand[]=sources if you do know your Customer has Sources attached.

For Payment Methods, there is no general default for the Customer. For one-time Payment Intents, you must always specify the payment_method from among those attached to the Customer for future payments.

For paying invoices (related to recurring subscriptions, eg), you can set the invoice_settings.default_payment_method for Customer. This only applies to invoices.

like image 153
Nolan H Avatar answered Dec 24 '25 11:12

Nolan H