com.ibm.etill.ldbcardcassette
Class LdbCardCassette.LuhnStringValidationItem

com.ibm.etill.ldbcardcassette.LdbCardCassette.LuhnStringValidationItem
Enclosing class:
LdbCardCassette

public static class LdbCardCassette.LuhnStringValidationItem

This class converts a parameter's value from a byte array into a string and then validates that the result passes the Luhn check.

Credit Card numbers are (most times) 13 to 16 digit numbers which are protected by a special numerical check, called Luhn check. From right to left, each digit is multiplied by the alternating factors 1 and 2 (the rightmost digit is always multiplied by 1). For each result, the digits are summed together. Then, these sums are totaled. Finally, to be a valid Credit Card number, the total must be evenly divisible by 10.

Example (Credit Card number: 1234 5678 7654 3210):

First, start from the right and multiply each digit by an alternating factor of 1 and 2. 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0 * * * * * * * * * * * * * * * * 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 = = = = = = = = = = = = = = = = 2 2 6 4 10 12 14 16 14 12 10 4 6 2 2 0

Sum the digits in the results. 2 2 6 4 (1+0) (1+2) (1+4) (1+6) (1+4) (1+2) (1+0) 4 6 2 2 0

Total the sums from above. 2 + 2 + 6 + 5 + 1 + 3 + 5 + 7 + 5 + 3 + 1 + 4 + 6 + 2 + 2 + 0 = 60

Divide the sum by 10 and if the remainder is 0 the value is valid. 60 % 10 = 0 so this number is valid.


Field Summary
private static int[] clsLuhnValue
          The Luhn value of a given digit depends on the alternating factor that is applied to the digit.
 
Constructor Summary
LdbCardCassette.LuhnStringValidationItem(java.lang.String argParameter, short argSecondaryReturnCode, boolean argNullValuesAllowed, int argMinLength, int argMaxLength)
          This constructor is used to create a Luhn String Validation item.
 
Method Summary
 java.lang.Object validateAndInsertValue(byte[] argValue, com.ibm.etill.framework.payapi.ParameterTable argResultTable)
          This method uses the parent's method to convert the byte array into a string and validate that the result is not too long or too short.
 

Field Detail

clsLuhnValue

private static final int[] clsLuhnValue
The Luhn value of a given digit depends on the alternating factor that is applied to the digit. The top half (first 10 values) in this array provides the Luhn value of the respective digit when the alternating factor is 1. The bottom half (last 10 values) in this array provides the Luhn value of the respective digit when the alternating factor is 2.
Constructor Detail

LdbCardCassette.LuhnStringValidationItem

public LdbCardCassette.LuhnStringValidationItem(java.lang.String argParameter,
                                                short argSecondaryReturnCode,
                                                boolean argNullValuesAllowed,
                                                int argMinLength,
                                                int argMaxLength)
This constructor is used to create a Luhn String Validation item.
Parameters:
argParameter - - the parameter keyword whose value is to be validated
argSecondaryReturnCode - - the secondary return code used to identify the parameter when it is invalid
argNullValuesAllowed - - a flag that specifies whether or not the parameter value can be null
argMinLength - - the minimum length of a valid string
argMaxLength - - the maximum length of a valid string
Method Detail

validateAndInsertValue

public java.lang.Object validateAndInsertValue(byte[] argValue,
                                               com.ibm.etill.framework.payapi.ParameterTable argResultTable)
                                        throws com.ibm.etill.framework.payapi.ETillAbortOperation
This method uses the parent's method to convert the byte array into a string and validate that the result is not too long or too short. Note that the parent's method will place the result into the parameter table if it does not detect an error. Then this method will continue the validation. It will make sure that each character is a digit and that it passes the Luhn test.
Parameters:
argValue - - the value passed by the merchant
argResultTable - - the parameter table to be passed to the cassette
Returns:
- a valid numeric string
Throws:
ETillAbortOperation - - any error results in this exception