CardUtils

public class CardUtils

Payment Form Utilities

  • Create an instance of CardUtils

    Declaration

    Swift

    public init()

    Return Value

    The new CardUtils instance

  • Perform the lunh check algorithm to determine the validity of a card number Note: the card number must be without spaces

    Declaration

    Swift

    public func luhnCheck(cardNumber: String) -> Bool

    Parameters

    cardNumber

    Card number

    Return Value

    true if the card valid the lunh check algorithm, false otherwise

  • Get the type of the card based on the card number Note: the card number must be without spaces

    Declaration

    Swift

    public func getTypeOf(cardNumber: String) -> CardType?

    Parameters

    cardNumber

    Card number

    Return Value

    The card type corresponding to the card number, nil if no card type is found

  • Format the card number based on the card type e.g. Visa card: 4242 4242 4242 4242

    Declaration

    Swift

    public func format(cardNumber: String, cardType: CardType) -> String

    Parameters

    cardNumber

    Card number

    cardType

    Card type

    Return Value

    The formatted card number

  • Check if the card number is valid

    Declaration

    Swift

    public func isValid(cardNumber: String) -> Bool

    Parameters

    cardNumber

    Card number

    Return Value

    true if the card number is valid, false otherwise

  • Check if the card number is valid based on the card type

    Declaration

    Swift

    public func isValid(cardNumber: String, cardType: CardType) -> Bool

    Parameters

    cardNumber

    Card number

    cardType

    Card type

    Return Value

    true if the card number is valid, false otherwise

  • Check if the cvv is valid based on the card type

    Declaration

    Swift

    public func isValid(cvv: String, cardType: CardType) -> Bool

    Parameters

    cvv

    cvv (card verification value)

    cardType

    Card type

    Return Value

    true if the cvv is valid, false otherwise

  • Check if the expiration date is valid

    Declaration

    Swift

    public func isValid(expirationMonth: String, expirationYear: String) -> Bool

    Parameters

    expirationMonth

    Expiration month

    expirationYear

    Expiration year

    Return Value

    true if the expiration date is valid, false otherwise

  • Standardize the card number by removing non digits and spaces

    Declaration

    Swift

    public func standardize(cardNumber: String) -> String

    Parameters

    cardNumber

    Card Number

    Return Value

    The card number standardized.

  • Standardize the expiration date by removing non digits and spaces

    Declaration

    Swift

    public func standardize(expirationDate: String) -> (month: String, year: String)

    Parameters

    expirationDate

    Expiration Date (e.g. 05/2020)

    Return Value

    Expiry month and expiry year (month: 05, year: 21)

  • Get the card type object of a card scheme

    Declaration

    Swift

    public func getCardType(scheme: CardScheme) -> CardType?

    Parameters

    scheme

    Card scheme (e.g. Visa)

    Return Value

    The card type corresponding to the scheme, nil if no card type is found