Skip to content

Java library that can parse magnetic stripes from a bank issued credit card.

License

Notifications You must be signed in to change notification settings

sualeh/magnetictrackparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magnetic Track Parser

Magnetic Track Parser is a Java 7 library that can parse magnetic track data from a bank issued credit card, such as might be returned from a USB magnetic card stripe reader. All classes are immutable and thread-safe. The standard toString() function formats data in a readable form. Validity is enforced by JUnit tests. Maven is needed for a build.

See the article on Magnetic stripe card on Wikipedia for information about the format of track data.

Download

You can download the jar on the Maven Central Repository.

Maven Build

To use Magnetic Track Parser 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>magnetictrackparser</artifactId>
    <version>1.0</version>
</dependency>

Examples

How to Get Bank Card Information

To get bank card information, use code like:

final PrimaryAccountNumber pan = new PrimaryAccountNumber("371449635398431");
final BankCard card = new BankCard(pan);
System.out.println(card);

and you will get this output:

Bank Card Information: 
  Primary Account Number: 371449635398431
    MII: 3 - Travel and entertainment and banking/financial
    IIN: 371449
    Card Brand: AmericanExpress
    Passes Luhn Check: true

How to Parse Magnetic Track Data

To parse a magnetic track, use code like:

final BankCardMagneticTrack track = 
    BankCardMagneticTrack.from("%B5350290149345177^FATEHI/SUALEH^16042010000000000000000000000000000567001000?;5350290149345177=16042010000056700100?");
System.out.println(track);

and you will get this output:

Track 1: %B5350290149345177^FATEHI/SUALEH^16042010000000000000000000000000000567001000?
  Primary Account Number: 5350290149345177
    MII: 5 - Banking and financial
    IIN: 535029
    Card Brand: MasterCard
  Expiration Date: April 2016
  Name: Sualeh Fatehi
  Service Code: 
    2 - Interchange: International interchange. Technology: Integrated circuit card.
    0 - Authorization Processing: Normal.
    1 - Allowed Services: No restrictions. PIN Requirements: None.
  Discretionary Data: 0000000000000000000000000000567001000
Track 2: ;5350290149345177=16042010000056700100?
  Primary Account Number: 5350290149345177
    MII: 5 - Banking and financial
    IIN: 535029
    Card Brand: MasterCard
  Expiration Date: April 2016
  Service Code: 
    2 - Interchange: International interchange. Technology: Integrated circuit card.
    0 - Authorization Processing: Normal.
    1 - Allowed Services: No restrictions. PIN Requirements: None.
  Discretionary Data: 0000056700100
No Track 3 Data