Skip to content
This repository was archived by the owner on Jan 20, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions Example/SwiftLuhn.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
A2BCD9AE2D95C7DCB60CB392 /* Pods-SwiftLuhn_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftLuhn_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftLuhn_Example/Pods-SwiftLuhn_Example.release.xcconfig"; sourceTree = "<group>"; };
AA640ED277322E98AADE4DB9 /* Pods-SwiftLuhn_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftLuhn_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftLuhn_Tests/Pods-SwiftLuhn_Tests.debug.xcconfig"; sourceTree = "<group>"; };
B2FBF89F16A4DC0F2751FEC7 /* Pods-SwiftLuhn_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwiftLuhn_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwiftLuhn_Example/Pods-SwiftLuhn_Example.debug.xcconfig"; sourceTree = "<group>"; };
B90E7FE8BD11978D5BB1B434 /* SwiftLuhn.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SwiftLuhn.podspec; path = ../SwiftLuhn.podspec; sourceTree = "<group>"; };
B90E7FE8BD11978D5BB1B434 /* SwiftLuhn.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SwiftLuhn.podspec; path = ../SwiftLuhn.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
CC106E6E669DC2ACEADFF7AC /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -218,11 +218,11 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0940;
LastSwiftMigration = 1010;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
LastSwiftMigration = 0940;
LastSwiftMigration = 1010;
TestTargetID = 607FACCF1AFB9204008FA782;
};
};
Expand Down Expand Up @@ -474,11 +474,12 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SwiftLuhn/Info.plist;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -488,26 +489,28 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = SwiftLuhn/Info.plist;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
};
name = Release;
};
607FACF31AFB9204008FA782 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = AA640ED277322E98AADE4DB9 /* Pods-SwiftLuhn_Tests.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = Tests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftLuhn_Example.app/SwiftLuhn_Example";
};
name = Debug;
Expand All @@ -516,10 +519,11 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 8AD47538614B334D166DC901 /* Pods-SwiftLuhn_Tests.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = "";
INFOPLIST_FILE = Tests/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftLuhn_Example.app/SwiftLuhn_Example";
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftLuhn/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?


func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
Expand Down
5 changes: 4 additions & 1 deletion Example/Tests/CardTypeTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class CardTypeTest: XCTestCase {
SwiftLuhn.CardType.jcb: "JCB",
SwiftLuhn.CardType.maestro: "Maestro",
SwiftLuhn.CardType.rupay: "Rupay",
SwiftLuhn.CardType.mir: "Mir"
SwiftLuhn.CardType.mir: "Mir",
SwiftLuhn.CardType.elo: "Elo",
SwiftLuhn.CardType.hipercard: "Hipercard",
SwiftLuhn.CardType.aura: "Aura"
]

mapping.forEach { key, value in
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ You can also get the type of the card being used which will be one of:
|Discover|
|Diner's Club|
|JCB|
|Elo|
|Hipercard|
|Aura|

```swift
do {
Expand All @@ -92,6 +95,10 @@ To run the unit test suite, please open the example project and hit CMD + U.

Max Kramer, max@maxkramer.co, [@maxkramer](http://twitter.com/maxkramer)

Elo, Hipercard and Aura by, [@bocato]

Elo update by, André Ferreira, [@andre991](https://github.com/andre991)

## License

SwiftLuhn is available under the MIT license. See the LICENSE file for more info.
Expand Down
2 changes: 1 addition & 1 deletion SwiftLuhn.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SwiftLuhn'
s.version = '1.0.0'
s.version = '1.1.0'
s.summary = 'SwiftLuhn is a port of the Luhn algorithm, used for validating debit/credit card details.'
s.description = <<-DESC
This is a port of the Luhn Algorithm, generally used for validating debit/credit card details, to Swift.
Expand Down
33 changes: 30 additions & 3 deletions SwiftLuhn/Classes/SwiftLuhn.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ open class SwiftLuhn {
case maestro
case rupay
case mir
case elo
case hipercard
case aura
}

public enum CardError: Error {
Expand Down Expand Up @@ -46,6 +49,12 @@ open class SwiftLuhn {
return "^6[0-9]{15}$"
case .mir:
return "^220[0-9]{13}$"
case .elo:
return "^(4011(78|79)|43(1274|8935)|45(1416|7393|763(1|2))|50(4175|6699|67[0-7][0-9]|9000)|50(9[0-9][0-9][0-9])|627780|63(6297|6368)|650(03([^4])|04([0-9])|05(0|1)|05([7-9])|06([0-9])|07([0-9])|08([0-9])|4([0-3][0-9]|8[5-9]|9[0-9])|5([0-9][0-9]|3[0-8])|9([0-6][0-9]|7[0-8])|7([0-2][0-9])|541|700|720|727|901)|65165([2-9])|6516([6-7][0-9])|65500([0-9])|6550([0-5][0-9])|655021|65505([6-7])|6516([8-9][0-9])|65170([0-4]))"
case .hipercard:
return "^(38|60)[0-9]{11,17}$"
case .aura:
return "^50[0-9]{14,17}$"
}
}

Expand All @@ -69,10 +78,16 @@ open class SwiftLuhn {
return "^6[0-9]+$"
case .mir:
return "^220[0-9]+$"
case .elo:
return "^(4011(78|79)|43(1274|8935)|45(1416|7393|763(1|2))|50(4175|6699|67[0-7][0-9]|9000)|50(9[0-9][0-9][0-9])|627780|63(6297|6368)|650(03([^4])|04([0-9])|05(0|1)|05([7-9])|06([0-9])|07([0-9])|08([0-9])|4([0-3][0-9]|8[5-9]|9[0-9])|5([0-9][0-9]|3[0-8])|9([0-6][0-9]|7[0-8])|7([0-2][0-9])|541|700|720|727|901)|65165([2-9])|6516([6-7][0-9])|65500([0-9])|6550([0-5][0-9])|655021|65505([6-7])|6516([8-9][0-9])|65170([0-4]))"
case .hipercard:
return "^(38|60)[0-9]{11,17}$"
case .aura:
return "^50[0-9]{14,17}$"
}
}

class func performLuhnAlgorithm(with cardNumber: String) throws {
public class func performLuhnAlgorithm(with cardNumber: String) throws {

let formattedCardNumber = cardNumber.formattedCardNumber()

Expand Down Expand Up @@ -113,10 +128,10 @@ open class SwiftLuhn {
}
}

class func cardType(for cardNumber: String, suggest: Bool = false) throws -> CardType {
public class func cardType(for cardNumber: String, suggest: Bool = false) throws -> CardType {
var foundCardType: CardType?

for i in CardType.amex.rawValue...CardType.jcb.rawValue {
for i in CardType.amex.rawValue...CardType.aura.rawValue {
let cardType = CardType(rawValue: i)!
let regex = suggest ? suggestionRegularExpression(for: cardType) : regularExpression(for: cardType)

Expand Down Expand Up @@ -157,6 +172,12 @@ public extension SwiftLuhn.CardType {
return "Rupay"
case .mir:
return "Mir"
case .elo:
return "Elo"
case .hipercard:
return "Hipercard"
case .aura:
return "Aura"
}
}

Expand All @@ -180,6 +201,12 @@ public extension SwiftLuhn.CardType {
self.init(rawValue: 7)
case "mir":
self.init(rawValue: 8)
case "elo":
self.init(rawValue: 9)
case "hipercard":
self.init(rawValue: 10)
case "aura":
self.init(rawValue: 11)
default:
return nil
}
Expand Down