diff --git a/.gitignore b/.gitignore index 8a30d25..104b544 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,10 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. ## -## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +## Get latest from `dotnet new gitignore` + +# dotenv files +.env # User-specific files *.rsuser @@ -57,11 +60,14 @@ dlldata.c # Benchmark Results BenchmarkDotNet.Artifacts/ -# .NET Core +# .NET project.lock.json project.fragment.lock.json artifacts/ +# Tye +.tye/ + # ASP.NET Scaffolding ScaffoldingReadMe.txt @@ -396,3 +402,83 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml +.idea + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp diff --git a/CodeCave.CredyCard.sln b/CodeCave.CredyCard.sln new file mode 100644 index 0000000..94f8a92 --- /dev/null +++ b/CodeCave.CredyCard.sln @@ -0,0 +1,30 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34321.82 +MinimumVisualStudioVersion = 10.0.40219.1' +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E034D940-89F7-4DF9-9F1C-A723F163E5BB}" + ProjectSection(SolutionItems) = preProject + .gitignore = .gitignore + EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CodeCave.CredyCard", "src\CodeCave.CredyCard.csproj", "{FC8BD8F5-5ECA-432A-85FE-2292A6E0E4E9}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FC8BD8F5-5ECA-432A-85FE-2292A6E0E4E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FC8BD8F5-5ECA-432A-85FE-2292A6E0E4E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FC8BD8F5-5ECA-432A-85FE-2292A6E0E4E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FC8BD8F5-5ECA-432A-85FE-2292A6E0E4E9}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {E8D4B4FF-527A-46C8-B5CA-0F1373C8E145} + EndGlobalSection +EndGlobal diff --git a/src/CardInfo.cs b/src/CardInfo.cs new file mode 100644 index 0000000..1cace24 --- /dev/null +++ b/src/CardInfo.cs @@ -0,0 +1,10 @@ +namespace CodeCave.CredyCard; + +public abstract class CardInfo +{ + public CardType Type { get; internal set; } + + public long Number { get; internal set; } + + public string NumberFormatted => string.Format("{0:0000 0000 0000 0000}", Number); +} diff --git a/src/CardType.cs b/src/CardType.cs new file mode 100644 index 0000000..a322b22 --- /dev/null +++ b/src/CardType.cs @@ -0,0 +1,82 @@ +namespace CodeCave.CredyCard; + +public class CardType +{ + private CardType() + { + + } + + public bool IsCreditCard { get; private set; } + + public bool IsDebitCard => !IsCreditCard; + + public string[] VendorCodes { get; private set; } + + public string VendorCode => VendorCodes?.FirstOrDefault(); + + public string[] VendorNames { get; private set; } + + public string VendorName => VendorNames?.FirstOrDefault(); + + public int RequiredLength { get; private set; } + + private void ParseNumber(long cardNumber) + { + RequiredLength = 16; + + switch (cardNumber) + { + case var visa when cardNumber.IsVisaCardNumber(): + VendorCodes = ["VISA"]; + VendorNames = ["Visa"]; + break; + + case var mastercard when cardNumber.IsMastercardNumber(): + VendorCodes = ["MAST"]; + VendorNames = ["Mastercard"]; + break; + + case var maestro when cardNumber.IsMaestroCardNumber(): + VendorCodes = ["MAES"]; + VendorNames = ["Maestro"]; + break; + + case var amex when cardNumber.IsAmexCardNumber(): + VendorCodes = ["AMEX"]; + VendorNames = ["American Express"]; + break; + + case var maestro when cardNumber.IsDinersCardNumber(): + VendorCodes = ["DINR"]; + VendorNames = ["Diners"]; + break; + + default: + VendorCodes = ["N/A"]; + VendorNames = ["Unknown"]; + break; + } + } + + public static CardType Parse(long cardNumber) + { + var cardType = new CardType(); + cardType.ParseNumber(cardNumber); + return cardType; + } + + public static bool TryParse(long cardNumber, out CardType cardType) + { + try + { + cardType = Parse(cardNumber); + return true; + } + catch + { + cardType = default; + return false; + } + } +} \ No newline at end of file diff --git a/src/CodeCave.CredyCard.csproj b/src/CodeCave.CredyCard.csproj new file mode 100644 index 0000000..cf309aa --- /dev/null +++ b/src/CodeCave.CredyCard.csproj @@ -0,0 +1,9 @@ + + + + net8.0 + enable + disable + + + diff --git a/src/Extensions/LongExtensions.cs b/src/Extensions/LongExtensions.cs new file mode 100644 index 0000000..da735fe --- /dev/null +++ b/src/Extensions/LongExtensions.cs @@ -0,0 +1,34 @@ +namespace System; + +public static class LongExtensions +{ + public static bool IsVisaCardNumber(this long cardNumber) + { + // TODO detect + return true; + } + + public static bool IsMastercardNumber(this long cardNumber) + { + // TODO detect + return true; + } + + public static bool IsMaestroCardNumber(this long cardNumber) + { + // TODO detect + return true; + } + + public static bool IsAmexCardNumber(this long cardNumber) + { + // TODO detect + return true; + } + + public static bool IsDinersCardNumber(this long cardNumber) + { + // TODO detect + return true; + } +} \ No newline at end of file