how can i check whether a Stripe customer already has a specific card before adding a new one in django python

Viewed 229

I want to store multiple card on stripe for customer.In this, customer try to add new card on stripe at that time check if this card store or not in django python

I use below code to add customer card on stripe

 card = stripe.Customer.create_source(
                    'customer_stripe_id'
                    source =request.POST['stripeToken']
                )
1 Answers

Once you use the customer create source api store the card details( card id, fingerprints, etc)

stripe.Customer.create_source(
                    'customer_stripe_id'
                    source =request.POST['stripeToken']
                )

You can check if the same card exists for the customer by listing the cards through card listing api and then checking the card fingerprints that you will get in the response:

cards = stripe.Customer.list_sources(
  'cus_FMsdyCbtYeOCJr',
  object='card'
)

For this you need to store the customer id and other card details that are required for this.

Fingerprints for all the cards are unique

For your Reference : Stripe Documentation

Related