Created
March 9, 2015 17:13
-
-
Save chadkouse/f772316c0fa8e4d2244f to your computer and use it in GitHub Desktop.
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
var cardNumber = "" | |
var cvv = "" | |
var expirationMonth = 0 | |
var expirationYear = 0 | |
var showError:(String)->Void = { errorMsg in | |
let alert = UIAlertView(title: "Missing Information", message: "Please ensure your \(errorMsg) is correct", delegate: nil, cancelButtonTitle: "OK") | |
alert.show() | |
} | |
var ok = false | |
if let tn = txtCardNumber { | |
cardNumber = tn.cardNumber | |
if cardNumber.utf16Count >= 13 { ok = true } | |
} | |
if !ok { | |
showError("credit card number") | |
return false | |
} | |
ok = false | |
if let tc = txtSecurityCode { | |
cvv = tc.text | |
if cvv.utf16Count >= 3 { ok = true } | |
} | |
if !ok { | |
showError("security code") | |
return false | |
} | |
ok = false | |
if let lm = lblExpirationMonth { | |
if let t = lm.text { | |
if let em = t.substringToIndex(advance(t.startIndex, 2)).toInt() { | |
expirationMonth = em | |
ok = true | |
} | |
} | |
} | |
if !ok { | |
showError("expiration date - month") | |
return false | |
} | |
ok = false | |
if let ly = lblExpirationYear { | |
if let t = ly.text { | |
if let ey = t.toInt() { | |
expirationYear = ey | |
ok = true | |
} | |
} | |
} | |
if !ok { | |
showError("expiration date - year") | |
return false | |
} | |
if let p = purchase { | |
p.creditCardInfo = GCICreditCardInfo(cardNumber: cardNumber, | |
cvv: cvv, | |
expirationMonth: expirationMonth, | |
expirationYear: expirationYear) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment