|
CreditCardPack | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.keyoti.creditCard.logic.CardType
Represents a credit card type (eg; Visa, AMEX, etc).
Overview
CardType objects can check that a card number agrees with a card type
as defined by ISO/IEC 7812-1:1993 & ANSI X4.13.
This is possible because each industry card type has two properties - card number length and card number pattern.
For example, Visa card numbers can be either 13 or 16 digits long and the first 6 digits (the IIN) must be 4xxxxx where "x"
is a wildcard.
Preset card types
This Class comes with several preset card types (see the static fields).
These can be accessed using a static field identifier
in the constructor,
eg; new CardType(CardType.AMERICAN_EXPRESS);
Non-preset card types
To create card types that haven't been included in this Class, or to amend ones that have with
changes to the card issuers IIN (Industry Identifier Number) information, simply instantiate a new CardType object with
the relevant data;
eg; new CardType("New Card Name", idPatterns, numberLengths);
Where idPatterns is an array of Strings containing the valid patterns for the card type. Eg; MasterCard cards have
card numbers that follow any of these patterns (from left to right) "51xxxx", "52xxxx", "53xxxx", "54xxxx", "55xxxx" where "x" signifies
a wildcard. Therefore idPatterns would be created as
String [] idPatterns = {"51xxxx", "52xxxx", "53xxxx", "54xxxx", "55xxxx"};
numberLengths is an array of ints containing the valid card number lengths for this card type. eg;
int[] numberLengths = {16};
The card name argument is a String that is presented to the user to identify this card type.
Carte Blanche and Diner's Club share pattern and length specifiers.
Note: currently Delta and Switch cards have undisclosed identifiers and lengths, therefore checkNumberMatchesIdentifier
will always return true for these card types.
| Field Summary | |
static int |
AMERICAN_EXPRESS
Preset card type, suitable for type constructor argument. |
static int |
CARTE_BLANCHE
Preset card type, suitable for type constructor argument. |
static int |
DELTA
Preset card type, suitable for type constructor argument. |
static int |
DINERS_CLUB
Preset card type, suitable for type constructor argument. |
static int |
DISCOVER
Preset card type, suitable for type constructor argument. |
static int |
EN_ROUTE
Preset card type, suitable for type constructor argument. |
protected String[] |
identifierPatterns
Card number patterns for this card type, eg "51xxxx" for MasterCard. |
static int |
JCB
Preset card type, suitable for type constructor argument. |
static int |
MASTERCARD
Preset card type, suitable for type constructor argument. |
protected String |
name
A string name for this type, eg "MasterCard". |
static int |
SWITCH
Preset card type, suitable for type constructor argument. |
protected int[] |
validNumberLengths
Valid card number lengths for this type of card, this may be empty. |
static int |
VISA
Preset card type, suitable for type constructor argument. |
| Constructor Summary | |
CardType(int type)
Construct a preset card type, where type is one of the static fields (CardType.AMERICAN_EXPRESS, CardType.VISA etc). |
|
CardType(String name,
String[] identifierPatterns,
int[] validNumberLengths)
Construct a new card type. |
|
| Method Summary | |
boolean |
checkNumberLength(String cardNumber)
Checks that the card number is one of the valid lengths specified by this card type. |
boolean |
checkNumberMatchesIdentifier(String cardNumber)
Checks that the card number conforms to one of the identifier patterns for this type. |
boolean |
equals(CardType type)
Evaluates if this card type is 'equal' to type, based on equality checks on name,
identifierPatterns and validNumberLengths. |
static CardType |
findTypeFromCardNumber(String cardNumber,
CardType[] types)
Returns the first card type (in types) whose identifier pattern matches the cardNumber, or null if none match. |
static CardType[] |
getAllCardTypes()
Returns all the preset card types in this class in an array. |
String[] |
getIdentifierPatterns()
Gets the String[] array of identifier patterns for this type of card. |
String |
getName()
Gets the name for this type of card, never returns null. |
int[] |
getValidNumberLengths()
Gets the int[] array of valid card number lengths for this type of card, never returns null. |
boolean |
isCardNumberValid(String cardNumber)
Checks if the card number conforms to one of this card type's patterns. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
protected String name
protected String[] identifierPatterns
Identifier patterns are an array of Strings containing the valid patterns for the card type.
Eg; MasterCard cards have
card numbers that follow any of these patterns "51xxxx", "52xxxx", "53xxxx", "54xxxx", "55xxxx"
where "x" signifies a wildcard.
This is never null although it may be an empty array.
protected int[] validNumberLengths
public static transient int AMERICAN_EXPRESS
type constructor argument.public static transient int CARTE_BLANCHE
type constructor argument.public static transient int DELTA
type constructor argument.public static transient int DINERS_CLUB
type constructor argument.public static transient int DISCOVER
type constructor argument.public static transient int EN_ROUTE
type constructor argument.public static transient int JCB
type constructor argument.public static transient int MASTERCARD
type constructor argument.public static transient int SWITCH
type constructor argument.public static transient int VISA
type constructor argument.| Constructor Detail |
public CardType(String name,
String[] identifierPatterns,
int[] validNumberLengths)
name - the String shown to the user as a representation of this card type.identifierPatterns - String[] array of patterns that card numbers under this card type should have, eg; AMEX 34xxxx or 37xxxxvalidNumberLengths - int[] array of valid card number lengthsname != null && identifierPatterns != null && validNumberLengths != nullgetName() != null && getIdentifierPatterns() != null && getValidNumberLengths() != null
public CardType(int type)
throws IllegalArgumentException
type - a static field type, such as CardType.AMERICAN_EXPRESStype == AMERICAN_EXPRESS || CARTE_BLANCHE || DELTA || DINERS_CLUB || DISCOVER || EN_ROUTE || JCB || MASTERCARD || SWITCH || VISAgetName() != null && getIdentifierPatterns() != null && getValidNumberLengths() != null| Method Detail |
public String getName()
return != nullpublic String[] getIdentifierPatterns()
return != nullidentifierPatternspublic int[] getValidNumberLengths()
return != nullpublic static CardType[] getAllCardTypes()
public boolean isCardNumberValid(String cardNumber)
cardNumber - the card number to check with this card type.cardNumber is null) this returns false.public boolean checkNumberMatchesIdentifier(String cardNumber)
cardNumber - the card number to check.cardNumber is null) this returns false.return == (true AND cardNumber matches patterns specified by self) OR (false)identifierPatternspublic boolean checkNumberLength(String cardNumber)
cardNumber - the card number to check, non-digit chars are ignored.cardNumber is null) this returns false.return == (true AND number of digits (not including whitespace) conforms to number length specified by self ) OR (false)
public static CardType findTypeFromCardNumber(String cardNumber,
CardType[] types)
types) whose identifier pattern matches the cardNumber, or null if none match.
CardType usersCard = CardType.findTypeFromCardNumber( usersCardNumber, CardType.getAllCardTypes() );cardNumber - String representation of the cardNumber, non-digit chars are ignored.types - CardType[] array of card types to look for match in.public boolean equals(CardType type)
type, based on equality checks on name,
identifierPatterns and validNumberLengths.
The elements in identifierPatterns and validNumberLengths are tested for equality with elements
in the corresponding arrays in type, the order of these arrays is relevant in determining equality.type - CardType to test for equality with.type is nulltype != nullresult == (true if name == type.getName() AND identifierPatterns == type.identifierPatters AND validNumberLengths == validNumberLengths) OR (false)
|
CreditCardPack | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||