Class Card

java.lang.Object
org.jpos.core.Card

public class Card extends Object
Immutable card data carrier. This class is based on the old CardHolder class and adds support for multiple PAN and expiration date sources (manual entry, track 1, track 2). It also fixes naming.
Since:
jPOS 2.0.5
  • Field Details

  • Constructor Details

    • Card

      public Card(Card.Builder builder)
      Creates a Card from the given Builder.
      Parameters:
      builder - the builder
  • Method Details

    • getPan

      public String getPan()
      Returns the primary account number.
      Returns:
      the PAN
    • getPanAsNumber

      Returns the primary account number as a BigInteger.
      Returns:
      the PAN as a BigInteger
    • getExp

      public String getExp()
      Returns the card expiry date.
      Returns:
      the expiry date in YYMM format
    • getCvv2

      public String getCvv2()
      Returns the CVV2 / CVC2 value.
      Returns:
      the CVV2 value
    • getServiceCode

      Returns the ISO service code.
      Returns:
      the 3-digit service code
    • hasTrack1

      public boolean hasTrack1()
      Returns true if track 1 data is present.
      Returns:
      true if track 1 is available
    • hasTrack2

      public boolean hasTrack2()
      Returns true if track 2 data is present.
      Returns:
      true if track 2 is available
    • hasBothTracks

      public boolean hasBothTracks()
      Returns true if both track 1 and track 2 data are present.
      Returns:
      true if both tracks are available
    • getBin

      public String getBin()
      Returns the traditional 6-digit BIN from the PAN.
      Returns:
      the first 6 digits of the PAN
    • getBin

      public String getBin(int len)
      Returns the first len digits from the PAN. Can be used for the newer 8-digit BINs, or some arbitrary length.
      Parameters:
      len - number of leading digits to return
      Returns:
      the first len digits of the PAN
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getTrack1

      public Track1 getTrack1()
      Returns the Track 1 data.
      Returns:
      the Track1 object, or null if not present
    • getTrack2

      public Track2 getTrack2()
      Returns the Track 2 data.
      Returns:
      the Track2 object, or null if not present
    • isExpired

      public boolean isExpired(Date currentDate)
      Returns true if the card is expired relative to the given date.
      Parameters:
      currentDate - the date to compare against
      Returns:
      true if the card is expired as of currentDate
    • builder

      public static Card.Builder builder()
      Returns a new Card.Builder for constructing a Card.
      Returns:
      a new Builder