-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cardholder name #1
Changes from all commits
0906c12
5da5c12
55d533f
1b59580
44690ff
bd65809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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 | ||
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. Should this be defined as a constant? 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. I agree that it should be a constant, but, again, this is strictly following their style (of not using constants). I think I'll do what Dan did, and after this branch gets merged, make another PR for Card.io that cleans up their code and implements constants. |
||
} | ||
return self; | ||
} | ||
|
||
+(BOOL)isValidCardholderName:(NSString*)cardholderName { | ||
return [cardholderName length] > 0; | ||
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. Where does it check for max length? |
||
} | ||
|
||
@end |
Large diffs are not rendered by default.
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; | ||
|
@@ -149,6 +151,7 @@ - (void)viewDidLoad { | |
self.collectExpiry = pvc.collectExpiry; | ||
self.collectCVV = pvc.collectCVV; | ||
self.collectPostalCode = pvc.collectPostalCode; | ||
self.collectCardholderName = pvc.collectCardholderName; | ||
|
||
self.scrollView = [[UIScrollView alloc] initWithFrame:self.relevantViewFrame]; | ||
|
||
|
@@ -318,6 +321,33 @@ - (void)viewDidLoad { | |
[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; | ||
self.cardholderNameTextField.clearButtonMode = UITextFieldViewModeNever; | ||
self.cardholderNameTextField.text = @""; | ||
self.cardholderNameTextField.textAlignment = [CardIOLocalizer textAlignmentForLanguageOrLocale:self.context.languageOrLocale]; | ||
self.cardholderNameTextField.autocorrectionType = UITextAutocorrectionTypeNo; | ||
self.cardholderNameTextField.autocapitalizationType = UITextAutocapitalizationTypeWords; | ||
|
||
[rows addObject:cardholderNameRow]; | ||
} | ||
|
||
CardIORowBasedTableViewSection *infoSection = [[CardIORowBasedTableViewSection alloc] init]; | ||
infoSection.rows = rows; | ||
[sections addObject:infoSection]; | ||
|
@@ -415,6 +445,12 @@ - (void)viewDidAppear:(BOOL)animated { | |
name:UITextFieldTextDidChangeNotification | ||
object:self.postalCodeTextField]; | ||
} | ||
if(self.collectCardholderName) { | ||
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.
|
||
[[NSNotificationCenter defaultCenter] addObserver:self | ||
selector:@selector(cardholderNameDidChange:) | ||
name:UITextFieldTextDidChangeNotification | ||
object:self.cardholderNameTextField]; | ||
} | ||
|
||
[self layoutForCurrentOrientation]; | ||
|
||
|
@@ -544,11 +580,13 @@ - (void)viewDidUnload { | |
self.expiryTextFieldDelegate = nil; | ||
self.cvvRowTextFieldDelegate = nil; | ||
self.postalCodeRowTextFieldDelegate = nil; | ||
self.cardholderNameRowTextFieldDelegate = nil; | ||
|
||
self.expiryTextField = nil; | ||
self.numberTextField = nil; | ||
self.cvvTextField = nil; | ||
self.postalCodeTextField = nil; | ||
self.cardholderNameTextField = nil; | ||
|
||
self.visibleTextFields = nil; | ||
|
||
|
@@ -771,6 +809,7 @@ - (void)done { | |
|
||
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]; | ||
|
@@ -929,12 +968,29 @@ - (void)postalCodeDidChange:(id)sender { | |
[self validate]; | ||
} | ||
|
||
- (void)cardholderNameDidChange:(id)sender { | ||
self.cardInfo.cardholderName = self.cardholderNameTextField.text; | ||
|
||
if([CardIOCardholderNameTextFieldDelegate isValidCardholderName:self.cardInfo.cardholderName]) { | ||
[self advanceToNextEmptyFieldFrom:self.cardholderNameTextField]; | ||
self.cardholderNameTextField.textColor = [CardIOTableViewCell defaultDetailTextLabelColorForCellStyle:[CardIOTableViewCell defaultCellStyle]]; | ||
} else if(self.cardholderNameTextField.text.length >= 175) { | ||
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. This 175 was also defined in 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. They define the max length for Expiry as 7 in both of the same places. I figured following their style was better than being potentially confusing with more organized code. |
||
// 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 cardholderNameIsValid = !self.cardholderNameTextField || [CardIOCardholderNameTextFieldDelegate isValidCardholderName:self.cardInfo.cardholderName]; | ||
BOOL isValid = numberIsValid && expiryIsValid && cvvIsValid && postalCodeIsValid && cardholderNameIsValid; | ||
self.navigationItem.rightBarButtonItem.enabled = isValid; | ||
|
||
return isValid; | ||
|
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.
The extra set of parentheses is not strictly required.
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.
That's their style on all of the other textFieldDelegate files.