Class Track2.Builder

java.lang.Object
org.jpos.core.Track2.Builder
Enclosing class:
Track2

public static class Track2.Builder extends Object
Fluent builder that parses a raw track2 string or assembles a Track2 from individual fields and validates the result against a configurable pattern.
Since:
jPOS 2.0.5
  • Method Details

    • pan

      public Track2.Builder pan(String pan)
      Sets the primary account number.
      Parameters:
      pan - primary account number
      Returns:
      this builder
    • exp

      public Track2.Builder exp(String exp)
      Sets the expiration date.
      Parameters:
      exp - expiration date in YYMM form
      Returns:
      this builder
    • cvv

      public Track2.Builder cvv(String cvv)
      Sets the CVV/CVC value.
      Parameters:
      cvv - CVV/CVC value
      Returns:
      this builder
    • serviceCode

      public Track2.Builder serviceCode(String serviceCode)
      Sets the service code.
      Parameters:
      serviceCode - three-digit service code
      Returns:
      this builder
    • discretionaryData

      public Track2.Builder discretionaryData(String discretionaryData)
      Sets the discretionary data trailing the service code.
      Parameters:
      discretionaryData - discretionary data trailing the service code
      Returns:
      this builder
    • pattern

      public Track2.Builder pattern(Pattern pattern)
      Optional method, can be used to override default pattern
      Parameters:
      pattern - overrides default pattern
      Returns:
      this builder
    • track

      Parses a raw track2 string and populates the builder fields.
      Parameters:
      s - raw track2 data
      Returns:
      this builder
      Throws:
      InvalidCardException - if s is null, exceeds 37 characters, or does not match the configured pattern
    • buildTrackData

      Constructs the Track2 data based on the card data provided. The generated Track2 data is validated using the pattern. If the Track2 data doesn't match the pattern, the track attribute keeps the original value.
      Returns:
      this builder.
    • build

      public Track2 build()
      Builds the immutable Track2. If no raw track string was set, one is assembled from the individual fields via buildTrackData().
      Returns:
      the built Track2