d-edge / cardidy Goto Github PK
View Code? Open in Web Editor NEWA .net library to identify credit card number and cvv
License: MIT License
A .net library to identify credit card number and cvv
License: MIT License
Hello,
I would like to identify card from UkrCard. You can get UkrCard traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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 |
If you want to solve this issue, check this how-to guide.
Cheers,
Hello,
I would like to identify card from China UnionPay. You can get China UnionPay traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
Hi!
All flags are not covered by the documentation and showcase as example. We need more :)
Hello,
I would like to identify card from Laser. You can get Laser traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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.
Hello,
I would like to identify card from LankaPay. You can get LankaPay traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
Hello,
I would like to identify card from Dankort. You can get Dankort traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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:
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?
Hello,
I would like to identify card from Troy. You can get Troy traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
Hello,
I would like to identify card from Humo. You can get Humo traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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.
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."
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?
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);
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,
Hello,
I would like to identify card from InterPayment. You can get InterPayment traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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:
Cardidy/src/DEdge.Cardidy/Model/Cards.cs
Line 108 in 81cd3f6
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,
Hello,
I would like to identify card from NPS Pridnestrovie. You can get NPS Pridnestrovie traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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();
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! ^^'
Hello,
I would like to update Verve. You can get Verve traits on Wikipedia.
We mostly have to:
18
to this lineCardidy/src/DEdge.Cardidy/Model/Cards.cs
Line 36 in 81cd3f6
ALuhnCard
instead of ACard
If you want to solve this issue, check this how-to guide.
Cheers,
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)
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
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:
digits.Take(6).ToNumber().PadRight(6, 0);
should be digits.Take(8).ToNumber().PadRight(8, 0);
8
should be a const digits.Take(maxIssuerIdentificationNumber ).ToNumber().PadRight(maxIssuerIdentificationNumber, 0);
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. 😃
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
2 - Card is not yet supported, so not found
3 - Wrap everything inside Identify with try - catch
To add new type
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".
Hello,
I would like to identify card from UzCard. You can get UzCard traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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!
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
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
Hello,
I would like to identify card from Bankcard. You can get Bankcard traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
Hello,
I would like to identify card from RuPay. You can get RuPay traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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).
In code Identify, instead of sending empty array back, it should return card type of "Invalid" or "Unknown" depending on if the card is not found or is shady/bad.
Hello,
I would like to identify card from InstaPayment. You can get InstaPayment traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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
.
Hello,
I would like to identify card from GPN. You can get GPN traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
I noticed in the how to, that is not mentioned that I need to fork the project, commit my changes in my branch and then make a PR.
Because if I just make a branch from main I will not have permission to make a PR, at least I tried and get an error.
An explication on how to contribute using a fork is here: https://www.dataschool.io/how-to-contribute-on-github/
Thanks.
Hello,
I would like to identify card from Switch. You can get Switch traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
Hello,
I would like to identify card from China T-Union. You can get China T-Union traits on Wikipedia.
If you want to solve this issue, check this how-to guide.
Cheers,
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:
Any new ideas are welcome! What do you like? What is your favorite?
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?
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)
Hello,
Some websites can returns more information than the issuing network from a IIN, should we investigate to returns more too?
Those websites:
Cheers,
Fill the read me with a gif, a how to install, how to use, etc. (cf Cardizer)
.NET 5.0 adds Source Code Generator to the C# world: https://devblogs.microsoft.com/dotnet/introducing-c-source-generators/
The goal would be to move all the data into a json data file and to generate all the classes, the enum, etc. with source generator.
Reproduced steps:
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
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,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.