Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PaymentKit Example/PaymentKit Example-Prefix.pch";
INFOPLIST_FILE = "PaymentKit Example/PaymentKit Example-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "PaymentKit Example";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand All @@ -571,7 +571,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "PaymentKit Example/PaymentKit Example-Prefix.pch";
INFOPLIST_FILE = "PaymentKit Example/PaymentKit Example-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
PRODUCT_NAME = "PaymentKit Example";
TARGETED_DEVICE_FAMILY = 1;
WRAPPER_EXTENSION = app;
Expand Down
94 changes: 66 additions & 28 deletions PaymentKit/PKView.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,17 @@ - (void)setDefaultTextAttributes:(NSDictionary *)defaultTextAttributes

// We shouldn't need to set the font and textColor attributes, but a bug exists in 7.0 (fixed in 7.1/)

NSArray *textFields = @[_cardNumberField, _cardExpiryField, _cardCVCField, _cardLastFourField];
for (PKTextField *textField in textFields) {
textField.defaultTextAttributes = _defaultTextAttributes;
textField.font = _defaultTextAttributes[NSFontAttributeName];
textField.textColor = _defaultTextAttributes[NSForegroundColorAttributeName];
textField.textAlignment = NSTextAlignmentLeft;
}
if (_cardNumberField && _cardExpiryField && _cardLastFourField && _cardCVCField) {
NSArray *textFields = @[_cardNumberField, _cardExpiryField, _cardCVCField, _cardLastFourField];
for (PKTextField *textField in textFields) {
if ([textField respondsToSelector:@selector(defaultTextAttributes)]) {
textField.defaultTextAttributes = _defaultTextAttributes;
}
textField.font = _defaultTextAttributes[NSFontAttributeName];
textField.textColor = _defaultTextAttributes[NSForegroundColorAttributeName];
textField.textAlignment = NSTextAlignmentLeft;
}
}

_cardExpiryField.textAlignment = NSTextAlignmentCenter;
_cardCVCField.textAlignment = NSTextAlignmentCenter;
Expand Down Expand Up @@ -140,8 +144,12 @@ - (void)setup
self.innerView.clipsToBounds = YES;

_cardLastFourField = [UITextField new];
_cardLastFourField.defaultTextAttributes = _defaultTextAttributes;
if ([_cardLastFourField respondsToSelector:@selector(defaultTextAttributes)]) {
_cardLastFourField.defaultTextAttributes = _defaultTextAttributes;
}
_cardLastFourField.backgroundColor = self.backgroundColor;
_cardLastFourField.delegate = self;
_cardLastFourField.keyboardType = UIKeyboardTypeNumberPad;

[self setupCardNumberField];
[self setupCardExpiryField];
Expand Down Expand Up @@ -172,7 +180,9 @@ - (PKTextField *)textFieldWithPlaceholder:(NSString *)placeholder
textField.delegate = self;
textField.placeholder = placeholder;
textField.keyboardType = UIKeyboardTypeNumberPad;
textField.defaultTextAttributes = _defaultTextAttributes;
if ([textField respondsToSelector:@selector(defaultTextAttributes)]) {
textField.defaultTextAttributes = _defaultTextAttributes;
}
textField.layer.masksToBounds = NO;

return textField;
Expand Down Expand Up @@ -242,26 +252,52 @@ - (void)layoutSubviews

NSDictionary *attributes = self.defaultTextAttributes;

CGSize lastGroupSize, cvcSize, cardNumberSize;
CGSize lastGroupSize, cvcSize, cardNumberSize, expirySize;

if (self.cardNumber.cardType == PKCardTypeAmex) {
cardNumberSize = [@"1234 567890 12345" sizeWithAttributes:attributes];
lastGroupSize = [@"00000" sizeWithAttributes:attributes];
cvcSize = [@"0000" sizeWithAttributes:attributes];
}
else {
if (self.cardNumber.cardType == PKCardTypeDinersClub) {
cardNumberSize = [@"1234 567890 1234" sizeWithAttributes:attributes];
}
else {
cardNumberSize = [_cardNumberField.placeholder sizeWithAttributes:attributes];
}

lastGroupSize = [@"0000" sizeWithAttributes:attributes];
cvcSize = [_cardCVCField.placeholder sizeWithAttributes:attributes];
}
// Calculate size for iOS7
if ([@"" respondsToSelector:@selector(sizeWithAttributes:)]) {
if (self.cardNumber.cardType == PKCardTypeAmex) {
cardNumberSize = [@"1234 567890 12345" sizeWithAttributes:attributes];
lastGroupSize = [@"00000" sizeWithAttributes:attributes];
cvcSize = [@"0000" sizeWithAttributes:attributes];
}
else {
if (self.cardNumber.cardType == PKCardTypeDinersClub) {
cardNumberSize = [@"1234 567890 1234" sizeWithAttributes:attributes];
}
else {
cardNumberSize = [_cardNumberField.placeholder sizeWithAttributes:attributes];
}

lastGroupSize = [@"0000" sizeWithAttributes:attributes];
cvcSize = [_cardCVCField.placeholder sizeWithAttributes:attributes];
}

expirySize = [_cardExpiryField.placeholder sizeWithAttributes:attributes];
}

// Calculate size for iOS6
else {
if (self.cardNumber.cardType == PKCardTypeAmex) {
cardNumberSize = [@"1234 567890 12345" sizeWithFont:self.font];
lastGroupSize = [@"00000" sizeWithFont:self.font];
cvcSize = [@"0000" sizeWithFont:self.font];
}
else {
if (self.cardNumber.cardType == PKCardTypeDinersClub) {
cardNumberSize = [@"1234 567890 1234" sizeWithFont:self.font];
}
else {
cardNumberSize = [_cardNumberField.placeholder sizeWithFont:self.font];
}

lastGroupSize = [@"0000" sizeWithFont:self.font];
cvcSize = [_cardCVCField.placeholder sizeWithFont:self.font];
}

expirySize = [_cardExpiryField.placeholder sizeWithFont:self.font];
}

CGSize expirySize = [_cardExpiryField.placeholder sizeWithAttributes:attributes];

CGFloat textFieldY = (self.frame.size.height - lastGroupSize.height) / 2.0;

Expand Down Expand Up @@ -512,8 +548,9 @@ - (void)textFieldDidBeginEditing:(UITextField *)textField
[self setPlaceholderToCardType];
}

if ([textField isEqual:_cardNumberField] && !isInitialState) {
if ([textField isEqual:_cardLastFourField] && !isInitialState) {
[self stateCardNumber];
[_cardNumberField becomeFirstResponder];
}
}

Expand Down Expand Up @@ -549,6 +586,7 @@ - (BOOL)cardNumberFieldShouldChangeCharactersInRange:(NSRange)range replacementS
PKCardNumber *cardNumber = [PKCardNumber cardNumberWithString:resultString];

if (![cardNumber isPartiallyValid]) {
[self stateMeta];
return NO;
}

Expand Down