how to prevent user to add duplicate card in stripe using laravel
$stripe = new StripeClient('STRIPE_SECRET_KEY');
$cards = $stripe->paymentMethods->all(['customer' => 'CUSTOMER_ID', 'type' => 'card']);
$fingerprints = [];
foreach ($cards as $card) {
$fingerprint = $card['card']['fingerprint'];
if (in_array($fingerprint, $fingerprints, true)) {
$stripe->paymentMethods->detach($card['id']);
} else {
$fingerprints[] = $fingerprint;
}
}