View on GitHub

Credit card number

Java 6 library that can provide details of a bank issued credit card number

Download this project as a .zip file Download this project as a tar.gz file

Credit Card Number

Credit Card Number is a Java library that can provide details of a bank issued credit card number.

All classes are immutable and thread-safe. The standard toString() function formats data in a readable form. Validity is enforced by JUnit tests. Java 6 or newer is required. In order to be Java 8 ready, Credit Card Number depends on Stephen Colebourne's ThreeTen backport project, a port of JSR 310 to Java 6.

The goal of this project is to use publicly and freely available documentation to create a reliable Java library to provide information about credit card numbers.

Some resources consulted are:

Download

You can download the jar on the Maven Central Repository.

Maven Build

To use Credit Card Number in your Maven build, include the following dependency. No repositories references are needed, since the jars are in the Maven Central Repository.

<dependency>
    <groupId>us.fatehi</groupId>
    <artifactId>credit_card_number</artifactId>
    <version>1.3</version>
</dependency>

Examples

How to Get Bank Card Information

To get bank card information, use code like:

final PrimaryAccountNumber pan = new AccountNumber("5266-0922-0141-6174");
final BankCard card = new BankCard(pan);
System.out.println(card);

and you will get this output:

Bank Card Information: 
  Primary Account Number: 5266092201416174
  Primary Account Number (Secure): MasterCard-6174
    Major Industry Identifier: 5 - Banking and financial
    Issuer Identification Number: 526609
    Card Brand: MasterCard
    Last Four Digits: 6174
    Passes Luhn Check? Yes
    Is Primary Account Number Valid? Yes

How to Secure the Credit Card Number

If you need the account number information, but want to be secure by not storing the actual primary account number in memory, you can use code like:

final PrimaryAccountNumber pan = 
  new AccountNumberInfo(new AccountNumber("5266-0922-0141-6174"));