#brian.scott
1 messages · Page 1 of 1 (latest)
You would have to create the Payment Method first in order to know if there is an identical fingerprint amongst your other Payment Methods
Yes, you can test if a payment method's fingerprint exists before adding it to the customer. One way to achieve this is by retrieving the customer's existing payment methods and comparing their fingerprints with the fingerprint of the new payment method you want to add.
Here's an example of how you can do this using the Stripe API in Python:
Retrieve the customer's existing payment methods:
import stripe
stripe.api_key = 'YOUR_SECRET_API_KEY'
customer_id = 'CUSTOMER_ID'
customer = stripe.Customer.retrieve(customer_id)
existing_payment_methods = customer.payment_methods
@fleet depot I appreciate the extra attention/assistance here, but I think you may be misunderstanding the question.
can I test if the payment method's fingerprint exists before adding it?
The answer is: no. The payment method has to be created in order to get a fingerprint from it. They're trying to prevent duplicates, so the above Python code isn't really helpful.
Ohh thanks for your attention and help
right, so setupIntent returns a paymentMethod, but at that point it attached to the customer already (and setup for future use) - creating the method outside of setupIntents is not recommended per the docs
yup, exactly. Alternatively, can iteratively go through all your customers' payment methods after the fact and delete duplicates, but keep in mind if you use Invoices or Subscriptions, you may need to double-check that they have a default payment method set after batch-deleting duplicates. It's possible to delete a customer's default payment method, which could affect your existing subscriptions and/or invoices
This makes sense, I can handle the deletion and defaulting was just wondering if there was a way to test before add, and it seems not
thanks for your help
Sure thing!