Skip to content

Latest commit

 

History

History
301 lines (241 loc) · 9.67 KB

File metadata and controls

301 lines (241 loc) · 9.67 KB

4. Message Type Indicators (MTIs)

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.

4.1. Authorization messages

Authorization messages are used to request and respond to transaction authorizations.

4.1.1. 0100: Authorization Request

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;
    }
}

4.1.2. 0110: Authorization Response

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);
        }
    }
}

4.2. Financial messages

Financial messages are used for actual monetary transactions.

4.2.1. 0200: Financial Request

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;
    }
}

4.2.2. 0210: Financial Response

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);
        }
    }
}

4.3. Reversal messages

Reversal messages are used to undo or correct previous transactions.

4.3.1. 0400: Reversal Request

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;
    }
}

4.3.2. 0410: Reversal Response

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);
        }
    }
}

4.4. Network management messages

Network management messages are used for administrative purposes between systems.

4.4.1. 0800: Network Management Request

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;
    }
}

4.4.2. 0810: Network Management Response

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
    }
}