fix(payment): validate card expiry date month range and fix PaymentCardView character length
This commit is contained in:
@@ -1116,10 +1116,18 @@ struct PaymentCardView: View {
|
||||
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
|
||||
}
|
||||
|
||||
private func validateExpiryDate(digits: Int) -> Bool {
|
||||
let clean = expiry.filter(\.isNumber)
|
||||
guard clean.count == digits else { return false }
|
||||
let monthStr = String(clean.prefix(2))
|
||||
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
var canSubmit: Bool {
|
||||
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
|
||||
cardNumber.filter(\.isNumber).count >= 13 &&
|
||||
expiry.filter(\.isNumber).count == 6 &&
|
||||
validateExpiryDate(digits: 4) &&
|
||||
cvv.filter(\.isNumber).count >= 3 &&
|
||||
cpf.filter(\.isNumber).count == 11
|
||||
}
|
||||
@@ -1665,10 +1673,18 @@ struct ChangePaymentNewCardView: View {
|
||||
_cpf = State(initialValue: appState.wrappedValue.profile.cpf)
|
||||
}
|
||||
|
||||
private func validateExpiryDate(digits: Int) -> Bool {
|
||||
let clean = expiry.filter(\.isNumber)
|
||||
guard clean.count == digits else { return false }
|
||||
let monthStr = String(clean.prefix(2))
|
||||
guard let month = Int(monthStr), (1...12).contains(month) else { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
var canSubmit: Bool {
|
||||
holderName.trimmingCharacters(in: .whitespaces).isEmpty == false &&
|
||||
cardNumber.filter(\.isNumber).count >= 13 &&
|
||||
expiry.filter(\.isNumber).count == 6 &&
|
||||
validateExpiryDate(digits: 6) &&
|
||||
cvv.filter(\.isNumber).count >= 3 &&
|
||||
cpf.filter(\.isNumber).count == 11
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user