How to Restrict Users from Adding Duplicate Cards on Stripe?

79 Views Asked by At

I'm working on integrating Stripe into my application and have encountered a scenario where users are able to add the same card multiple times. I want to prevent users from adding duplicate card entries.

Is there any built-in restriction in Stripe to prevent the addition of the same card again and again? If not, what would be the recommended approach to implement such a restriction on my end? I want to ensure a seamless user experience while avoiding unnecessary duplication of card entries.

Any insights or code snippets demonstrating how to handle this scenario would be greatly appreciated!

I'm using laravel. I've checked the relevant documentation on Stripe but couldn't find information specifically addressing this use case. I'm currently handling card additions through

$paymentMethod = $request->user()->addPaymentMethod($request->token);
        //setting newly added card as default card if getting mark as default true in request
        $request->input('mark_as_default') ? $request->user()->updateDefaultPaymentMethod($paymentMethod->id) : null;

        return $paymentMethod;

Thank you in advance for your assistance!

1

There are 1 best solutions below

0
soma On

It's possible to prevent duplicate cards, but that require some custom code. What you need to do:

  • Save in your own database the fingerprint of all your existing PaymentMethods
  • When saving a new PaymentMethod, compare the new fingerprint to the ones in your database
  • If you find another card with the same fingerprint, it means it's a duplicate