#nickderobertis
1 messages · Page 1 of 1 (latest)
Hello! What do you mean by "belongs to"? Like one that's been attached to a Customer?
Hi, yes sorry attached
You can retrieve the Payment Method: https://stripe.com/docs/api/payment_methods/retrieve
And then look at its customer property: https://stripe.com/docs/api/payment_methods/object#payment_method_object-customer
oh great, this works even better for our purpose. because in our case we lost some customer IDs and now are not able to create payment intents for those payment methods. but with this we can even just recover that customer ID. thanks!
This payment method api works for Card objects too, right?
Or do we need to inspect the ID and switch to calling retrieve card?
No, Card objects have a different API: https://stripe.com/docs/api/cards
But the principal is the same.
ok cool, we'll do some switching logic on the first part of the ID then.
Last thing to confirm, so this note on retrieve payment method is more a best practice than a restriction? The API will still work when the payment method is attached to a customer?
To retrieve a payment method attached to a Customer, you should use Retrieve a Customer’s PaymentMethods
If you have the Payment Method's ID it will work, yeah.
At least I'm pretty sure it will... not sure why it wouldn't.
Ok awesome. Thanks for your help!
Wait, it looks like the retrieve a card endpoint requires the customer ID in the first place https://stripe.com/docs/api/cards/retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
It seems like all the card endpoints are prefixed by customer ID. So is this not possible for Card objects? Is there another strategy I can use?
I guess my original thought of validating would still be possible. If we plug a customer ID and card ID in, it would assumedly return a not found response if the card is not attached to the customer. But there's no way to recover the customer ID given a card ID?
So you have a bunch of Payment Method and Card IDs and you need to find the associated Customer IDs?
You can list all Cards and get the Customer IDs for them that way: https://stripe.com/docs/api/cards/list
Oh, wait, that requires a Customer ID too.
Hm.
There may not be a way, actually. At least not via the API.
You can look in the Dashboard... how many do you have?
For Cards you could list Customers and expand sources: https://stripe.com/docs/api/customers/object#customer_object-sources
And I guess list all Payment Methods for each Customer as you go through every Customer: https://stripe.com/docs/api/payment_methods/customer_list
Yeah that seems like it could work! A little roundabout but I'm glad this is possible
Yeah, I can't find a more direct way to do it.
So customer.sources[].data.id will return Card id? Or do I need to back into the card from a Source object somehow?
It depends on how the Card was attached. Did you use Cards directly or did you wrap them in Sources? Or a mix? You might need to do both depending on what you find in the result.
I think cards directly, but not 100% clear on that, will need to review the existing implementation
What does the response look like for standalone Card versus Source-wrapped Card?
👋 hopping in here since rubeus has to head out
The Card and Source objects are slightly different. If you're attaching Sources instead of Cards then you'll have to check the card hash for the card-specific details
👋 Hey! Thanks for jumping in.
Could you clarify the card hash? I don't see card under the attributes here: https://stripe.com/docs/api/customers/object#customer_object-sources-data
And are you saying that if we attached a card directly, then the ID here would be Card.id? https://stripe.com/docs/api/customers/object#customer_object-sources-data-id
Yeah I'm not sure why it's not reflected in the API reference, but here's a quick example that I did on my end
That's super helpful, thanks! Hmm but I notice the Card wrapped in the source doesn't have a Card ID in the card part. Is there not a Card ID when a Card is wrapped in a Source?
Yeah I don't think you get that back with the Source object if it's wrapping a card
Are you saying in general or just with this response? Like if we were historically wrapping cards with sources, would we have only ever seen Source IDs and not Card ids? Or if it's just this response, what endpoint should I use to go from Source ID -> Card ID?
Let me back up - if you've been only creating Sources/cards wrapped in Sources then you'll have only been working with Source IDs.
There isn't an endpoint to go from the Source -> Card
Ok thank you, that definitely clarifies things. Examining our database, we only have card_xxx and pm_xxx ids, not src_xxx ids, so it seems that we have not wrapped cards in sources. In that case, I should get the object: card example response you gave.
yup!