Using the CreditCard Validator Control

The CreditCard Control provides a single method for credit card validation. The essential parameter(s) to this method are shown below. The java interface for the control is below:
Collection validate(java.lang.String number, java.util.Date expiryDate, com.bea.powertoys.creditcard.CardType type);

Invoking the control

The credit card validator method is invoked as follows:
String number = "5334 5678 1234 5670";
GregorianCalendar calender = new GregorianCalendar(2010,4,20);
Date expiryDate = calender.getTime();
CardType cardType = CardType.MASTER_CARD;

Collection result = control.validate(number,expiryDate,cardType);
Please note all the three arguments provided to the control are mandatory and credit card number may have spaces.

Using the result

Control returns a collection of 'com.bea.powertoys.creditcard.CreditCardError' objects. Empty collection means the credit card is valid, on the other hand non-empty collections means errors. For every error, the collection contains an immutable obejct of type 'com.bea.powertoys.creditcard.CreditCardError'. Errors in collection may be among the following:
public static final CreditCardError NUMBER_INVALID;
public static final CreditCardError EXPIRED;
public static final CreditCardError INVALID_TYPE;

Invalid Credit Card

NUMBER_INVALID : Denotes that the credit card number provided has failed to pass Luhn Formula as described here.
EXPIRED : Denotes that the credit card expiry date has been expired.
INVALID_TYPE : Denotes that credit card type is not-valid for the credit card number provided.

Valid Credit Card

When the returned collection is empty, it denotes that the credit card information provided to the control is valid  with respect to three tests performed.

The Java Page Flow sample that accompanies the CreditCard Control demonstrates how to use the control.