CreditCardPack

com.keyoti.creditCard.logic
Class CreditCard

java.lang.Object
  |
  +--com.keyoti.creditCard.logic.CreditCard

public class CreditCard
extends Object
implements Serializable

Business layer Bean, holds credit card data and can perform checks on the details to verify their validity, such as MOD10 checks on the card number, card type/number matches and simple date testing. Not all fields are required. Only card number, type, name and expiry date are required to fulfil isMinimumValid().

Events
Every time one of the minimum required fields (card number, type, name and expiry date) are changed, isMinimumValid() is called to check their validity. If the credit card details become invalid or valid a CreditCardEvent is fired. CreditCard objects begin in an invalid details state, since the minimum required details are not defined. When they are all defined and valid a CreditCardEvent is fired by calling detailsValid in all registered listeners.

Author:
Keyoti
See Also:
Serialized Form

Field Summary
static int BILLING_ADDRESS
          Credit card field identifier
protected  String[] billingAddress
          The billing address for this card, this is a 5 element array.
static int CARD_NAME
          Credit card field identifier
static int CARD_NUMBER
          Credit card field identifier
static int CARD_TYPE
          Credit card field identifier
static int CARD_VERIFICATION_NUMBER
          Credit card field identifier
protected  String cardName
          The card owners name
protected  String cardNumber
          The card number.
protected  CardType cardType
          The card type
protected  String cardVerificationNumber
          The card verification number (CVV2/CVC2/CID), which for Mastercard & Visa is a 3 digit number that appears on the back of the card, above the signature strip on the right.
protected  String comments
          Any comments, this is a plain String field that may be used to record comments about this card.
static int COMMENTS
          Credit card field identifier
static int EXPIRY_MONTH
          Credit card field identifier
static int EXPIRY_YEAR
          Credit card field identifier
protected  Integer expiryMonth
          The card expiry month (1->12)
protected  Integer expiryYear
          The 2 digit card expiry year (yy)
static int ISSUE_NUMBER
          Credit card field identifier
protected  Integer issueNumber
          The card issue number
protected  String issuer
          The card issuer's (i.e.
static int ISSUER
          Credit card field identifier
static int START_MONTH
          Credit card field identifier
static int START_YEAR
          Credit card field identifier
protected  Integer startMonth
          The card start month (1->12)
protected  Integer startYear
          The 2 digit card start year (yy)
 
Constructor Summary
CreditCard()
          Constructs a new CreditCard object.
 
Method Summary
 void addCreditCardListener(CreditCardListener l)
          Adds the supplied CreditCardListener.
 void addPropertyChangeListener(PropertyChangeListener l)
          Adds the supplied PropertyChangeListener object to registry of objects to be notified of changes to:
cardNumber, expiryMonth, expiryYear, startMonth, startYear, issueNumber, cardName & cardType properties.
 String[] getBillingAddress()
          Gets the card billingAddress array
 String getCardName()
          Gets the card owners name
 String getCardNumber()
          Gets the credit card number.
 CardType getCardType()
          Gets the card type.
 String getCardVerificationNumber()
          Gets the Card Verification Number, this should not be stored in long term persistence.
 String getComments()
          Gets the card comments
 CreditCardListener[] getCreditCardListeners()
          Gets all CreditCardListeners as an array.
 Integer getExpiryMonth()
          Gets the card expiry date month.
 Integer getExpiryYear()
          Gets the card expiry date year.
 Integer getIssueNumber()
          Gets the card issue number.
 String getIssuer()
          Gets the card issuer's name
 Integer getStartMonth()
          Gets the card start date month.
 Integer getStartYear()
          Gets the card start date year.
 boolean isCardNameValid()
          Determines if the card holders name is valid, this is a very simple method, that just checks if the card name field is longer than 0 chars and not null.
 boolean isCardNumberValid()
          Determines if the card number is valid, according to a MOD10 check and character validity check.
 boolean isCardTypeValid()
          Determines if the card type corresponds with the credit card number.
 boolean isCardVerificationNumberValid()
          Determines if the card verification number is 3 or 4 digits long and only includes numeric characters.
 boolean isExpiryMonthValid()
          Determines if the expiry month is valid, simply by checking that it is between 1 and 12 inclusive, if it is null, false is returned.
 boolean isExpiryYearValid()
          Determines if the expiry year is valid , simply by checking that it is between 0 and 99 inclusive (since credit card expiry dates are 2 digits long), if it is null, false is returned.
 boolean isMinimumValid()
          Convenience method, checks that card number, expiry date, type and card name are valid.
 boolean isStartMonthValid()
          Determines if the start month is valid, simply by checking that it is between 1 and 12 inclusive, if it is null, false is returned.
 boolean isStartYearValid()
          Determines if the start year is valid , simply by checking that it is between 0 and 99 inclusive (since credit card start dates are 2 digits long), if it is null, false is returned.
 void removeCreditCardListener(CreditCardListener l)
          Removes the supplied CreditCardListener.
 void removePropertyChangeListener(PropertyChangeListener l)
          Removes the supplied PropertyChangeListener from the registry of objects notified of property changes.
 void setBillingAddress(String[] billingAddress)
          Sets the card billingAddress array.
 void setCardName(String cardName)
          Sets the card owners name.
 void setCardNumber(String cardNumber)
          Sets the card number.
 void setCardType(CardType cardType)
          Sets the card type.
 void setCardVerificationNumber(String cvn)
          Sets the Card Verification Number (CVN), this should not be stored in long term persistence.
 void setComments(String comments)
          Sets the card comments.
 void setExpiryMonth(int expiryMonth)
          Sets the card expiry date month, using setExpiryMonth(Integer).
 void setExpiryMonth(Integer expiryMonth)
          Sets the card expiry date month.
 void setExpiryYear(int expiryYear)
          Sets the card expiry date year, using setExpiryYear(Integer).
 void setExpiryYear(Integer expiryYear)
          Sets the card expiry date year, because credit cards usually specify 2 digit year values this is mirrored here.
 void setIssueNumber(int issueNumber)
          Sets the card issue number, using setIssueNumber(Integer).
 void setIssueNumber(Integer issueNumber)
          Sets the card issue number.
 void setIssuer(String issuer)
          Sets the card issuer's name.
 void setStartMonth(int startMonth)
          Sets the card start date month, using setStartMonth(Integer).
 void setStartMonth(Integer startMonth)
          Sets the card start date month.
 void setStartYear(int startYear)
          Sets the card start date year, using setStartYear(Integer).
 void setStartYear(Integer startYear)
          Sets the card start date year, because credit cards usually specify 2 digit year values this is mirrored here.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cardNumber

protected String cardNumber
The card number.

expiryMonth

protected Integer expiryMonth
The card expiry month (1->12)

expiryYear

protected Integer expiryYear
The 2 digit card expiry year (yy)

startMonth

protected Integer startMonth
The card start month (1->12)

startYear

protected Integer startYear
The 2 digit card start year (yy)

issueNumber

protected Integer issueNumber
The card issue number

cardName

protected String cardName
The card owners name

cardType

protected CardType cardType
The card type

cardVerificationNumber

protected String cardVerificationNumber
The card verification number (CVV2/CVC2/CID), which for Mastercard & Visa is a 3 digit number that appears on the back of the card, above the signature strip on the right. For American Express this is a 4 digit number on the front of the card, to the right, above the card number.

issuer

protected String issuer
The card issuer's (i.e. the bank) name.

comments

protected String comments
Any comments, this is a plain String field that may be used to record comments about this card.

billingAddress

protected String[] billingAddress
The billing address for this card, this is a 5 element array. eg;
     billingAddress[0] = "StreetLine1";
     billingAddress[1] = "StreetLine2";
     billingAddress[2] = "City";
     billingAddress[3] = "State/Province/County";
     billingAddress[4] = "PostalCode";
     billingAddress[5] = "Country";
     

CARD_NAME

public static transient int CARD_NAME
Credit card field identifier

CARD_NUMBER

public static transient int CARD_NUMBER
Credit card field identifier

CARD_TYPE

public static transient int CARD_TYPE
Credit card field identifier

EXPIRY_MONTH

public static transient int EXPIRY_MONTH
Credit card field identifier

EXPIRY_YEAR

public static transient int EXPIRY_YEAR
Credit card field identifier

ISSUE_NUMBER

public static transient int ISSUE_NUMBER
Credit card field identifier

START_MONTH

public static transient int START_MONTH
Credit card field identifier

START_YEAR

public static transient int START_YEAR
Credit card field identifier

CARD_VERIFICATION_NUMBER

public static transient int CARD_VERIFICATION_NUMBER
Credit card field identifier

ISSUER

public static transient int ISSUER
Credit card field identifier

COMMENTS

public static transient int COMMENTS
Credit card field identifier

BILLING_ADDRESS

public static transient int BILLING_ADDRESS
Credit card field identifier
Constructor Detail

CreditCard

public CreditCard()
Constructs a new CreditCard object.
Method Detail

addCreditCardListener

public void addCreditCardListener(CreditCardListener l)
Adds the supplied CreditCardListener.
Parameters:
l - an object implementing CreditCardListener
Returns:
void
Throws:
NullPointerException - if l is null.
Preconditions:
l != null
Postconditions:
l will be notified of CreditCard events

removeCreditCardListener

public void removeCreditCardListener(CreditCardListener l)
Removes the supplied CreditCardListener.
Parameters:
l - a CreditCardListener that should be excluded from future event broadcasts.
Returns:
void
Throws:
NullPointerException - if l is null.
Preconditions:
l != null
Postconditions:
l will not be notified of CreditCard events

getCreditCardListeners

public CreditCardListener[] getCreditCardListeners()
Gets all CreditCardListeners as an array.
Returns:
a CreditCardListener[] array of currently registered listener objects.
Postconditions:
return == array of listeners

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Adds the supplied PropertyChangeListener object to registry of objects to be notified of changes to:
cardNumber, expiryMonth, expiryYear, startMonth, startYear, issueNumber, cardName & cardType properties.
Parameters:
l - an object implementing the PropertyChangeListener interface, to be notified of property change events.
Returns:
void
Throws:
NullPointerException - if l is null.

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Removes the supplied PropertyChangeListener from the registry of objects notified of property changes.
Parameters:
l - an object implementing the PropertyChangeListener interface, will not be notified of property change events in future.
Returns:
void
Throws:
NullPointerException - if l is null.

getCardNumber

public String getCardNumber()
Gets the credit card number.
Returns:
the credit card number String.

setCardNumber

public void setCardNumber(String cardNumber)
Sets the card number. Any number formatting (spaces or hyphens) is removed. Notifies any property change listeners if new value is different to the current value.
Parameters:
cardNumber - the new card number String.
Returns:
void
Throws:
NullPointerException - if cardNumber is null.
Preconditions:
cardNumber != null
Postconditions:
getCardNumber() == cardNumber

isCardNumberValid

public boolean isCardNumberValid()
Determines if the card number is valid, according to a MOD10 check and character validity check.
Returns:
true if the card number is valid, false if the card number is not valid (or has not been set yet).
Postconditions:
return == LuhnChecker.isValid(getCardNumber())

getCardName

public String getCardName()
Gets the card owners name

setCardName

public void setCardName(String cardName)
Sets the card owners name. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if cardName is null.
Preconditions:
cardName != null
Postconditions:
getCardName() == cardName

isCardNameValid

public boolean isCardNameValid()
Determines if the card holders name is valid, this is a very simple method, that just checks if the card name field is longer than 0 chars and not null.
Returns:
true if the card name field is a String with length > 0, false otherwise
Postconditions:
return == getCardName().length() > 0

getExpiryMonth

public Integer getExpiryMonth()
Gets the card expiry date month.

setExpiryMonth

public void setExpiryMonth(Integer expiryMonth)
Sets the card expiry date month. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if expiryMonth is null.
IllegalArgumentException - if 0 < expiryMonth <= 12 is not true.
Preconditions:
expiryMonth != null AND expiryMonth >= 1 AND expiryMonth <= 12
Postconditions:
getExpiryMonth() == expiryMonth AND isExpiryMonthValid() == true

getExpiryYear

public Integer getExpiryYear()
Gets the card expiry date year.

setExpiryYear

public void setExpiryYear(Integer expiryYear)
Sets the card expiry date year, because credit cards usually specify 2 digit year values this is mirrored here. Expiry year must be between 0 and 99 inclusive, otherwise an IllegalArgumentException is thrown. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if expiryYear is null.
IllegalArgumentException - if 0 <= expiryYear <= 99 is not true
Preconditions:
expiryYear != null AND expiryYear >= 0 AND expiryYear <= 99
Postconditions:
getExpiryYear() == expiryYear AND isExpiryYearValid() == true

setExpiryMonth

public void setExpiryMonth(int expiryMonth)
                    throws IllegalArgumentException
Sets the card expiry date month, using setExpiryMonth(Integer).
Throws:
IllegalArgumentException - if 1<=expiryMonth<=12 is not true.
See Also:
setExpiryMonth(Integer)

setExpiryYear

public void setExpiryYear(int expiryYear)
                   throws IllegalArgumentException
Sets the card expiry date year, using setExpiryYear(Integer).
Throws:
IllegalArgumentException - if 0<=expiryYear<=99 is not true.
See Also:
setExpiryYear(Integer)

isExpiryMonthValid

public boolean isExpiryMonthValid()
Determines if the expiry month is valid, simply by checking that it is between 1 and 12 inclusive, if it is null, false is returned.
Returns:
boolean true if expiry month is an Integer between 1 and 12 inclusive, false otherwise.
Postconditions:
return == (0 < getExpiryMonth() && getExpiryMonth() <= 12)

isExpiryYearValid

public boolean isExpiryYearValid()
Determines if the expiry year is valid , simply by checking that it is between 0 and 99 inclusive (since credit card expiry dates are 2 digits long), if it is null, false is returned.
Returns:
boolean true if expiry year is an Integer between 0 and 99 inclusive, false otherwise.
Postconditions:
return == (0 <= getExpiryYear() && getExpiryYear <= 99)

getStartMonth

public Integer getStartMonth()
Gets the card start date month.

setStartMonth

public void setStartMonth(Integer startMonth)
Sets the card start date month. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if startMonth is null.
IllegalArgumentException - if 0 < startMonth <= 12 is not true.
Preconditions:
startMonth != null AND startMonth >= 1 AND startMonth <= 12
Postconditions:
getStartMonth() == startMonth AND isStartMonthValid() == true

getStartYear

public Integer getStartYear()
Gets the card start date year.

setStartYear

public void setStartYear(Integer startYear)
Sets the card start date year, because credit cards usually specify 2 digit year values this is mirrored here. Start year must be between 0 and 99 inclusive, otherwise an IllegalArgumentException is thrown. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if startYear is null.
IllegalArgumentException - if 0 <= startYear <= 99 is not true
Preconditions:
startYear != null AND startYear >= 0 AND startYear <= 99
Postconditions:
getStartYear() == startYear AND isStartYearValid() == true

setStartMonth

public void setStartMonth(int startMonth)
                   throws IllegalArgumentException
Sets the card start date month, using setStartMonth(Integer).
Throws:
IllegalArgumentException - if 1<=startMonth<=12 is not true.
See Also:
setStartMonth(Integer)

setStartYear

public void setStartYear(int startYear)
                  throws IllegalArgumentException
Sets the card start date year, using setStartYear(Integer).
Throws:
IllegalArgumentException - if 0<=startYear<=99 is not true.
See Also:
setStartYear(Integer)

isStartMonthValid

public boolean isStartMonthValid()
Determines if the start month is valid, simply by checking that it is between 1 and 12 inclusive, if it is null, false is returned.
Returns:
boolean true if start month is an Integer between 1 and 12 inclusive, false otherwise.
Postconditions:
return == (0 < getStartMonth() && getStartMonth() <= 12)

isStartYearValid

public boolean isStartYearValid()
Determines if the start year is valid , simply by checking that it is between 0 and 99 inclusive (since credit card start dates are 2 digits long), if it is null, false is returned.
Returns:
boolean true if start year is an Integer between 0 and 99 inclusive, false otherwise.
Postconditions:
return == (0 <= getStartYear() && getStartYear <= 99)

getIssueNumber

public Integer getIssueNumber()
Gets the card issue number.

setIssueNumber

public void setIssueNumber(Integer issueNumber)
Sets the card issue number. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if issueNumber is null.
IllegalArgumentException - if 0 <= issueNumber <= 999 is not true.
Preconditions:
issueNumber != null AND issueNumber >=0 AND issueNumber <= 999
Postconditions:
getIssueNumber() == issueNumber

setIssueNumber

public void setIssueNumber(int issueNumber)
                    throws IllegalArgumentException
Sets the card issue number, using setIssueNumber(Integer).
Throws:
IllegalArgumentException - if 0<=issueNumber<=999 is not true.
See Also:
setIssueNumber(Integer)

getCardType

public CardType getCardType()
Gets the card type.

setCardType

public void setCardType(CardType cardType)
Sets the card type. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if cardType is null.
Preconditions:
cardType != null
Postconditions:
getCardType() == cardType

isCardTypeValid

public boolean isCardTypeValid()
Determines if the card type corresponds with the credit card number. Each card type has a number length and pattern defined for the card number to obey, eg; MasterCard cards start "51xxxx".
If the value of getCardNumber() conforms to the pattern specified in the card type returned by getCardType() then true is returned, otherwise false ( if getCardType() is null then this returns false).
Returns:
true if the card type number patterns match the card number, false otherwise.
Postconditions:
return == (true AND getCardNumber() matches patterns specified by getCardType()) OR (false)
See Also:
CardType

getCardVerificationNumber

public String getCardVerificationNumber()
Gets the Card Verification Number, this should not be stored in long term persistence. It is a misuse to store this number because it is intended that it be verified by the issuer and not be held any where other than on the physical card.
See Also:
cardVerificationNumber

setCardVerificationNumber

public void setCardVerificationNumber(String cvn)
Sets the Card Verification Number (CVN), this should not be stored in long term persistence. It is a misuse to store this number because it is intended that it be verified by the issuer and not be held any where other than on the physical card. The CVN must be either 3 or 4 digits in length or empty.
Parameters:
cvn - the card verification number String.
Returns:
void
Throws:
NullPointerException - if cvn is null.
IllegalArgumentException - if cvn is not 3 or 4 numeric characters or an empty String.
Preconditions:
cvn != null AND ((3 <= cvn.length() <= 4 AND cvn.equals(LuhnChecker.getDigitsOnly(cvn))) OR cvn == "" )
Postconditions:
getCardVerificationNumber() == cvn
See Also:
cardVerificationNumber

isCardVerificationNumberValid

public boolean isCardVerificationNumberValid()
Determines if the card verification number is 3 or 4 digits long and only includes numeric characters. Note: that only the card processor can determine if the card verification number is truly 'valid', this only provides pre-processing checks.
Returns:
true if card verification number is 3 or 4 digits long, false otherwise (including if getCardVerificationNumber() is null).
Postconditions:
return == (true AND getCardVerificationNumber() != null AND 3 <= getCardVerificationNumber().length() <= 4 AND LuhnChecker.getDigitsOnly(getCardVerificationNumber()).equals(getCardVerificationNumber())) OR false

getIssuer

public String getIssuer()
Gets the card issuer's name

setIssuer

public void setIssuer(String issuer)
Sets the card issuer's name. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if issuer is null.
Preconditions:
issuer != null
Postconditions:
getIssuer() == issuer

getComments

public String getComments()
Gets the card comments

setComments

public void setComments(String comments)
Sets the card comments. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if comments is null.
Preconditions:
comments != null
Postconditions:
getComments() == comments

getBillingAddress

public String[] getBillingAddress()
Gets the card billingAddress array

setBillingAddress

public void setBillingAddress(String[] billingAddress)
Sets the card billingAddress array. Notifies any property change listeners if new value is different to the current value.
Returns:
void
Throws:
NullPointerException - if billingAddress is null.
IllegalArgumentException - if billingAddress.length > 5
Preconditions:
billingAddress != null
Postconditions:
getBillingAddress() == billingAddress

isMinimumValid

public boolean isMinimumValid()
Convenience method, checks that card number, expiry date, type and card name are valid. Calls isCardNumberValid(), isExpiryMonthValid(), isExpiryYearValid(), isCardNameValid() and isCardTypeValid(). Fields are determined as valid according to the individual methods.
Returns:
true if all fields are valid, false otherwise.
Postconditions:
return == isCardNumberValid() && isExpiryMonthValid() && isExpiryYearValid() && isCardNameValid() && isCardTypeValid()

CreditCardPack

Copyright © 2002 Keyoti All Rights Reserved.