Class CardValidatorImpl
- java.lang.Object
-
- de.hybris.platform.payment.methods.impl.CardValidatorImpl
-
- All Implemented Interfaces:
CardValidator
public class CardValidatorImpl extends java.lang.Object implements CardValidator
-
-
Constructor Summary
Constructors Constructor Description CardValidatorImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CardValidationResultcheckCard(CardInfo cardInfo)Performs the complete suite of card validation, including the luhn check.java.util.List<CreditCardType>getSupportedCardSchemes()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(java.lang.Integer year, java.lang.Integer month, int currentYear, int currentMonth)protected booleanisBeforeCurrentYear(java.lang.Integer year, java.lang.Integer month, int currentYear, int currentMonth)booleanisCardSchemeSupported(CreditCardType cardScheme)Determines if the provided card scheme is supported by the system.protected booleanisExpired(CardInfo cardInfo)booleanisInternationalMaestro(java.lang.String cardNumber)Return whether the card number is an international Maestro card number.protected booleanisLuhnCheckCompliant(CardInfo cardInfo)protected booleanisValidDate(java.lang.Integer month, java.lang.Integer year, boolean expiryDate)booleanluhnCheck(java.lang.String number)Lifted from Wikipedia.voidsetCv2ExemptCardSchemes(java.util.List<CreditCardType> cv2ExemptCardSchemes)Sets a list of cards that do not require cv2 numbers.voidsetSupportedCardSchemes(java.util.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
-
-
-
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:
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
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 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
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.
-
getSupportedCardSchemes
public java.util.List<CreditCardType> getSupportedCardSchemes()
Description copied from interface:CardValidatorReturns the card schemes supported by the system.- Specified by:
getSupportedCardSchemesin interfaceCardValidator
-
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.
-
isCardSchemeSupported
public boolean isCardSchemeSupported(CreditCardType cardScheme)
Description copied from interface:CardValidatorDetermines if the provided card scheme is supported by the system.- Specified by:
isCardSchemeSupportedin interfaceCardValidator
-
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(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)
-
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: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
-
-