-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
253 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |