diff --git a/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardExpirationDetector.swift b/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardExpirationDetector.swift index 72b282de..d020e009 100644 --- a/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardExpirationDetector.swift +++ b/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardExpirationDetector.swift @@ -20,7 +20,8 @@ struct CardExpirationDetector: CardAttributeDetector { guard let regex = regexProvider.regex(with: "(0[1-9]|1[0-2])[.\\/](\\d{4}|\\d{2})") else { return nil } - for (offset, candidate) in candidates.enumerated() { + var matchedExpiration: POScannedCard.Expiration? + for (offset, candidate) in candidates.enumerated().reversed() { let candidate = candidate.removingCharacters(in: .whitespacesAndNewlines) let range = NSRange(candidate.startIndex..., in: candidate) guard let match = regex.firstMatch(in: candidate, range: range) else { @@ -36,9 +37,9 @@ struct CardExpirationDetector: CardAttributeDetector { continue } let description = formatter.string(from: String(month) + String(year % 100)) - return .init(month: month, year: year, description: description) + matchedExpiration = .init(month: month, year: year, description: description) } - return nil + return matchedExpiration } // MARK: - Private Properties diff --git a/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardholderNameDetector.swift b/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardholderNameDetector.swift index 391fc7ec..f864ec0a 100644 --- a/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardholderNameDetector.swift +++ b/Sources/ProcessOutUI/Sources/Modules/CardScanner/AttributeDetector/Detectors/CardholderNameDetector.swift @@ -58,8 +58,7 @@ struct CardholderNameDetector: CardAttributeDetector { } private func areSimilar(string: String, and secondString: String) -> Bool { - let differencesCount = string.difference(from: secondString).count - return differencesCount <= 1 + string == secondString // Check for exact match to avoid potential false negatives, e.g. Visa <-> Lisa } }