#Pain - Customer PMs
1 messages ยท Page 1 of 1 (latest)
HI ๐
This needs to be 2 API calls if you want the full customer object and payment methods.
If you have the customer ID and just want the Payment Methods you can get those directly
I see, I can also see that the default payment method does get retrieved with the customer
Well...more than 2 if you have multiple payment method types.
https://stripe.com/docs/api/payment_methods/customer_list
Sorry, I was referring to the customers.retrieve endpoint
Right. But if you want more than the default (for customers with multiple PMs) then this is the endpoint you'll need to hit
I will try this endpoint, I want to make sure it specifies if a card is default
Ah okay.
I believe this endpoint does not return which payment method is default, would I have to expand on the customer and then access the default payment method from there?
If you just want the default PM for a customer the you'll want to expand the default_source property
From the customer?
Hitting the Customer retrieve endpoint and pass default_source in the expand parameter
Wouldn't it be better to do the following:
const paymentMethods = await stripe.customers.listPaymentMethods(
customerId,
{
expand: ['data.customer'],
type: 'card'
},
);
Then access it from paymentMethods.data.customer.invoice_settings.default_payment_method?
(data is an array but that's just a path example)
My question is, is it better to just expand it there initially or just do another API call to get that specifically
I'm sorry but what are you actually trying to do here?
I'm trying to retrieve all the payment methods from a customer and know which one is default
Okay so I would first retrieve the Customer object: https://stripe.com/docs/api/customers/retrieve
while passing expand: ["default_source"] to get the full expanded PM.
Then retrieve the rest of the payment methods and filter out the default?
Also, does 'expand' act as multiple requests or is it still 1 request? On top of that is it faster to use expand over two requests?
Hi there ๐ jumping in as my teammate needed to step away, please bear with me a moment while I catch up on the context here.
That approach that you raised, about listing all Payment Methods for a Customer and expanding the Customer object in that response, is something that I haven't seen before but seems quite clever.
Leveraging expand within a request still results in just a single request being created/processed. I'm not entirely certain whether using expand is faster than making two separate requests, as that would depend on the underlying joins being performed compared to the general overhead of making a network request.