CardValidator

public class CardValidator : CardValidating

Provides utility functions to validate cards

Public

  • 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

    cardNumber

    The 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

    cardNumber

    The 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 ExpiryDate object. The expiryMonth can be 1 or 2 digits, and the expiryYear can be 2 or 4 digits.

    Declaration

    Swift

    public func validate(
      expiryMonth: String,
      expiryYear: String
    ) -> Result<ExpiryDate, ValidationError.ExpiryDate>

    Parameters

    expiryMonth

    The expiry month of the card.

    expiryYear

    The expiry year of the card.

    Return Value

    The card’s expiry date as an ExpiryDate object, else an error.

  • Checks whether the given expiry month and year are valid, if valid returns the values wrapped in an ExpiryDate object. The expiryMonth can be 1 or 2 digits, and the expiryYear can be 2 or 4 digits.

    Declaration

    Swift

    public func validate(
      expiryMonth: Int,
      expiryYear: Int
    ) -> Result<ExpiryDate, ValidationError.ExpiryDate>

    Parameters

    expiryMonth

    The expiry month of the card.

    expiryYear

    The expiry year of the card.

    Return Value

    The card’s expiry date as an ExpiryDate object, 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

    cvv

    The CVV of the card.

    cardScheme

    The 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 standards

    Declaration

    Swift

    public func isValid(cvv: String, for scheme: Card.Scheme) -> Bool

    Parameters

    cvv

    The CVV of the card.

    cardScheme

    The 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) -> Int

    Parameters

    scheme

    The 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>