Giter Site home page Giter Site logo

d-edge / cardidy Goto Github PK

View Code? Open in Web Editor NEW
29.0 8.0 12.0 153 KB

A .net library to identify credit card number and cvv

License: MIT License

C# 99.49% Batchfile 0.08% F# 0.43%
credit-card dotnet visa mastercard american-express jcb luhn-algorithm luhn library cvv

cardidy's People

Contributors

alejandrocq avatar aloisdg avatar aumeunier avatar blouflashdb avatar chiaramistro avatar dependabot[bot] avatar fighou avatar hey24sheep avatar ntbm avatar tarmil avatar torendil avatar wbalbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cardidy's Issues

Add support for Solo

Hello,

I would like to identify card from Solo. You can get Solo traits on Wikipedia.

Issuing network IIN ranges Active Length  Validation
Solo 6334, 6767 No 16, 18, 19 Luhn

Solo

If you want to solve this issue, check this how-to guide.

Cheers,

Would it be useful to prefilter per cards?

Hi!

Let's look at the main example from the readme.

var card = Dedge.Cardidy.Identify("4127540509730813").Single();
Console.WriteLine(card); // print Visa

Let's say that as a dev, we would like to know if a given card is a Visa. The current code would be a good enough way. To work Identify() has to walk every card until the find a matching one.

Basically here is how Cardidy currently works:

var list = new [] { Amex, MC, Mir, Foo, Bar, Visa }

var results = list.Where(card => card is matching)
return results;

We could improve that by passing a prefiltered list to Indentify().

var card = Dedge.Cardidy.Identify("4127540509730813", where: new[]{Visa}).Single();
Console.WriteLine(card); // print Visa

and inside we would do:

var list = prefiltered == null || !prefiltered.Any() ?  new [] { Amex, MC, Mir, Foo, Bar, Visa } : prefiltered;
var results = prefiltered.Where(card => card is matching);
return results;

Yay or nay? Since there is not a lot of card I am not sure that we gain much by doing that.

Should inactive card loose precedence over active card?

Hello,

Right now the precedence rule is quite wacky. One way to improve it could be to strictly favorite an active card over an inactive one. To know which card id actually active or not we can follow the Wikipedia's table:

For example, we would have Visa over Switch for a card starting with 4903 and GPN over Solor for a card starting with 6334:

image

Our goal is to identify a card given a card number. I guess that there are more chance to cross the path of an active card over an inactive one.

This change could introduce a breaking change.

What do you think?

Add support for Diners

Hello,

I would like to identify card from Diners (Diners Club International and Diners Club United States & Canada). You can get Diners traits on Wikipedia.

Should we returns meaningful error or should we keep it simple, stupid?

Hello,

Instead of an empty list maybe we could return a Result of data. Where Result can contains an error type (like Luhn check error or length error) or a all good with data something like

enum ResultCode {
    Ok,
    LengthError, // card with 50 digits
    ValidationAlgorithmError, // luhn fail
    ImplementationError, // unkown card
    etc...
}

class Result {
    public ResultCode ResultCode { get; }
    public CardType Card { get; }
}

This could be nice in the front-end to show message to the end user like "This card seems to be a visa be the length does not match. A visa should have 13 or 16 numbers."

image

Of course we wont handle the message, but this issue will provide the tool to unlock the feature to developers

Thoughts? Would it be useful?

cc @4gq @fighou @torendil

Allow noise in strict mode

Hi!

Before the Luhn check, there is a protection name strict mode. The strict mode is a guard to block the use of the Luhn check if all the other conditions are not fulfilled.

var isStrict = validateLength && !ignoreNoise && !handleAnonymization;
return knownCards
    .Where(knownCard => knownCard.Prefixes
        .Any(prefix => prefix.Contains(identificationNumber)
            && (!validateLength || knownCard.Lengths.Contains(digits.Count))
            && (!useCheck || isStrict && knownCard.Check(digits))
        )
).Select(x => x.Name);

source

The idea is that there is no meaning of using Luhn if we have a subsection of the card number filled with "#" or if we doesn't have the right number of digit. But we can allow noise. Let's change it by removing the ignoring noise from the strict check. This will follow the logic of https://www.creditcardvalidator.org/validator.

So the idea is to replace in Cardidy.cs:

var isStrict = validateLength && !ignoreNoise && !handleAnonymization;

by

var isStrict = validateLength && !handleAnonymization;

That's all.

Cheers,

Update card LankaPay

Hello,

I would like to update LankaPay. You can get LankaPay traits on Wikipedia.

This card uses Luhn check validation. You can add it by replacing its inheritance from ACard to ALuhnCard. That's all. It happens here:

internal record LankaPay : ACard

Of course, dont forget to edit the test cases to handle this update.

If you want to solve this issue, check this how-to guide.

Cheers,

Fix typos in the documentation

Hello,

English is not my mother tongue and it shows. In the file Cardidy.cs, I found some typo and maybe there is more.

  • valitidy should be validity
  • matchs should be matches
  • idenfied should be identified
  • True if it is seems alright should be True if it seems alright

Thank you! ^^'

Add Diners Club EnRoute

Diners Club EnRoute doesn't have IIN ranges on Wikipedia, but we can consider that they are missing. An thread is open on the "talk" section to add them:

Add missing Diners Club enRoute IIN ranges

Currently there is none. I looked online and found four tertiary sources mentioning that enRoute cards start with 2014 or 2149:

http://www.iinbase.com/
https://baymard.com/checkout-usability/credit-card-patterns
https://business.mapsofindia.com/finance/credit-cards/credit-card-number.html
https://binlists.com/

This match the number on the picture from enRoute's page: https://en.wikipedia.org/wiki/EnRoute_(credit_card)

Use BenchmarkDotNet as profiler

Hello,

Cardidy's performance are not critical and this project can value readability over performance, but it would still be nice to now where it stand and see if can do better without losing its readability. And since every performance subject starts with a profiler to get bottlenecks, let's add one: https://benchmarkdotnet.org/

Cheers

Fix the IIN size

Currently we consider that the IIN of a card is the 6 first digits max. So we extract it like this

var firstSixDigits = digits.Take(6).ToNumber().PadRight(6, 0);

In the Structure part of the Payment card number, we can read

The leading six or eight digits are the issuer identification number (IIN) sometimes referred to as the "bank identification number (BIN)". [emphasis added]

A good example of that is the card NPS Pridnestrovie with a IIN of 7 (i.e. 6054740–6054744) or the can UkrCard with a IIN of 8 (i.e. 60400100–60420099).

Here is what I would change in the current code:

  1. digits.Take(6).ToNumber().PadRight(6, 0); should be digits.Take(8).ToNumber().PadRight(8, 0);
  2. actually 8 should be a const digits.Take(maxIssuerIdentificationNumber ).ToNumber().PadRight(maxIssuerIdentificationNumber, 0);
  3. Finally firstSixDigits should be renamed to issuerIdentificationNumber

Note that issuerIdentificationNumber is a bit too long imho. bankIdentificationNumber is slighty better. We could as well use identificationNumber. Feel free to share you opinion on this matter. 😃

Suggestion to add a result model instead of [cardtype]

Identify function should return a result model class (serializable) instead of an IEnumerable. It will be scalable and better.

A few suggestions, when return card types from Identify function, there are 3 scenarios

1 - Card is invalid or symbols or shady

  • return should be CardType.Invalid

2 - Card is not yet supported, so not found

  • return should be CardType.Unkown or CardType.NotYetSupported

3 - Wrap everything inside Identify with try - catch

  • return CardType.ErrorIdentifying from catch block

To add new type

  • Invalid
  • ErrorIdentifying (this should be instead wrapped by another class instead)

Now, cardtype should only have card types(imo). A new model should be used for Identify result which could have

[Serializable]
IdentifyResult.cs

{
"Card Number": user_inputed numbe
"Identified Card Type" : {result}
"Error Identifying" : // bool? some string error? discuss?
"IsInvalid" : // if do not want to use cardtype for error handling
}

this should also in future could be wrapped in a bulkIdentify function which could have another property "Count".

Add missing credit cards

Hello,

We need some help to improve Cardidy. There are a lot of missing credit card. You can find them on Wikipedia. To identify them, we need to support them. Feel free to open a request issue for any missing cards. Looking for more? You can implement and test them yourself.

Thank you!

Compile down to JavaScript

Hello,

Cardidy could be helpful to the js crowd too.
Would it be possible to compile down the library to a npm package? I would love to see a GitHub Actions trigger on each release pushing to both nuget and npm.

I think the solution could be done with h5: https://github.com/theolivenbaum/h5

Have fun

Could we/should we replace the CardType as an enum to an object hierarchy?

Regarding the use of the library, keeping an enum such as CardTypes means that users will mostly have to use a huge switch to parse the type of card (for instance, in order to add some css class to display the card logo or in order other things, true story here).

Having an object hierarchy would allow for simpler overrides and usage, and keeping the object paradigm.

Your thoughts on that? I volunteer for this task if it is accepted

Generate a HTML doc and host it online

Hi!

Let's use docfx to generate a static documentation for Cardidy.

DocFX is an API documentation generator for .NET, which currently supports C#, VB and F#. It generates API reference documentation from triple-slash comments in your source code. It also allows you to use Markdown files to create additional topics such as tutorials and how-tos, and to customize the generated reference documentation. DocFX builds a static HTML website from your source code and Markdown files.

Then to we could host it on a web server (for example, github.io).

Add a F# sample to showcase Cardidy

Hello,

Cardidy should work as expected in a F# solution. Could we create a sample project to showcase it like we did for C#? The project can be named AppFs.

What should be this project's name?

Hello,

This is a sister project of Cardizer. In this one we are writing a library to correctly identify brands from a credit card number. Isn't there already library to achieve that? Yes. Most of them rely on regex and are quite difficult to maintain. This one will be regex free and tailored for our need.

Basically we are mostly going to do:

var card = "4771320594033";
var isVisa = Foo.Identify(card) == CardType.Visa; // true

Where Foo is the library's name. We are looking for a good, unique, easy name. Some idea:

If you choose a pun with detection, I will rename the Identify to function into Detect. Consistency is the key to predictability.

More ideas:

  • Cardamom (two herbs related to ginger. Their seeds are used as a spice.)
  • Cardamum (alternative name of Cardamom)
  • Cardamon (third alternative name of Cardamom)
  • Cardamome (french translation of Cardamom)
  • Cardamomo (spanish translation of Cardamom)

Any new ideas are welcome! What do you like? What is your favorite?

Target multiple sdks lower than .net6.0

This project + nugget only supports .net6.0 which is probably only a few hunder people using right now. I think at least min 4.6 should be targetted, otherwise .net5.0. What do you think?

Target .NET 5.0

Hello,

I am looking to use Cardidy in my project and I get this error:

NU1202: Le package Dedge.Cardidy 0.1.0-alpha n'est pas compatible avec net5.0 (.NETCoreApp,Version=v5.0). Le package Dedge.Cardidy 0.1.0-alpha prend en charge : net6.0 (.NETCoreApp,Version=v6.0)

Write documentation

Fill the read me with a gif, a how to install, how to use, etc. (cf Cardizer)

We got a not be fully compatible error on build

Reproduced steps:

  • pull the code base
  • dotnet build

output

Microsoft (R) Build Engine version 17.0.0-preview-21460-01+8f208e609 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [/home/aloisdg/Source/Cardidy/Cardidy.sln]
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [/home/aloisdg/Source/Cardidy/Cardidy.sln]
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
  Dedge.Cardidy -> /home/aloisdg/Source/Cardidy/src/Dedge.Cardidy/bin/Debug/netstandard2.0/Dedge.Cardidy.dll
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  Tests -> /home/aloisdg/Source/Cardidy/src/Tests/bin/Debug/netstandard2.0/Tests.dll
  Tests -> /home/aloisdg/Source/Cardidy/src/Tests/bin/Debug/net6.0/Tests.dll
  App -> /home/aloisdg/Source/Cardidy/src/App/bin/Debug/net6.0/App.dll

Build succeeded.

/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [/home/aloisdg/Source/Cardidy/Cardidy.sln]
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. [/home/aloisdg/Source/Cardidy/Cardidy.sln]
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'Dedge.Cardizer 0.5.0-alpha' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
/home/aloisdg/Source/Cardidy/src/Tests/Tests.csproj : warning NU1701: Package 'NUnit3TestAdapter 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
    6 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.04

I think this may be linked to #45

Add support for card Borica

Hello,

I would like to identify card from BORICA. You can get BORICA traits on Wikipedia:

Issuing network IIN ranges Active Length  Validation
BORICA (Bulgarian national payment system) 2205 Yes 16 Luhn

If you want to solve this issue, check this how-to guide.

Cheers,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.