Tuesday, April 10, 2012

ISO-8583 Standard in Java for Financial Transactions

Dear Reader,

I am writing about "ISO-8583 Standard" which is used in financial transactions that I learnt
while writing code and monitoring these banking/financial transactions.

A Financial transaction is a communication between 2 Systems through socket connection. Of course
this connection is maintained by network team. Once connection is established, each system (Sender and Recipient)
can send messages in ISO-8583 format which is common for request and response. However there are attributes which
differentiates a message into Request and Response.

From our experience the communication starts with Sign-on and then Echo messages and then financial transaction 
starts. Also periodically an echo message is sent to make sure the other system is still alive.

So following steps are involved in Transaction Flow:
    1. System A open connection to System B (through specific IP and Port).
    2. Connection established.
    3. System A send Sign-On request message.
    4. System B send Sign-on response message.
    5. System A will start sending Echo request message periodically (e.g. every 2 minute).
    6. System B will send Echo response message whenever receive Echo request message.
    7. When financial transaction happen, System A will send Transaction request message.
    8. Then System B will send Transaction response message.
    9. If something wrong happens (usually Timeout, so System A didn’t get the response), System A 
       will send Reversal request message to cancel the previous transaction.
    10. System B will send Reversal response message based on previous transaction.

I hope the flow is clear now. Next the question is how is this ISO-8583 message looks like.
An ISO-8583 message is made of the following parts:
   a. Message Type Indicator (MTI).
   b. One or more bitmaps, indicating which data elements are present.
   c. Data Elements, the fields of the message.

   
Message Type Indicator or MTI is 4 digits numeric that describe the message type. Commonly used are:
    - 02xx : Financial Message (e.g 0200 for request, 0210 for response)
    - 04xx : Reversal Message (e.g 0400 for request, 0410 for response)
    - 08xx : Network Management Message (e.g 0800 for request, 0810 for response)
    
    

    This 4 digit numeric field classifies the high level function of the message. A message type indicator 
    includes the ISO 8583 version, the Message Class, the Message Function and the Message Origin. 
    The following example (MTI 0110) lists what each digit indicates:    
        0xxx -> version of ISO 8583 (1987 version: 0-1987, 1-1993, 2-2003, 9-Private Usage).
        x1xx -> class of the Message (Authorization Message: 1-Authorization Message, 2-Financial Message, 
                4-Reversal Message)
                
        xx1x -> function of the Message (Request Response: 0-Request, 1-Request Response, 2-Advice, 
                4-Notification, 8-Response Acknowledgement).
        xxx0 -> who began the communication (Acquirer: 0-Acquirer, 1-Acquirer Repeat, 2-Issuer, 3-Issuer Repeat).

Complete example is below on the above pattern:
0200-     (Meaning: Acquirer Financial Request), Value: Request for funds, typically from an ATM or NPCI.
0210-     (Meaning: Issuer Response to Financial Request), Value:    Issuer response to request for funds.
More details can be checked at Wikipedia: http://en.wikipedia.org/wiki/ISO_8583

Bitmaps: 
Within ISO-8583, a bitmap is a field or subfield within a message which indicates which other data elements 
or data element subfields are present in a message. A message will contain at least one bitmap, 
called the Primary Bitmap which indicates which of Data Elements 1 to 64 are present. A secondary bitmap may 
also be present, generally as data element one and indicates which of data elements 65 to 128 are present. 
Similarly, a tertiary, but these are rarely used. In most of the messages Primary bitmap is enough.

The bitmap may be transmitted as 8 bytes of binary data, or as 16 hexadecimal characters 0-9, A-F. A field is 
present only when the specific bit in the bitmap is true. For example, 
byte '82x is binary '1000 0010' which means fields 1 and 7 are present in the message and fields 2, 3, 4, 5, 6, 
and 8 are not present. More details can be checked at Wikipedia: http://en.wikipedia.org/wiki/ISO_8583

Data Elements:
 Data Elements are the essence of the whole ISO message, which contains information about the transaction 
 (transaction type, amount, customer id, etc). 
 Data elements are the individual fields carrying the transaction information. There are up to 128 data 
 elements specified in the original ISO 8583:1987 standard, and up to 192 data elements in later releases.
 The 1993 revision added new definitions, deleted some, while leaving the message format itself unchanged. 
 Each data element have their own format, attribute and length. Each data element number also have standard 
 purpose, for example DE #4 is transaction amount.
 
 I am explaining below based on the example above. Check Wikipedia link given above again for full list.
 Each data element is designed to have a fixed set of either numeric, alpha numeric or variable character
 sets. These are called data type for each data element. Below are few abbreviations and meanings:

 a         Alpha, including blanks
 n         Numeric values only
 s         Special characters only
 an     Alphanumeric
 as     Alpha & special characters only
 ns     Numeric and special characters only
 ans     Alphabetic, numeric and special characters.
 b         Binary data
 z         Tracks 2 and 3 code set as defined in ISO/IEC 7813 and ISO/IEC 4909 respectively
 . or .. or ...     variable field length indicator, each . indicating a digit.
 x or xx or xxx     fixed length of field or maximum length in the case of variable length fields.

So, 
 DE6     n 12     Amount, cardholder billing with fixed 12 digits.
 DE7     n 10     Transmission date & time with fixed 10 digits.
 DE32     n ..11     Acquiring institution identification code with variable length. In our system: 100035.
 DE39     an 2     Response code, In our system: 00-Success, any other-Failure.
 
Now Few Data Elements name and details are given below: 
 DE32 = AcquirerId;
 DE41 = TID;
 DE42 = MID;
 DE49 = 356;
 DE3 = Processing code;
 DE4 = Transaction amount;
 DE7 – Transmission date & time (10 digits);
 DE11 – Systems trace audit number (STAN- 6 digits);
 DE44 – Additional response data;
 DE105 – Reserved for ISO use;

To make it practical let’s use an example. We want to send:
    DE3 : 201234
    DE4 : 10000
    DE7 : 1107221830
    DE11 : 123456
    DE44 : A5DFGR
    DE32 : 100035
    DE105 : ABCDEFGHIJ 1234567890

So now you will have a large bit pattern holding these values, that I don't want to display this.
By the way there is an open source Tool/Jar called JPOS Library which does this conversion. So we 
just use that Jar and set these attributes based on Data elements position in Code. 

Next I will write article about implementing ISO-8583 using JPOS library.

-----------------------------END-----------------------------

2 comments:

  1. Hi Deepak,

    I am new in s/w field and i am trying to make transaction b/w my device to bank but every time when i run my program i am facing this exception
    Exception in thread "main" org.jpos.iso.ISOException: java.io.FileNotFoundException: C:\workspace\ISO8586\genericpackager.dtd (The system cannot find the file specified) (java.io.FileNotFoundException: C:\workspace\ISO8586\genericpackager.dtd (The system cannot find the file specified))
    at org.jpos.iso.packager.GenericPackager.readFile(GenericPackager.java:183)
    at org.jpos.iso.packager.GenericPackager.(GenericPackager.java:110)
    at com.bank.iso8586.ParseISOMessage.main(ParseISOMessage.java:11)

    i am not getting understand where and how to make .dtd file in my eclipse core java project plz help me ..

    thanks

    ReplyDelete
  2. Check this link, I have written genericpackager.dtd, search in the below link:

    http://deepakmodi2006.blogspot.in/2012/05/iso-message-packing-and-un-packing.html

    ReplyDelete