Rails : Stripe : Check if the card is already used

 

Stripe adds the same card multiple times; so skip duplication you need to verify and add if required

stripe_multiple_card26

 

new_card_token = params[:stripeToken]
stripe_token_object = Stripe::Token.retrieve(new_card_token)
stripe_card_object = stripe_token_object.card
fingerprint_of_the_card = stripe_card_object.fingerprint

unless @user.payment_sources.find_by_fingerprint(fingerprint_of_the_card)
  # Create a new source in Stripe

 

 

 

Sources:

http://stackoverflow.com/questions/23698614/can-i-check-whether-stripe-a-card-is-already-existed-before-going-to-create-new

https://stripe.com/docs/api#card_object

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s