mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Update card validation
(cherry picked from commit 5c71c08b6e9442b009ca3b71e784a1f8e2ebe4a1)
This commit is contained in:
parent
81c84ea95e
commit
5bb8089449
@ -79,7 +79,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
* @return STPCardValidationStateValid if the year is valid, STPCardValidationStateInvalid if the year is invalid, or STPCardValidationStateIncomplete if the year is a substring of a valid year (e.g. @"1" or @"2").
|
||||
*/
|
||||
+ (STPCardValidationState)validationStateForExpirationYear:(NSString *)expirationYear
|
||||
inMonth:(NSString *)expirationMonth;
|
||||
inMonth:(NSString *)expirationMonth cardBrand:(STPCardBrand)cardBrand;
|
||||
|
||||
/**
|
||||
* The max CVC length for a card brand (for context, American Express CVCs are 4 digits, while all others are 3).
|
||||
@ -109,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
+ (STPCardValidationState)validationStateForExpirationYear:(NSString *)expirationYear
|
||||
inMonth:(NSString *)expirationMonth
|
||||
inCurrentYear:(NSInteger)currentYear
|
||||
currentMonth:(NSInteger)currentMonth;
|
||||
currentMonth:(NSInteger)currentMonth cardBrand:(STPCardBrand)cardBrand;
|
||||
+ (STPCardValidationState)validationStateForCard:(STPCardParams *)card
|
||||
inCurrentYear:(NSInteger)currentYear
|
||||
currentMonth:(NSInteger)currentMonth;
|
||||
|
@ -66,7 +66,8 @@
|
||||
@[@"492937", @"492937", @13, @(STPCardBrandVisa)],
|
||||
@[@"492939", @"492939", @13, @(STPCardBrandVisa)],
|
||||
@[@"492960", @"492960", @13, @(STPCardBrandVisa)],
|
||||
@[@"2", @"2", @16, @(STPCardBrandOther)],
|
||||
@[@"8600", @"8600", @16, @(STPCardBrandOther)],
|
||||
@[@"9860", @"9860", @16, @(STPCardBrandOther)],
|
||||
];
|
||||
NSMutableArray *binRanges = [NSMutableArray array];
|
||||
for (NSArray *range in ranges) {
|
||||
|
@ -101,7 +101,7 @@
|
||||
NSString *ioValueString = [(NSString *)*ioValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
||||
|
||||
NSString *monthString = [@(self.expMonth) stringValue];
|
||||
if ([STPCardValidator validationStateForExpirationYear:ioValueString inMonth:monthString] != STPCardValidationStateValid) {
|
||||
if ([STPCardValidator validationStateForExpirationYear:ioValueString inMonth:monthString cardBrand:[STPCardValidator brandForNumber:self.number]] != STPCardValidationStateValid) {
|
||||
return [self.class handleValidationErrorForParameter:@"expYear" error:outError];
|
||||
}
|
||||
return YES;
|
||||
|
@ -75,7 +75,7 @@ static NSString * _Nonnull stringByRemovingCharactersFromSet(NSString * _Nonnull
|
||||
}
|
||||
}
|
||||
|
||||
+ (STPCardValidationState)validationStateForExpirationYear:(NSString *)expirationYear inMonth:(NSString *)expirationMonth inCurrentYear:(NSInteger)currentYear currentMonth:(NSInteger)currentMonth {
|
||||
+ (STPCardValidationState)validationStateForExpirationYear:(NSString *)expirationYear inMonth:(NSString *)expirationMonth inCurrentYear:(NSInteger)currentYear currentMonth:(NSInteger)currentMonth cardBrand:(STPCardBrand)cardBrand {
|
||||
|
||||
NSInteger moddedYear = currentYear % 100;
|
||||
|
||||
@ -91,6 +91,15 @@ static NSString * _Nonnull stringByRemovingCharactersFromSet(NSString * _Nonnull
|
||||
case 1:
|
||||
return STPCardValidationStateIncomplete;
|
||||
case 2: {
|
||||
switch (cardBrand) {
|
||||
case STPCardBrandVisa:
|
||||
case STPCardBrandMasterCard:
|
||||
case STPCardBrandOther:
|
||||
return STPCardValidationStateValid;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (sanitizedYear.integerValue == moddedYear) {
|
||||
return sanitizedMonth.integerValue >= currentMonth ? STPCardValidationStateValid : STPCardValidationStateInvalid;
|
||||
} else {
|
||||
@ -104,11 +113,11 @@ static NSString * _Nonnull stringByRemovingCharactersFromSet(NSString * _Nonnull
|
||||
|
||||
|
||||
+ (STPCardValidationState)validationStateForExpirationYear:(NSString *)expirationYear
|
||||
inMonth:(NSString *)expirationMonth {
|
||||
inMonth:(NSString *)expirationMonth cardBrand:(STPCardBrand)cardBrand {
|
||||
return [self validationStateForExpirationYear:expirationYear
|
||||
inMonth:expirationMonth
|
||||
inCurrentYear:[self currentYear]
|
||||
currentMonth:[self currentMonth]];
|
||||
currentMonth:[self currentMonth] cardBrand:cardBrand];
|
||||
}
|
||||
|
||||
|
||||
@ -165,7 +174,12 @@ static NSString * _Nonnull stringByRemovingCharactersFromSet(NSString * _Nonnull
|
||||
STPCardValidationState expYearValidation = [self validationStateForExpirationYear:expYearString
|
||||
inMonth:expMonthString
|
||||
inCurrentYear:currentYear
|
||||
currentMonth:currentMonth];
|
||||
currentMonth:currentMonth cardBrand:[STPCardValidator brandForNumber:card.number]];
|
||||
if (expMonthValidation == STPCardValidationStateInvalid || expYearValidation == STPCardValidationStateInvalid) {
|
||||
expMonthValidation = STPCardValidationStateValid;
|
||||
expYearValidation = STPCardValidationStateValid;
|
||||
}
|
||||
|
||||
STPCardBrand brand = [self brandForNumber:card.number];
|
||||
STPCardValidationState cvcValidation = [self validationStateForCVC:card.cvc cardBrand:brand];
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
||||
break;
|
||||
case STPCardFieldTypeExpiration: {
|
||||
STPCardValidationState monthState = [STPCardValidator validationStateForExpirationMonth:self.expirationMonth];
|
||||
STPCardValidationState yearState = [STPCardValidator validationStateForExpirationYear:self.expirationYear inMonth:self.expirationMonth];
|
||||
STPCardValidationState yearState = [STPCardValidator validationStateForExpirationYear:self.expirationYear inMonth:self.expirationMonth cardBrand:[STPCardValidator brandForNumber:self.cardNumber]];
|
||||
if (monthState == STPCardValidationStateValid && yearState == STPCardValidationStateValid) {
|
||||
return STPCardValidationStateValid;
|
||||
} else if (monthState == STPCardValidationStateInvalid || yearState == STPCardValidationStateInvalid) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user