Skip to content

Commit

Permalink
Merge pull request #307 from omise/release-5.3.0
Browse files Browse the repository at this point in the history
Release 5.3.0
  • Loading branch information
AnasNaouchi authored Nov 18, 2024
2 parents 1348ca1 + 70cfd53 commit dbd2247
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 20 deletions.
6 changes: 3 additions & 3 deletions OmiseSDK/Resources/Assets.xcassets/Credit Card/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images": [
{
"filename": "Discover.pdf",
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images": [
{
"filename": "UnionPay.pdf",
"idiom": "universal"
}
],
"info": {
"author": "xcode",
"version": 1
}
}
Binary file not shown.
13 changes: 10 additions & 3 deletions OmiseSDK/Sources/Models/CardBrand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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.
Expand All @@ -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})$"
}
}

Expand All @@ -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
}
}

Expand Down
12 changes: 1 addition & 11 deletions OmiseSDK/Sources/Models/PAN.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion OmiseSDK/Sources/OmiseSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class OmiseSDK {
public static var shared = OmiseSDK(publicKey: "pkey_")

/// OmiseSDK version
public let version: String = "5.2.1"
public let version: String = "5.3.0"

/// Public Key associated with this instance of OmiseSDK
public let publicKey: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ class CreditCardPaymentController: UIViewController {
cardBrandIconName = "AMEX"
case .diners?:
cardBrandIconName = "Diners"
case .unionPay:
cardBrandIconName = "UnionPay"
case .discover?:
cardBrandIconName = "Discover"
default:
cardBrandIconName = nil
}
Expand Down

0 comments on commit dbd2247

Please sign in to comment.