#Pain - Customer PMs

1 messages ยท Page 1 of 1 (latest)

sonic prairie
#

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

mossy blaze
#

I see, I can also see that the default payment method does get retrieved with the customer

sonic prairie
mossy blaze
#

Sorry, I was referring to the customers.retrieve endpoint

sonic prairie
#

Right. But if you want more than the default (for customers with multiple PMs) then this is the endpoint you'll need to hit

mossy blaze
#

I will try this endpoint, I want to make sure it specifies if a card is default

sonic prairie
#

Ah okay.

mossy blaze
#

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?

sonic prairie
#

If you just want the default PM for a customer the you'll want to expand the default_source property

mossy blaze
#

From the customer?

sonic prairie
#

Hitting the Customer retrieve endpoint and pass default_source in the expand parameter

mossy blaze
#

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

sonic prairie
#

I'm sorry but what are you actually trying to do here?

mossy blaze
#

I'm trying to retrieve all the payment methods from a customer and know which one is default

sonic prairie
mossy blaze
#

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?

runic locust
#

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.

mossy blaze
#

Got it, I think it's best to use expand whenever possible. Joins tend to be typically faster in general, especially since I wont be sending multiple requests. I will have to filter out the default_payment in both scenarios.

#

Thanks for the insight.