diff --git a/OmiseSDK/Resources/Assets.xcassets/Credit Card/Contents.json b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Contents.json index da4a164c..73c00596 100644 --- a/OmiseSDK/Resources/Assets.xcassets/Credit Card/Contents.json +++ b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Contents.json b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Contents.json new file mode 100644 index 00000000..312e77d2 --- /dev/null +++ b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images": [ + { + "filename": "Discover.pdf", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Discover.pdf b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Discover.pdf new file mode 100644 index 00000000..2e1fba7d Binary files /dev/null and b/OmiseSDK/Resources/Assets.xcassets/Credit Card/Discover.imageset/Discover.pdf differ diff --git a/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/Contents.json b/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/Contents.json new file mode 100644 index 00000000..36ddf0ef --- /dev/null +++ b/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/Contents.json @@ -0,0 +1,12 @@ +{ + "images": [ + { + "filename": "UnionPay.pdf", + "idiom": "universal" + } + ], + "info": { + "author": "xcode", + "version": 1 + } +} diff --git a/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/UnionPay.pdf b/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/UnionPay.pdf new file mode 100644 index 00000000..17601956 Binary files /dev/null and b/OmiseSDK/Resources/Assets.xcassets/Credit Card/UnionPay.imageset/UnionPay.pdf differ diff --git a/OmiseSDK/Sources/Models/CardBrand.swift b/OmiseSDK/Sources/Models/CardBrand.swift index a2e873f8..2b074f5c 100644 --- a/OmiseSDK/Sources/Models/CardBrand.swift +++ b/OmiseSDK/Sources/Models/CardBrand.swift @@ -17,6 +17,8 @@ public enum CardBrand: String, CustomStringConvertible, Codable { case laser = "Laser" /// Maestro card newtwork brand case maestro = "Maestro" + /// UnionPay card network brand + case unionPay = "UnionPay" /// Discover card newtwork brand case discover = "Discover" @@ -28,7 +30,8 @@ public enum CardBrand: String, CustomStringConvertible, Codable { diners, laser, maestro, - discover + discover, + unionPay ] /// Regular expression pattern that can detect cards issued by the brand. @@ -48,8 +51,10 @@ public enum CardBrand: String, CustomStringConvertible, Codable { return "^(6304|670[69]|6771)" case .maestro: return "^(5[0,6-8]|6304|6759|676[1-3])" + case .unionPay: + return "^62\\d{14,17}$" case .discover: - return "^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)" + return "^(6011\\d{12,15}|65\\d{14,17}|64[4-9]\\d{13,16}|6221[2-9]\\d{11,14}|622[3-9]\\d{12,15})$" } } @@ -70,8 +75,10 @@ public enum CardBrand: String, CustomStringConvertible, Codable { return 16...19 case .maestro: return 12...19 + case .unionPay: + return 16...19 case .discover: - return 16...16 + return 16...19 } } diff --git a/OmiseSDK/Sources/Models/PAN.swift b/OmiseSDK/Sources/Models/PAN.swift index 568098a5..958e7a86 100644 --- a/OmiseSDK/Sources/Models/PAN.swift +++ b/OmiseSDK/Sources/Models/PAN.swift @@ -39,17 +39,7 @@ public struct PAN { /// The suggested of where the space should be displayed string indexes public var suggestedSpaceFormattedIndexes: IndexSet { - switch self { - case CardBrand.amex.pattern, "^5[6-8]": - return [ 4, 10 ] - case "^50": - return [ 4, 8 ] - case "^3[0,6,8-9]": - return [ 4, 10 ] - case "^[0-9]": - return [ 4, 8, 12 ] - default: return [] - } + return IndexSet(stride(from: 4, to: 19, by: 4)) } /// The last 4 digits of the PAN number diff --git a/OmiseSDK/Sources/Views/Components/TextFields/CardNumberTextField.swift b/OmiseSDK/Sources/Views/Components/TextFields/CardNumberTextField.swift index 82cec6e4..1498c235 100644 --- a/OmiseSDK/Sources/Views/Components/TextFields/CardNumberTextField.swift +++ b/OmiseSDK/Sources/Views/Components/TextFields/CardNumberTextField.swift @@ -119,7 +119,9 @@ public class CardNumberTextField: OmiseTextField { options: .regularExpression, range: nil) - let panLength = (self.pan.brand?.validLengths.upperBound ?? 16) - (self.text?.count ?? 0) + selectedTextLength + // Using the current detected upper bound for the current brand will cause problems when swtching from + // a brand that has an upper bound that is lower than that of the pasted detected card. (ex from visa to discover). So the upper bound will be set to the highest upper bound available for cards which is 19 + let panLength = 19 - (self.text?.count ?? 0) + selectedTextLength let maxPastingPANLength = min(pan.count, panLength) guard maxPastingPANLength > 0 else { return @@ -306,7 +308,7 @@ extension CardNumberTextField { guard range.length >= 0 else { return true } - let maxLength = (pan.brand?.validLengths.upperBound ?? 16) + let maxLength = (pan.brand?.validLengths.upperBound ?? 19) return maxLength >= (self.text?.count ?? 0) - range.length + string.count } diff --git a/OmiseSDK/Sources/Views/Screens/Credit Card Payment/CreditCardPaymentController.swift b/OmiseSDK/Sources/Views/Screens/Credit Card Payment/CreditCardPaymentController.swift index fab1dcbb..81e62894 100644 --- a/OmiseSDK/Sources/Views/Screens/Credit Card Payment/CreditCardPaymentController.swift +++ b/OmiseSDK/Sources/Views/Screens/Credit Card Payment/CreditCardPaymentController.swift @@ -547,6 +547,10 @@ class CreditCardPaymentController: UIViewController { cardBrandIconName = "AMEX" case .diners?: cardBrandIconName = "Diners" + case .unionPay: + cardBrandIconName = "UnionPay" + case .discover?: + cardBrandIconName = "Discover" default: cardBrandIconName = nil }