d-edge / Cardidy

A .net library to identify credit card number and cvv
MIT License
30 stars 12 forks source link

Cardidy failed with JCB cards and Diners club cards #111

Closed merge-tek closed 1 year ago

merge-tek commented 1 year ago

Hello, I tried with the following credit cards numbers

JCB: 3530111333300000, 3566002020360505 Diners: 30569309025904, 3056930009020004

Also, I tried with this Credit Card Generator https://www.vccgenerator.org/, https://www.validcreditcardnumber.com/, and choose JCB or Diners Club options to generated, and all failed

The error I get is a Sequence contains more than one element

with DEdge.Cardidy.Identify(cardNumber).Single();

image
torendil commented 1 year ago

Hi @merge-tek !

First of all, thanks for using Cardidy!

For the first situation regarding JCB, it's because those cards could also be RuPay cards. We ordered them in an order that seemed like the most likely use of cards, hence why you'll find that JCB is the first one that gets out of the Identify method, but not the only one Please use First() instead of Single 🙂

For Diner's Club International, the IIN should start with 36, so it is normal you wouldn't find a match with a card that starts with 30. Could you please tell me the configuration you used to get something else than 36 as a prefix? I tried with the first card generator you provided (put US/Diner's club international as an issuer brand) and it worked for the credit card numbers I was provided.

By the way, if you know there is a range that is not in the Wiki page, please update the wikipedia and you can also contribute to the library by opening a PR 🙂

Don't hesitate to close the issue or ask for it's closing if you have no further issue 😃

With my best

aloisdg commented 1 year ago

Hi! Here is a a small demo showcasing @torendil's excellent answer:

using System;
using System.Linq;
using DEdge;

public class Program
{
    public static void Main()
    {
        var cardNumber = "3530111333300000";
        // this line will fail because this card number can be either a JCB or RuPay card
        // var result = Cardidy.Identify(cardNumber).Single();
        // try this instead
        var result = Cardidy.Identify(cardNumber).First();
        Console.WriteLine(result);
        // or even
        foreach (var card in Cardidy.Identify(cardNumber))
        {
            Console.WriteLine($"cardNumber can be {card}");
        }
    }
}

https://dotnetfiddle.net/2yHfZQ

aloisdg commented 1 year ago

Let's close this one for now. Feel free to open a new question if you have one.