ISO-8583 messages are structured in a specific way to ensure standardized communication between financial systems. The message structure consists of three main parts: the Message Type Indicator (MTI), Bitmaps, and Data Elements.
The Message Type Indicator (MTI) is a four-digit code that defines the overall purpose and characteristics of the ISO-8583 message.
The MTI is always a four-digit numeric value. Each digit has a specific meaning:
- First digit: Version
- Second digit: Message Class
- Third digit: Message Function
- Fourth digit: Message Origin
-
Version (1st digit):
- 0: ISO 8583-1:1987
- 1: ISO 8583-2:1993
- 2: ISO 8583-3:2003
- 3-9: Reserved for future use
-
Message Class (2nd digit):
- 0: Reserved
- 1: Authorization
- 2: Financial
- 3: File actions
- 4: Reversal and chargeback
- 5: Reconciliation
- 6: Administrative
- 7: Fee collection
- 8: Network management
- 9: Reserved for ISO use
-
Message Function (3rd digit):
- 0: Request
- 1: Response
- 2: Advice
- 3: Advice response
- 4-9: Reserved for ISO use
-
Message Origin (4th digit):
- 0: Acquirer
- 1: Acquirer repeat
- 2: Issuer
- 3: Issuer repeat
- 4: Other
- 5: Other repeat
Here's an example of how to create an ISO-8583 message with a specific MTI using jPOS:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class MTIExample {
public static void main(String[] args) throws ISOException {
ISOMsg message = new ISOMsg();
message.setMTI("0100"); // Authorization request
System.out.println("MTI: " + message.getMTI());
}
}Bitmaps are used to indicate which data elements are present in the message. Each bit in the bitmap represents a specific data element.
The primary bitmap is always present and indicates the presence of data elements 1 to 64.
If bit 1 of the primary bitmap is set (1), it indicates the presence of a secondary bitmap. The secondary bitmap indicates the presence of data elements 65 to 128.
Some implementations may use a tertiary bitmap for data elements 129 to 192, although this is less common.
Here's an example of how to set and check bitmaps using jPOS:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class BitmapExample {
public static void main(String[] args) throws ISOException {
ISOMsg message = new ISOMsg();
message.setMTI("0100");
// Set some fields
message.set(2, "1234567890123456"); // Primary Account Number
message.set(3, "000000"); // Processing Code
message.set(4, "000000010000"); // Transaction Amount
message.set(65, "1234567890"); // Extended Primary Account Number
// Print bitmap information
System.out.println("Primary Bitmap: " + message.getBitmap());
System.out.println("Has Secondary Bitmap: " + message.hasSecondaryBitmap());
}
}Data elements are the actual fields that contain the transaction data.
- Fields 1-64 are represented by the primary bitmap
- Fields 65-128 are represented by the secondary bitmap
- Fields 129-192 are represented by the tertiary bitmap (if used)
The presence of a data element is indicated by setting the corresponding bit in the bitmap to 1. If the bit is 0, the data element is not present in the message.
Here's an example of how to work with data elements using jPOS:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class DataElementExample {
public static void main(String[] args) throws ISOException {
ISOMsg message = new ISOMsg();
message.setMTI("0100");
// Set some fields
message.set(2, "1234567890123456"); // Primary Account Number
message.set(3, "000000"); // Processing Code
message.set(4, "000000010000"); // Transaction Amount
// Check if a field is present
System.out.println("Field 2 present: " + message.hasField(2));
System.out.println("Field 5 present: " + message.hasField(5));
// Get field value
System.out.println("Field 2 value: " + message.getString(2));
// Print all fields
for (int i = 0; i <= 128; i++) {
if (message.hasField(i)) {
System.out.println("Field " + i + ": " + message.getString(i));
}
}
}
}