This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Adding Brazilian cards and improve example project #7
Open
ghashi
wants to merge
8
commits into
maxkramer:master
Choose a base branch
from
ghashi:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3b15ba
Updating with Brazilian Cards
bocato e08b091
Merge pull request #1 from bocato/brazilian-swiftluhn
bocato f995442
Update README.md
bocato c30c509
Update README.md
bocato 0765c2f
Update README.md
bocato 88c9438
Update README.md
bocato 4683177
Make it compatible with swift3
ghashi be7b31f
Merge branch 'feature/swift3' into master
ghashi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -10,19 +10,47 @@ import UIKit | |
import SwiftLuhn | ||
|
||
class ViewController: UIViewController, UITextFieldDelegate { | ||
|
||
@IBOutlet weak var cardTextField: UITextField! | ||
@IBOutlet weak var typeLabel: UILabel! | ||
@IBOutlet weak var validityLabel: UILabel! | ||
|
||
|
||
//src: http://www.paypalobjects.com/en_US/vhelp/paypalmanager_help/credit_card_numbers.htm | ||
let americanExpress = "378282246310005" | ||
let americanExpress2 = "371449635398431" | ||
let americanExpressCorporate = "378734493671000" | ||
let australianBankCard = "5610591081018250" | ||
let dinersClub = "30569309025904" | ||
let dinersClub2 = "38520000023237" | ||
let discover = "6011111111111117" | ||
let discover2 = "6011000990139424" | ||
let jCB = "3530111333300000" | ||
let jCB2 = "3566002020360505" | ||
let masterCard = "5555555555554444" | ||
let masterCard2 = "5105105105105100" | ||
let visa = "4111111111111111" | ||
let visa2 = "4012888888881881" | ||
let visa3 = "4222222222222" | ||
|
||
// src: http://www.dicastech.net/numeros-de-cartoes-de-credito-para-testes/ | ||
let aura = "5078601870000127985" | ||
let aura2 = "5078601800003247449" | ||
let eloo = "636297000045701" | ||
|
||
// src: http://www.geradorcartaodecredito.com.br/hipercard | ||
let hipercard = "6062825756950756" | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
cardTextField.text = "378282246310005" | ||
updateLabel(cardTextField.text!.isValidCardNumber()) | ||
// Do any additional setup after loading the view, typically from a nib. | ||
|
||
let initialValue = visa2 | ||
|
||
cardTextField.text = initialValue | ||
updateValidityLabel(initialValue.isValidCardNumber()) | ||
updateTypeLabel(initialValue) | ||
} | ||
|
||
func updateLabel(_ isValid: Bool) { | ||
private func updateValidityLabel(_ isValid: Bool) { | ||
if isValid { | ||
validityLabel.text = "VALID" | ||
validityLabel.textColor = UIColor.green | ||
|
@@ -32,6 +60,14 @@ class ViewController: UIViewController, UITextFieldDelegate { | |
validityLabel.textColor = UIColor.red | ||
} | ||
} | ||
|
||
private func updateTypeLabel(_ string: String) { | ||
if let type = string.cardType() { | ||
typeLabel.text = type.stringValue() | ||
} else { | ||
typeLabel.text = "Unknown" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | ||
|
||
|
@@ -40,7 +76,10 @@ class ViewController: UIViewController, UITextFieldDelegate { | |
let updatedString = text.replacingCharacters(in: range, with: string) | ||
|
||
let isValid = updatedString.isValidCardNumber() | ||
updateLabel(isValid) | ||
updateValidityLabel(isValid) | ||
|
||
updateTypeLabel(updatedString) | ||
|
||
return true | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -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 { | ||
|
@@ -92,6 +95,8 @@ To run the unit test suite, please open the example project and hit CMD + U. | |
|
||
Max Kramer, [email protected], [@maxkramer](http://twitter.com/maxkramer) | ||
|
||
Elo, Hipercard and Aura by [@bocato](http://github.com/bocato/) | ||
|
||
## License | ||
|
||
SwiftLuhn is available under the MIT license. See the LICENSE file for more info. | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.