Skip to content

Commit

Permalink
drafting C# implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
salaros committed Dec 10, 2023
1 parent 7efe018 commit 5693df1
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 2 deletions.
90 changes: 88 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
30 changes: 30 additions & 0 deletions CodeCave.CredyCard.sln
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions src/CardInfo.cs
Original file line number Diff line number Diff line change
@@ -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);
}
82 changes: 82 additions & 0 deletions src/CardType.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
9 changes: 9 additions & 0 deletions src/CodeCave.CredyCard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>

</Project>
34 changes: 34 additions & 0 deletions src/Extensions/LongExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 5693df1

Please sign in to comment.