Class CardValidatorImpl

    • Constructor Detail

      • CardValidatorImpl

        public CardValidatorImpl()
    • Method Detail

      • luhnCheck

        public boolean luhnCheck​(java.lang.String number)
        Lifted from Wikipedia. Checks whether a string of digits is a valid credit card number according to the Luhn algorithm. 1. Starting with the second to last digit and moving left, double the value of all the alternating digits. For any digits that thus become 10 or more, add their digits together. For example, 1111 becomes 2121, while 8763 becomes 7733 (from (1+6)7(1+2)3). 2. Add all these digits together. For example, 1111 becomes 2121, then 2+1+2+1 is 6; while 8763 becomes 7733, then 7+7+3+3 is 20. 3. If the total ends in 0 (put another way, if the total modulus 10 is 0), then the number is valid according to the Luhn formula, else it is not valid. So, 1111 is not valid (as shown above, it comes out to 6), while 8763 is valid (as shown above, it comes out to 20).
        Specified by:
        luhnCheck in interface CardValidator
        Parameters:
        number - the credit card number to validate. If no credit card number is provided, false will be returned.
        Returns:
        true if the number is valid, false otherwise.
      • isInternationalMaestro

        public boolean isInternationalMaestro​(java.lang.String cardNumber)
        Return whether the card number is an international Maestro card number. Taken from information supplied by DataCash: http://www.barclaycardbusiness.co.uk/docs/binranges.pdf
      • inRange

        protected boolean inRange​(int num,
                                  int lower,
                                  int upper)
        Return whether a number is within a given range (inclusive)
        Parameters:
        num - The number to test
        lower - The low end of the range
        upper - The upper end of the range
        Returns:
        True if number is within lower and upper range (inclusive)
      • setSupportedCardSchemes

        public void setSupportedCardSchemes​(java.util.List<CreditCardType> supportedCardSchemes)
        Set all the card schemes that are supported by the site. This may be a reduced list from all known card schemes.
      • setCv2ExemptCardSchemes

        public void setCv2ExemptCardSchemes​(java.util.List<CreditCardType> cv2ExemptCardSchemes)
        Sets a list of cards that do not require cv2 numbers. By default all cards require cv2.
      • validateName

        protected void validateName​(CardValidationResult result,
                                    CardInfo cardInfo)
        Checks that the name consists of two separate names
      • validateCardScheme

        protected void validateCardScheme​(CardValidationResult result,
                                          CardInfo cardInfo)
        checks to see if the card scheme is supported for the given result with card scheme data. If it is not, an error is added to the result object.
        Parameters:
        result -
      • validateCardNumber

        protected void validateCardNumber​(CardValidationResult validationResult,
                                          CardInfo cardInfo)
        Implements basic card validation. i.e. has the luhn check passed and is the number a number.
      • isLuhnCheckCompliant

        protected boolean isLuhnCheckCompliant​(CardInfo cardInfo)
      • isExpired

        protected boolean isExpired​(CardInfo cardInfo)
      • hasExpirationDate

        protected boolean hasExpirationDate​(CardInfo cardInfo)
      • isValidDate

        protected boolean isValidDate​(java.lang.Integer month,
                                      java.lang.Integer year,
                                      boolean expiryDate)
      • isBeforeCurrentYear

        protected boolean isBeforeCurrentYear​(java.lang.Integer year,
                                              java.lang.Integer month,
                                              int currentYear,
                                              int currentMonth)
      • isAfterCurrentYear

        protected boolean isAfterCurrentYear​(java.lang.Integer year,
                                             java.lang.Integer month,
                                             int currentYear,
                                             int currentMonth)
      • checkCard

        public CardValidationResult checkCard​(CardInfo cardInfo)
        Description copied from interface: CardValidator
        Performs the complete suite of card validation, including the luhn check. The Card Validation process also discovers useful information about the card number, such as the card scheme, issuing country and bank. This is all returned in the card validation result.
        Specified by:
        checkCard in interface CardValidator