Class CardValidatorImpl
java.lang.Object
de.hybris.platform.payment.methods.impl.CardValidatorImpl
- All Implemented Interfaces:
CardValidator
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionPerforms the complete suite of card validation, including the luhn check.Returns the card schemes supported by the system.protected booleanhasExpirationDate(CardInfo cardInfo) protected booleaninRange(int num, int lower, int upper) Return whether a number is within a given range (inclusive)protected booleanisAfterCurrentYear(Integer year, Integer month, int currentYear, int currentMonth) protected booleanisBeforeCurrentYear(Integer year, Integer month, int currentYear, int currentMonth) booleanisCardSchemeSupported(CreditCardType cardScheme) Determines if the provided card scheme is supported by the system.protected booleanbooleanisInternationalMaestro(String cardNumber) Return whether the card number is an international Maestro card number.protected booleanisLuhnCheckCompliant(CardInfo cardInfo) protected booleanisValidDate(Integer month, Integer year, boolean expiryDate) booleanLifted from Wikipedia.voidsetCv2ExemptCardSchemes(List<CreditCardType> cv2ExemptCardSchemes) Sets a list of cards that do not require cv2 numbers.voidsetSupportedCardSchemes(List<CreditCardType> supportedCardSchemes) Set all the card schemes that are supported by the site.protected voidvalidateCardNumber(CardValidationResult validationResult, CardInfo cardInfo) Implements basic card validation.protected voidvalidateCardScheme(CardValidationResult result, CardInfo cardInfo) checks to see if the card scheme is supported for the given result with card scheme data.protected voidvalidateCv2(CardValidationResult validationResult, CardInfo cardInfo, boolean isCv2AvsPolicyDisabled) protected voidvalidateCv2Format(CardValidationResult validationResult, CardInfo cardInfo) protected voidvalidateDates(CardValidationResult validationResult, CardInfo cardInfo) protected voidvalidateName(CardValidationResult result, CardInfo cardInfo) Checks that the name consists of two separate names
-
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
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:
luhnCheckin interfaceCardValidator- 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
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 testlower- The low end of the rangeupper- The upper end of the range- Returns:
- True if number is within lower and upper range (inclusive)
-
setSupportedCardSchemes
Set all the card schemes that are supported by the site. This may be a reduced list from all known card schemes. -
getSupportedCardSchemes
Description copied from interface:CardValidatorReturns the card schemes supported by the system.- Specified by:
getSupportedCardSchemesin interfaceCardValidator
-
setCv2ExemptCardSchemes
Sets a list of cards that do not require cv2 numbers. By default all cards require cv2. -
isCardSchemeSupported
Description copied from interface:CardValidatorDetermines if the provided card scheme is supported by the system.- Specified by:
isCardSchemeSupportedin interfaceCardValidator
-
validateName
Checks that the name consists of two separate names -
validateCardScheme
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
Implements basic card validation. i.e. has the luhn check passed and is the number a number. -
isLuhnCheckCompliant
-
validateDates
-
isExpired
-
hasExpirationDate
-
isValidDate
-
isBeforeCurrentYear
-
isAfterCurrentYear
-
validateCv2
protected void validateCv2(CardValidationResult validationResult, CardInfo cardInfo, boolean isCv2AvsPolicyDisabled) -
validateCv2Format
-
checkCard
Description copied from interface:CardValidatorPerforms 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:
checkCardin interfaceCardValidator
-