atg.payment.creditcard
Class CreditCardTools

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.payment.creditcard.CreditCardTools
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener

public class CreditCardTools
extends GenericService

This class contains methods which contain functionality useful in dealing with credit cards.


Field Summary
static int CARD_EXP_DATE_NOT_VALID
           
static int CARD_EXPIRED
           
static int CARD_INFO_NOT_VALID
           
static int CARD_LENGTH_NOT_VALID
           
static int CARD_NUMBER_DOESNT_MATCH_TYPE
           
static int CARD_NUMBER_HAS_INVALID_CHARS
           
static int CARD_NUMBER_NOT_VALID
           
static int CARD_TYPE_NOT_VALID
           
static java.lang.String CLASS_VERSION
          Class version string
static int SUCCESS
           
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
CreditCardTools()
           
 
Method Summary
protected static java.lang.String Code(java.lang.String iName)
          Get a code, given a name
 java.util.Properties getCardCodesMap()
           
 java.util.Properties getCardLengthsMap()
           
 java.util.Properties getCardPrefixesMap()
           
 java.util.Properties getCardTypesMap()
           
 atg.payment.creditcard.ExtendableCreditCardTools getCreditCardTools()
           
static java.lang.String getStatusCodeMessage(int pCode)
          This method returns an error string which maps to the supplied status code.
static java.lang.String getStatusCodeMessage(int pCode, java.util.Locale pLocale)
          This method returns an error string which maps to the supplied status code.
protected static boolean isNumber(java.lang.String pNumber)
          Check to see if this is a number
protected static boolean isValidCardNumberLength(java.lang.String iTypeName, java.lang.String iNumber)
          Check the length of a credit card number against it's card type.
protected static boolean isValidCardType(java.lang.String iTypeName, java.lang.String iNumber)
          Check a credit card number against it's card type.
protected static java.lang.String Name(java.lang.String iCode)
          Get a name, given a code
 void setCardCodesMap(java.util.Properties pCardCodesMap)
           
 void setCardLengthsMap(java.util.Properties pCardLengthsMap)
           
 void setCardPrefixesMap(java.util.Properties pCardPrefixesMap)
           
 void setCardTypesMap(java.util.Properties pCardTypesMap)
           
 void setCreditCardTools(atg.payment.creditcard.ExtendableCreditCardTools pCreditCardTools)
           
protected static boolean validateCheckDigit(java.lang.String iNumber)
          Validate a credit card number's checksum.
static int verifyCreditCard(CreditCardInfo pCreditCard)
          This method does basic credit card verification, such as comparing the expiration date to the current date and verifying that the credit card number conforms to simple algorithm.
protected static int verifyCreditCard(CreditCardInfo pCreditCard, java.lang.String number, java.lang.String type)
           
protected static int verifyCreditCardDate(CreditCardInfo pCreditCard, java.lang.String pExpMonth, java.lang.String pExpDayOfMonth, java.lang.String pExpYear)
           
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string


SUCCESS

public static final int SUCCESS
See Also:
Constant Field Values

CARD_EXPIRED

public static final int CARD_EXPIRED
See Also:
Constant Field Values

CARD_NUMBER_HAS_INVALID_CHARS

public static final int CARD_NUMBER_HAS_INVALID_CHARS
See Also:
Constant Field Values

CARD_NUMBER_DOESNT_MATCH_TYPE

public static final int CARD_NUMBER_DOESNT_MATCH_TYPE
See Also:
Constant Field Values

CARD_LENGTH_NOT_VALID

public static final int CARD_LENGTH_NOT_VALID
See Also:
Constant Field Values

CARD_NUMBER_NOT_VALID

public static final int CARD_NUMBER_NOT_VALID
See Also:
Constant Field Values

CARD_INFO_NOT_VALID

public static final int CARD_INFO_NOT_VALID
See Also:
Constant Field Values

CARD_EXP_DATE_NOT_VALID

public static final int CARD_EXP_DATE_NOT_VALID
See Also:
Constant Field Values

CARD_TYPE_NOT_VALID

public static final int CARD_TYPE_NOT_VALID
See Also:
Constant Field Values
Constructor Detail

CreditCardTools

public CreditCardTools()
Method Detail

getCreditCardTools

public atg.payment.creditcard.ExtendableCreditCardTools getCreditCardTools()

setCreditCardTools

public void setCreditCardTools(atg.payment.creditcard.ExtendableCreditCardTools pCreditCardTools)

getCardTypesMap

public java.util.Properties getCardTypesMap()

setCardTypesMap

public void setCardTypesMap(java.util.Properties pCardTypesMap)

getCardCodesMap

public java.util.Properties getCardCodesMap()

setCardCodesMap

public void setCardCodesMap(java.util.Properties pCardCodesMap)

getCardPrefixesMap

public java.util.Properties getCardPrefixesMap()

setCardPrefixesMap

public void setCardPrefixesMap(java.util.Properties pCardPrefixesMap)

getCardLengthsMap

public java.util.Properties getCardLengthsMap()

setCardLengthsMap

public void setCardLengthsMap(java.util.Properties pCardLengthsMap)

getStatusCodeMessage

public static java.lang.String getStatusCodeMessage(int pCode)
This method returns an error string which maps to the supplied status code. The default locale is used for loading the message.

Parameters:
pCode - the status code returned from a method in this class
Returns:
an error string which maps to the status code supplied

getStatusCodeMessage

public static java.lang.String getStatusCodeMessage(int pCode,
                                                    java.util.Locale pLocale)
This method returns an error string which maps to the supplied status code. The supplied Locale is used for loading the message.

Parameters:
pCode - the status code returned from a method in this class
Returns:
an error string which maps to the status code supplied

verifyCreditCard

public static int verifyCreditCard(CreditCardInfo pCreditCard)
This method does basic credit card verification, such as comparing the expiration date to the current date and verifying that the credit card number conforms to simple algorithm.

Parameters:
pCreditCard - the credit card data
Returns:
a status code

verifyCreditCardDate

protected static int verifyCreditCardDate(CreditCardInfo pCreditCard,
                                          java.lang.String pExpMonth,
                                          java.lang.String pExpDayOfMonth,
                                          java.lang.String pExpYear)

verifyCreditCard

protected static int verifyCreditCard(CreditCardInfo pCreditCard,
                                      java.lang.String number,
                                      java.lang.String type)

validateCheckDigit

protected static boolean validateCheckDigit(java.lang.String iNumber)
Validate a credit card number's checksum. This is kinda neat. The last digit of all credit cards is acutally a "check digit", and can be determined by performing a checksum on all the digits that precede it. The checksum is referred to in the credit card industry as a "MOD 10 check digit routine".

Each digit,except the last is multipled by a "weight", to produce a digit "value". The weight alternates between 2 and 1, starting with 2 for the last (right most) digit. The resulting values are summed. To sum the results, single digit values are simply added to the total. For two digit values the tens and the ones digits are added separately, so 14 = 1+4 = 5. Then to test the check digit take the total MOD 10 and subtract it from ten. This should equal the check digit.


isNumber

protected static boolean isNumber(java.lang.String pNumber)
Check to see if this is a number


Code

protected static java.lang.String Code(java.lang.String iName)
Get a code, given a name

Parameters:
iName - credit card type name

Name

protected static java.lang.String Name(java.lang.String iCode)
Get a name, given a code

Parameters:
iCode - two letter credit card type code

isValidCardType

protected static boolean isValidCardType(java.lang.String iTypeName,
                                         java.lang.String iNumber)
Check a credit card number against it's card type. Different types of cards have different allowable prefixes in their numbers. This check currently allows a few Type II errors, but can never havea Type I error, i.e. we can let a few bougs numbers slip by (cuz they'll get caught later), but we cannot reject any valid numbers.

Parameters:
iTypeName - full name of card type (Visa, MasterCard)
iNumber - normalized card number

isValidCardNumberLength

protected static boolean isValidCardNumberLength(java.lang.String iTypeName,
                                                 java.lang.String iNumber)
Check the length of a credit card number against it's card type. Different types of cards have different allowable lengths. Actually all of them have exactly one allowable length, except for Visa cards, which can either be 13 or 16 digits.

Parameters:
iTypeName - full name of card type (Visa, MasterCard)
iNumber - normalized card number