Message Type Indicators (MTIs) are four-digit codes that define the purpose and overall function of an ISO-8583 message. They are crucial in determining how a message should be processed.
Authorization messages are used to request and respond to transaction authorizations.
This message is sent from the acquirer to the issuer to request authorization for a transaction.
Example of creating an authorization request using jPOS:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
public class AuthorizationRequestCreator {
public ISOMsg createAuthorizationRequest() throws ISOException {
ISOMsg msg = new ISOMsg();
msg.setMTI("0100");
msg.set(2, "4111111111111111"); // PAN
msg.set(3, "000000"); // Processing Code (Purchase)
msg.set(4, "000000012345"); // Amount
msg.set(7, ISOUtil.formatDate(new Date(), "MMddHHmmss")); // Transmission Date & Time
msg.set(11, "123456"); // STAN
msg.set(22, "051"); // POS Entry Mode
msg.set(25, "00"); // POS Condition Code
msg.set(41, "12345678"); // Card Acceptor Terminal ID
msg.set(42, "MERCHANT123456"); // Card Acceptor ID Code
msg.set(49, "840"); // Currency Code (USD)
return msg;
}
}This message is the issuer's response to an authorization request.
Example of handling an authorization response:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class AuthorizationResponseHandler {
public void handleAuthorizationResponse(ISOMsg response) throws ISOException {
String responseCode = response.getString(39);
if ("00".equals(responseCode)) {
System.out.println("Authorization approved");
String authCode = response.getString(38);
System.out.println("Authorization code: " + authCode);
} else {
System.out.println("Authorization declined");
System.out.println("Response code: " + responseCode);
}
}
}Financial messages are used for actual monetary transactions.
This message is used to request a financial transaction, such as a purchase or cash withdrawal.
Example of creating a financial request:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
public class FinancialRequestCreator {
public ISOMsg createFinancialRequest() throws ISOException {
ISOMsg msg = new ISOMsg();
msg.setMTI("0200");
msg.set(2, "4111111111111111"); // PAN
msg.set(3, "000000"); // Processing Code (Purchase)
msg.set(4, "000000012345"); // Amount
msg.set(7, ISOUtil.formatDate(new Date(), "MMddHHmmss")); // Transmission Date & Time
msg.set(11, "123456"); // STAN
msg.set(22, "051"); // POS Entry Mode
msg.set(25, "00"); // POS Condition Code
msg.set(41, "12345678"); // Card Acceptor Terminal ID
msg.set(42, "MERCHANT123456"); // Card Acceptor ID Code
msg.set(49, "840"); // Currency Code (USD)
return msg;
}
}This message is the response to a financial request, indicating whether the transaction was successful.
Example of handling a financial response:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class FinancialResponseHandler {
public void handleFinancialResponse(ISOMsg response) throws ISOException {
String responseCode = response.getString(39);
if ("00".equals(responseCode)) {
System.out.println("Transaction approved");
String authCode = response.getString(38);
System.out.println("Authorization code: " + authCode);
} else {
System.out.println("Transaction declined");
System.out.println("Response code: " + responseCode);
}
}
}Reversal messages are used to undo or correct previous transactions.
This message is sent to request the reversal of a previous transaction.
Example of creating a reversal request:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
public class ReversalRequestCreator {
public ISOMsg createReversalRequest(ISOMsg originalMsg) throws ISOException {
ISOMsg msg = new ISOMsg();
msg.setMTI("0400");
msg.set(2, originalMsg.getString(2)); // PAN
msg.set(3, originalMsg.getString(3)); // Processing Code
msg.set(4, originalMsg.getString(4)); // Amount
msg.set(7, ISOUtil.formatDate(new Date(), "MMddHHmmss")); // Transmission Date & Time
msg.set(11, originalMsg.getString(11)); // STAN
msg.set(37, originalMsg.getString(37)); // Retrieval Reference Number
msg.set(41, originalMsg.getString(41)); // Card Acceptor Terminal ID
msg.set(42, originalMsg.getString(42)); // Card Acceptor ID Code
return msg;
}
}This message is the response to a reversal request.
Example of handling a reversal response:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class ReversalResponseHandler {
public void handleReversalResponse(ISOMsg response) throws ISOException {
String responseCode = response.getString(39);
if ("00".equals(responseCode)) {
System.out.println("Reversal approved");
} else {
System.out.println("Reversal failed");
System.out.println("Response code: " + responseCode);
}
}
}Network management messages are used for administrative purposes between systems.
This message is used for various network management functions, such as echo tests or sign-on requests.
Example of creating a network management request (echo test):
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
import org.jpos.iso.ISOUtil;
public class NetworkManagementRequestCreator {
public ISOMsg createEchoTest() throws ISOException {
ISOMsg msg = new ISOMsg();
msg.setMTI("0800");
msg.set(7, ISOUtil.formatDate(new Date(), "MMddHHmmss")); // Transmission Date & Time
msg.set(11, ISOUtil.zeropad(String.valueOf(System.currentTimeMillis() % 1000000), 6)); // STAN
msg.set(70, "301"); // Network Management Information Code (Echo Test)
return msg;
}
}This message is the response to a network management request.
Example of handling a network management response:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class NetworkManagementResponseHandler {
public void handleNetworkManagementResponse(ISOMsg response) throws ISOException {
String responseCode = response.getString(39);
if ("00".equals(responseCode)) {
System.out.println("Network management request successful");
String networkManagementCode = response.getString(70);
System.out.println("Network Management Code: " + networkManagementCode);
} else {
System.out.println("Network management request failed");
System.out.println("Response code: " + responseCode);
}
}
}To tie all of these concepts together, here's an example of a simple ISO-8583 message processor that can handle different MTIs:
import org.jpos.iso.ISOMsg;
import org.jpos.iso.ISOException;
public class ISO8583MessageProcessor {
public void processMessage(ISOMsg msg) throws ISOException {
String mti = msg.getMTI();
switch (mti) {
case "0100":
processAuthorizationRequest(msg);
break;
case "0110":
processAuthorizationResponse(msg);
break;
case "0200":
processFinancialRequest(msg);
break;
case "0210":
processFinancialResponse(msg);
break;
case "0400":
processReversalRequest(msg);
break;
case "0410":
processReversalResponse(msg);
break;
case "0800":
processNetworkManagementRequest(msg);
break;
case "0810":
processNetworkManagementResponse(msg);
break;
default:
System.out.println("Unsupported MTI: " + mti);
}
}
private void processAuthorizationRequest(ISOMsg msg) throws ISOException {
// Process authorization request
}
private void processAuthorizationResponse(ISOMsg msg) throws ISOException {
// Process authorization response
}
private void processFinancialRequest(ISOMsg msg) throws ISOException {
// Process financial request
}
private void processFinancialResponse(ISOMsg msg) throws ISOException {
// Process financial response
}
private void processReversalRequest(ISOMsg msg) throws ISOException {
// Process reversal request
}
private void processReversalResponse(ISOMsg msg) throws ISOException {
// Process reversal response
}
private void processNetworkManagementRequest(ISOMsg msg) throws ISOException {
// Process network management request
}
private void processNetworkManagementResponse(ISOMsg msg) throws ISOException {
// Process network management response
}
}