Class CardValidatorImpl

java.lang.Object
de.hybris.platform.payment.methods.impl.CardValidatorImpl
All Implemented Interfaces:
CardValidator

public class CardValidatorImpl extends Object implements CardValidator
  • Field Details

    • CARD_NUMBER_FIRST_LOWER

      public static final int CARD_NUMBER_FIRST_LOWER
      See Also:
    • CARD_NUMBER_FIRST_UPPER

      public static final int CARD_NUMBER_FIRST_UPPER
      See Also:
    • CARD_NUMBER_SECOND_LOWER

      public static final int CARD_NUMBER_SECOND_LOWER
      See Also:
    • CARD_NUMBER_SECOND_UPPER

      public static final int CARD_NUMBER_SECOND_UPPER
      See Also:
    • CARD_NUMBER_THIRD_UPPER

      public static final int CARD_NUMBER_THIRD_UPPER
      See Also:
    • CARD_NUMBER_THIRD_LOWER

      public static final int CARD_NUMBER_THIRD_LOWER
      See Also:
    • CARD_NUMBER_FORTH_LOWER

      public static final int CARD_NUMBER_FORTH_LOWER
      See Also:
    • CARD_NUMBER_FORTH_UPPER

      public static final int CARD_NUMBER_FORTH_UPPER
      See Also:
    • CARD_NUMBER_FIFTH_LOWER

      public static final int CARD_NUMBER_FIFTH_LOWER
      See Also:
    • CARD_NUMBER_FIFTH_UPPER

      public static final int CARD_NUMBER_FIFTH_UPPER
      See Also:
  • Constructor Details

    • CardValidatorImpl

      public CardValidatorImpl()
  • Method Details

    • luhnCheck

      public boolean luhnCheck(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(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(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.
    • getSupportedCardSchemes

      public List<CreditCardType> getSupportedCardSchemes()
      Description copied from interface: CardValidator
      Returns the card schemes supported by the system.
      Specified by:
      getSupportedCardSchemes in interface CardValidator
    • setCv2ExemptCardSchemes

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

      public boolean isCardSchemeSupported(CreditCardType cardScheme)
      Description copied from interface: CardValidator
      Determines if the provided card scheme is supported by the system.
      Specified by:
      isCardSchemeSupported in interface CardValidator
    • 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)
    • validateDates

      protected void validateDates(CardValidationResult validationResult, CardInfo cardInfo)
    • isExpired

      protected boolean isExpired(CardInfo cardInfo)
    • hasExpirationDate

      protected boolean hasExpirationDate(CardInfo cardInfo)
    • isValidDate

      protected boolean isValidDate(Integer month, Integer year, boolean expiryDate)
    • isBeforeCurrentYear

      protected boolean isBeforeCurrentYear(Integer year, Integer month, int currentYear, int currentMonth)
    • isAfterCurrentYear

      protected boolean isAfterCurrentYear(Integer year, Integer month, int currentYear, int currentMonth)
    • validateCv2

      protected void validateCv2(CardValidationResult validationResult, CardInfo cardInfo, boolean isCv2AvsPolicyDisabled)
    • validateCv2Format

      protected void validateCv2Format(CardValidationResult validationResult, CardInfo cardInfo)
    • 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