CardValidator
public class CardValidator : CardValidating
Provides utility functions to validate cards
-
Initializes a CardValidator object.
Declaration
Swift
public convenience init(environment: Environment)
-
Checks whether a given card number is valid and matches any of the supported schemes.
Declaration
Swift
public func validateCompleteness(cardNumber: String) -> Result<ValidationScheme, ValidationError.CardNumber>Parameters
cardNumberThe card number to validate.
Return Value
The card’s scheme if successful, else an error.
-
Declaration
Swift
public func validate(cardNumber: String) -> Result<Card.Scheme, ValidationError.CardNumber> -
Checks whether a given card number is at least a partial match for any of the supported schemes.
Declaration
Swift
public func eagerValidate(cardNumber: String) -> Result<Card.Scheme, ValidationError.EagerCardNumber>Parameters
cardNumberThe card number to validate.
Return Value
The card’s scheme if successful, else an error.
-
Checks whether the given expiry month and year are valid, if valid returns the values wrapped in an
ExpiryDateobject. TheexpiryMonthcan be 1 or 2 digits, and theexpiryYearcan be 2 or 4 digits.Declaration
Swift
public func validate( expiryMonth: String, expiryYear: String ) -> Result<ExpiryDate, ValidationError.ExpiryDate>Parameters
expiryMonthThe expiry month of the card.
expiryYearThe expiry year of the card.
Return Value
The card’s expiry date as an
ExpiryDateobject, else an error. -
Checks whether the given expiry month and year are valid, if valid returns the values wrapped in an
ExpiryDateobject. TheexpiryMonthcan be 1 or 2 digits, and theexpiryYearcan be 2 or 4 digits.Declaration
Swift
public func validate( expiryMonth: Int, expiryYear: Int ) -> Result<ExpiryDate, ValidationError.ExpiryDate>Parameters
expiryMonthThe expiry month of the card.
expiryYearThe expiry year of the card.
Return Value
The card’s expiry date as an
ExpiryDateobject, else an error. -
Checks whether a CVV is valid for a given card scheme. If the cardScheme is
unknown, this validates that the cvv is 3 or 4 digits.Declaration
Swift
public func validate( cvv: String, cardScheme: Card.Scheme = .unknown ) -> ValidationResult<ValidationError.CVV>Parameters
cvvThe CVV of the card.
cardSchemeThe scheme of the card.
Return Value
Whether the CVV is valid, else an error.
-
Checks whether a CVV is valid for a given card scheme. If the cardScheme is
unknown, this validates that the cvv is conforming to internal generic standardsDeclaration
Swift
public func isValid(cvv: String, for scheme: Card.Scheme) -> BoolParameters
cvvThe CVV of the card.
cardSchemeThe scheme of the card.
Return Value
True if CVV is valid, otherwise False
-
Checks what the maximum CVV length is for a given scaheme.
Declaration
Swift
public func maxLengthCVV(for scheme: Card.Scheme) -> IntParameters
schemeThe scheme against which the request is made
Return Value
The maximum length for input for it to be valid
-
Declaration
Swift
public func validate(_ card: Card) -> ValidationResult<ValidationError.Card>
View on GitHub
CardValidator