forked from card-io/card.io-iOS-source
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Mark Rogers
committed
Nov 17, 2015
1 parent
9726410
commit 0906c12
Showing
39 changed files
with
257 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// CardIOConfigurableTextFieldDelegate.h | ||
// See the file "LICENSE.md" for the full license governing this code. | ||
// | ||
|
||
#import "CardIOConfigurableTextFieldDelegate.h" | ||
|
||
@interface CardIOCardholderNameTextFieldDelegate : CardIOConfigurableTextFieldDelegate { | ||
|
||
} | ||
|
||
+(BOOL)isValidCardholderName:(NSString*)cardholderName; | ||
|
||
@end |
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,24 @@ | ||
// | ||
// CardIOCardholderNameTextFieldDelegate.m | ||
// See the file "LICENSE.md" for the full license governing this code. | ||
// | ||
|
||
#import "CardIOCardholderNameTextFieldDelegate.h" | ||
|
||
@implementation CardIOCardholderNameTextFieldDelegate | ||
|
||
-(id) init { | ||
if ((self = [super init])) { | ||
// Globalization: alphanumeric, space, hyphen are all definitely okay; | ||
// there's no compelling reason for us to get fussy here. | ||
self.numbersOnly = NO; | ||
self.maxLength = 175; // PayPal REST APIs accept max of 175 chars for cardholder name | ||
} | ||
return self; | ||
} | ||
|
||
+(BOOL)isValidCardholderName:(NSString*)cardholderName { | ||
return [cardholderName length] > 0; | ||
} | ||
|
||
@end |
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
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,6 +10,7 @@ | |
#import "CardIONumbersTextFieldDelegate.h" | ||
#import "CardIOCVVTextFieldDelegate.h" | ||
#import "CardIOPostalCodeTextFieldDelegate.h" | ||
#import "CardIOCardholderNameTextFieldDelegate.h" | ||
#import "CardIOCreditCardNumber.h" | ||
#import "CardIORowBasedTableViewSection.h" | ||
#import "CardIOSectionBasedTableViewDelegate.h" | ||
|
@@ -50,6 +51,7 @@ - (NSString *)cvvPlaceholder; | |
@property(nonatomic, strong, readwrite) CardIOExpiryTextFieldDelegate* expiryTextFieldDelegate; | ||
@property(nonatomic, strong, readwrite) CardIOCVVTextFieldDelegate *cvvRowTextFieldDelegate; | ||
@property(nonatomic, strong, readwrite) CardIOPostalCodeTextFieldDelegate *postalCodeRowTextFieldDelegate; | ||
@property(nonatomic, strong, readwrite) CardIOCardholderNameTextFieldDelegate *cardholderNameRowTextFieldDelegate; | ||
@property(nonatomic, assign, readwrite) CGSize notificationSize; | ||
@property(nonatomic, strong, readwrite) CardIOContext *context; | ||
@property(nonatomic, assign, readwrite) CardIOCreditCardType cardTypeForLogo; | ||
|
@@ -147,8 +149,9 @@ - (void)viewDidLoad { | |
self.navigationItem.rightBarButtonItem.enabled = NO; | ||
|
||
self.collectExpiry = pvc.collectExpiry; | ||
self.collectCVV = pvc.collectCVV; | ||
self.collectPostalCode = pvc.collectPostalCode; | ||
self.collectCVV = pvc.collectCVV; | ||
self.collectPostalCode = pvc.collectPostalCode; | ||
self.collectCardholderName = pvc.collectCardholderName; | ||
|
||
self.scrollView = [[UIScrollView alloc] initWithFrame:self.relevantViewFrame]; | ||
|
||
|
@@ -290,33 +293,59 @@ - (void)viewDidLoad { | |
} | ||
|
||
[rows addObject:multiFieldRow]; | ||
} | ||
|
||
if(self.collectPostalCode) { | ||
CardIOMultipleFieldTableViewCell *postalCodeRow = [[CardIOMultipleFieldTableViewCell alloc] init]; | ||
postalCodeRow.backgroundColor = kColorDefaultCell; | ||
postalCodeRow.numberOfFields = 1; | ||
postalCodeRow.hiddenLabels = YES; | ||
postalCodeRow.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
|
||
NSString *postalCodeText = CardIOLocalizedString(@"entry_postal_code", self.context.languageOrLocale); // Postal Code | ||
[postalCodeRow.labels addObject:postalCodeText]; | ||
|
||
self.postalCodeTextField = [postalCodeRow.textFields lastObject]; | ||
[self.visibleTextFields addObject:self.postalCodeTextField]; | ||
|
||
self.postalCodeRowTextFieldDelegate = [[CardIOPostalCodeTextFieldDelegate alloc] init]; | ||
self.postalCodeTextField.placeholder = postalCodeText; | ||
self.postalCodeTextField.delegate = self.postalCodeRowTextFieldDelegate; | ||
self.postalCodeTextField.text = self.cardInfo.postalCode; | ||
self.postalCodeTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; | ||
self.postalCodeTextField.clearButtonMode = UITextFieldViewModeNever; | ||
self.postalCodeTextField.text = @""; | ||
self.postalCodeTextField.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
self.postalCodeTextField.autocorrectionType = UITextAutocorrectionTypeNo; | ||
|
||
[rows addObject:postalCodeRow]; | ||
} | ||
} | ||
|
||
if(self.collectPostalCode) { | ||
CardIOMultipleFieldTableViewCell *postalCodeRow = [[CardIOMultipleFieldTableViewCell alloc] init]; | ||
postalCodeRow.backgroundColor = kColorDefaultCell; | ||
postalCodeRow.numberOfFields = 1; | ||
postalCodeRow.hiddenLabels = YES; | ||
postalCodeRow.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
|
||
NSString *postalCodeText = CardIOLocalizedString(@"entry_postal_code", self.context.languageOrLocale); // Postal Code | ||
[postalCodeRow.labels addObject:postalCodeText]; | ||
|
||
self.postalCodeTextField = [postalCodeRow.textFields lastObject]; | ||
[self.visibleTextFields addObject:self.postalCodeTextField]; | ||
|
||
self.postalCodeRowTextFieldDelegate = [[CardIOPostalCodeTextFieldDelegate alloc] init]; | ||
self.postalCodeTextField.placeholder = postalCodeText; | ||
self.postalCodeTextField.delegate = self.postalCodeRowTextFieldDelegate; | ||
self.postalCodeTextField.text = self.cardInfo.postalCode; | ||
self.postalCodeTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; | ||
self.postalCodeTextField.clearButtonMode = UITextFieldViewModeNever; | ||
self.postalCodeTextField.text = @""; | ||
self.postalCodeTextField.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
self.postalCodeTextField.autocorrectionType = UITextAutocorrectionTypeNo; | ||
|
||
[rows addObject:postalCodeRow]; | ||
} | ||
|
||
if(self.collectCardholderName) { | ||
CardIOMultipleFieldTableViewCell *cardholderNameRow = [[CardIOMultipleFieldTableViewCell alloc] init]; | ||
cardholderNameRow.backgroundColor = kColorDefaultCell; | ||
cardholderNameRow.numberOfFields = 1; | ||
cardholderNameRow.hiddenLabels = YES; | ||
cardholderNameRow.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
|
||
NSString *cardholderNameText = CardIOLocalizedString(@"entry_cardholder_name", self.context.languageOrLocale); // Cardholder Name | ||
[cardholderNameRow.labels addObject:cardholderNameText]; | ||
|
||
self.cardholderNameTextField = [cardholderNameRow.textFields lastObject]; | ||
[self.visibleTextFields addObject:self.cardholderNameTextField]; | ||
|
||
self.cardholderNameRowTextFieldDelegate = [[CardIOCardholderNameTextFieldDelegate alloc] init]; | ||
self.cardholderNameTextField.placeholder = cardholderNameText; | ||
self.cardholderNameTextField.delegate = self.cardholderNameRowTextFieldDelegate; | ||
self.cardholderNameTextField.text = self.cardInfo.cardholderName; | ||
self.cardholderNameTextField.keyboardType = UIKeyboardTypeNumbersAndPunctuation; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
self.cardholderNameTextField.clearButtonMode = UITextFieldViewModeNever; | ||
self.cardholderNameTextField.text = @""; | ||
self.cardholderNameTextField.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
self.cardholderNameTextField.autocorrectionType = UITextAutocorrectionTypeNo; | ||
|
||
[rows addObject:cardholderNameRow]; | ||
} | ||
|
||
CardIORowBasedTableViewSection *infoSection = [[CardIORowBasedTableViewSection alloc] init]; | ||
infoSection.rows = rows; | ||
|
@@ -408,13 +437,19 @@ - (void)viewDidAppear:(BOOL)animated { | |
selector:@selector(cvvDidChange:) | ||
name:UITextFieldTextDidChangeNotification | ||
object:self.cvvTextField]; | ||
} | ||
if(self.collectPostalCode) { | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(postalCodeDidChange:) | ||
name:UITextFieldTextDidChangeNotification | ||
object:self.postalCodeTextField]; | ||
} | ||
} | ||
if(self.collectPostalCode) { | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(postalCodeDidChange:) | ||
name:UITextFieldTextDidChangeNotification | ||
object:self.postalCodeTextField]; | ||
} | ||
if(self.collectCardholderName) { | ||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(cardholderNameDidChange:) | ||
name:UITextFieldTextDidChangeNotification | ||
object:self.cardholderNameTextField]; | ||
} | ||
|
||
[self layoutForCurrentOrientation]; | ||
|
||
|
@@ -542,13 +577,15 @@ - (void)viewDidUnload { | |
self.tableViewDelegate = nil; | ||
self.numberRowTextFieldDelegate = nil; | ||
self.expiryTextFieldDelegate = nil; | ||
self.cvvRowTextFieldDelegate = nil; | ||
self.postalCodeRowTextFieldDelegate = nil; | ||
self.cvvRowTextFieldDelegate = nil; | ||
self.postalCodeRowTextFieldDelegate = nil; | ||
self.cardholderNameRowTextFieldDelegate = nil; | ||
|
||
self.expiryTextField = nil; | ||
self.numberTextField = nil; | ||
self.cvvTextField = nil; | ||
self.postalCodeTextField = nil; | ||
self.cvvTextField = nil; | ||
self.postalCodeTextField = nil; | ||
self.cardholderNameTextField = nil; | ||
|
||
self.visibleTextFields = nil; | ||
|
||
|
@@ -769,8 +806,9 @@ - (void)done { | |
self.cardInfo.cardNumber = [CardIOCreditCardNumber stringByRemovingNonNumbers:self.numberTextField.text]; | ||
} | ||
|
||
self.cardInfo.cvv = self.cvvTextField.text; | ||
self.cardInfo.postalCode = [self.postalCodeTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
self.cardInfo.cvv = self.cvvTextField.text; | ||
self.cardInfo.postalCode = [self.postalCodeTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
self.cardInfo.cardholderName = self.cardholderNameTextField.text; | ||
|
||
CardIOPaymentViewController *pvc = (CardIOPaymentViewController *)self.navigationController; | ||
[pvc.paymentDelegate userDidProvideCreditCardInfo:self.cardInfo inPaymentViewController:pvc]; | ||
|
@@ -912,29 +950,46 @@ - (void)updateCvvColor { | |
} | ||
|
||
- (void)postalCodeDidChange:(id)sender { | ||
self.cardInfo.postalCode = [self.postalCodeTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
|
||
// For globalization, we can't be sure of a valid postalCode length. So for now we'll skip all of this. | ||
// | ||
// if([CardIOPostalCodeTextFieldDelegate isValidPostalCode:self.cardInfo.postalCode]) { | ||
// [self advanceToNextEmptyFieldFrom:self.postalCodeTextField]; | ||
// self.postalCodeTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
// } else if(self.postalCodeTextField.text.length >= 5) { | ||
// // probably won't reach this case, since length == 5 is the only validation rule, but we'll leave it here for consitency and for future enhancements. | ||
// self.postalCodeTextField.textColor = [UIColor redColor]; | ||
// } else { | ||
// self.postalCodeTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
// } | ||
self.cardInfo.postalCode = [self.postalCodeTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
|
||
// For globalization, we can't be sure of a valid postalCode length. So for now we'll skip all of this. | ||
// | ||
// if([CardIOPostalCodeTextFieldDelegate isValidPostalCode:self.cardInfo.postalCode]) { | ||
// [self advanceToNextEmptyFieldFrom:self.postalCodeTextField]; | ||
// self.postalCodeTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
// } else if(self.postalCodeTextField.text.length >= 5) { | ||
// // probably won't reach this case, since length == 5 is the only validation rule, but we'll leave it here for consitency and for future enhancements. | ||
// self.postalCodeTextField.textColor = [UIColor redColor]; | ||
// } else { | ||
// self.postalCodeTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
// } | ||
|
||
[self validate]; | ||
} | ||
|
||
[self validate]; | ||
- (void)cardholderNameDidChange:(id)sender { | ||
self.cardInfo.cardholderName = self.cardholderNameTextField.text; | ||
|
||
if([CardIOCardholderNameTextFieldDelegate isValidCardholderName:self.cardInfo.cardholderName]) { | ||
[self advanceToNextEmptyFieldFrom:self.cardholderNameTextField]; | ||
This comment has been minimized.
Sorry, something went wrong.
bluk
|
||
self.cardholderNameTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
} else if(self.cardholderNameTextField.text.length >= 175) { | ||
// probably won't reach this case, since length == 175 is the only validation rule, but we'll leave it here for consitency and for future enhancements. | ||
self.cardholderNameTextField.textColor = [UIColor redColor]; | ||
} else { | ||
self.cardholderNameTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
} | ||
|
||
[self validate]; | ||
} | ||
|
||
- (BOOL)validate { | ||
BOOL numberIsValid = !self.manualEntry || [CardIOCreditCardNumber isValidNumber:self.cardInfo.cardNumber]; | ||
BOOL expiryIsValid = !self.expiryTextField || [[self class] cardExpiryIsValid:self.cardInfo]; | ||
BOOL cvvIsValid = !self.cvvTextField || [CardIOCVVTextFieldDelegate isValidCVV:self.cardInfo.cvv forNumber:self.cardInfo.cardNumber]; | ||
BOOL postalCodeIsValid = !self.postalCodeTextField || [CardIOPostalCodeTextFieldDelegate isValidPostalCode:self.cardInfo.postalCode]; | ||
BOOL isValid = numberIsValid && expiryIsValid && cvvIsValid && postalCodeIsValid; | ||
BOOL cvvIsValid = !self.cvvTextField || [CardIOCVVTextFieldDelegate isValidCVV:self.cardInfo.cvv forNumber:self.cardInfo.cardNumber]; | ||
BOOL postalCodeIsValid = !self.postalCodeTextField || [CardIOPostalCodeTextFieldDelegate isValidPostalCode:self.cardInfo.postalCode]; | ||
BOOL cardholderNameIsValid = !self.cardholderNameTextField || [CardIOCardholderNameTextFieldDelegate isValidCardholderName:self.cardInfo.cardholderName]; | ||
BOOL isValid = numberIsValid && expiryIsValid && cvvIsValid && postalCodeIsValid && cardholderNameIsValid; | ||
self.navigationItem.rightBarButtonItem.enabled = isValid; | ||
|
||
return isValid; | ||
|
Oops, something went wrong.
I believe this should be
UIKeyboardTypeDefault
.