How to process MasterCard IPM File

3,084 views
Skip to first unread message

Ramses Vidor

unread,
Mar 25, 2014, 7:31:06 PM3/25/14
to jpos-...@googlegroups.com
Hi,


I'm trying to parse a MasterCard IPM file using jPOS, but I have no clue on how to achieve this.

What I tried so far:
1. Configured the GenericPackager with an xml file according to the specs from MasterCard IPM Format doc. It looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE isopackager PUBLIC
        "-//jPOS/jPOS Generic Packager DTD 1.0//EN"

<isopackager>
    <isofield id="0" length="4"  name="MIT" class="org.jpos.iso.IFE_NUMERIC" />
    <isofield id="1" length="16" name="Bit Map" class="org.jpos.iso.IFE_BITMAP" />
    <isofield id="2" length="19" name="PAN" class="org.jpos.iso.IFE_LLNUM" pad="false" />
    <isofield id="3" length="6"  name="Processing Code" class="org.jpos.iso.IFE_NUMERIC" pad="true" />
    <isofield id="4" length="12" name="Transaction Amount" class="org.jpos.iso.IFE_NUMERIC" pad="true" />
    <isofield id="5" length="12" name="Settlement Amount" class="org.jpos.iso.IFE_NUMERIC" pad="true" />
    <isofield id="6" length="12" name="Cardholder Billing Amount" class="org.jpos.iso.IFE_NUMERIC" pad="true" />
    [...]
</isopackager>


2. When I execute the following code:

ISOMsg message = new ISOMsg();
message.setPackager(new GenericPackager("path/to/my/config.xml");
message.unpack(myIPMFileBytes);

for (Entry<Integer, ISOComponent> transaction : ((Map<Integer, ISOComponent>) message.getChildren()).entrySet()) {
    System.out.println(MessageFormat.format("{0} : {1}", transaction.getKey(), transaction.getValue().getValue()));
}

3. The output generated from this snippet is:

-1 : {1, 2, 3, 4, 5, 6, 7, 8, 12, 14, 15, 18, 22, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 93, 96, 98, 99, 100, 106, 120, 126, 128}
0 : 0000
2 : 50
3 : 011310
4 : 230000001488
5 : 101101012200
6 : 1T00000001

It doesn't seem to be right, as the MTI is coming as 0000 and not all fields I need to extract data from are listed in the bit map (DE2, DE3, DE5, DE6, DE12, DE24, DE31, DE48/PDS147, PDS159, PDS0105 and PDS0195).

What am I doing wrong here?


Thanks,
Ramses

Mark Salter

unread,
Mar 25, 2014, 8:38:35 PM3/25/14
to jpos-...@googlegroups.com
On 25/03/2014 23:31, Ramses Vidor wrote:
>
> What I tried so far:
> 1. Configured the GenericPackager with an xml file according to the
> specs from MasterCard IPM Format doc. It looks like this:
Ok


> 2. When I execute the following code:
>
> |
> ISOMsg message = new ISOMsg();
> message.setPackager(new GenericPackager("path/to/my/config.xml");
> message.unpack(myIPMFileBytes);
How do you form 'myIPMFileBytes' ?
Is it the first data record in the file?
Do these bytes have any structure?
Is there a header?, can you share a sample of the data?

>
> for (Entry<Integer, ISOComponent> transaction : ((Map<Integer,
> ISOComponent>) message.getChildren()).entrySet()) {
> System.out.println(MessageFormat.format("{0} : {1}",
> transaction.getKey(), transaction.getValue().getValue()));
> }
> |
message.dump might be easier to 'read'?
>
> 3. The output generated from this snippet is:
>
> |
> -1 : {1, 2, 3, 4, 5, 6, 7, 8, 12, 14, 15, 18, 22, 25, 26, 27, 28, 29,
> 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
> 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65,
> 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
> 84, 85, 86, 87, 88, 90, 91, 93, 96, 98, 99, 100, 106, 120, 126, 128}
> 0 : 0000
> 2 : 50
> 3 : 011310
> 4 : 230000001488
> 5 : 101101012200
> 6 : 1T00000001
> |
>
> It doesn't seem to be right, as the MTI is coming as 0000 and not all
> fields I need to extract data from are listed in the bit map (DE2, DE3,
> DE5, DE6, DE12, DE24, DE31, DE48/PDS147, PDS159, PDS0105 and PDS0195).
The bytes that have been taken as the bitmap are not correct...
>
> What am I doing wrong here?
The bytes you are giving to the unpack do not match the form defined by
your packager.

The contents of 'myIPMFileBytes' *have* to be just a single message
*and* their structure needs to match that defined by the Packager (or
vice versa).


--
Mark

Ramses Vidor

unread,
Mar 25, 2014, 9:17:16 PM3/25/14
to jpos-...@googlegroups.com
Hi Mark!


Thanks for your response. The output from the dump is:

<isomsg>
  <field id="0" value="0000"/>
  <field id="2" value="50"/>
  <field id="3" value="011310"/>
  <field id="4" value="230000001488"/>
  <field id="5" value="101101012200"/>
  <field id="6" value="1T00000001&#0;&#0;"/>
</isomsg>

Answering your questions:

Q: How do you form 'myIPMFileBytes'?
A: This is how I read the bytes from the file:

File file = new File("path/to/myIPMFile.ipm");
myIPMFileBytes = new byte[(int) file.length()];
InputStream in = new FileInputStream(file);
in.read(myIPMFileBytes);
in.close();


Q: Is it the first data record in the file? Do these bytes have any structure? Is there a header? Can you share a sample of the data?
R: I really don't know about these things. I only know the file is encoded with EBCDIC and I read the bytes directly from it. I also know that there are more fields on it, I only didn't configure all of them, as I saw that data in the first fields are not logical for me. I'm not sure if I can share the original file, but I can ask for permission to share it with you.

Well, I never implemented anything like this before, so I'm sure I'm missing something (if not everything).


Thanks,
Ramses

Mark Salter

unread,
Mar 26, 2014, 3:38:45 AM3/26/14
to jpos-...@googlegroups.com
On 26/03/2014 01:17, Ramses Vidor wrote:

> Thanks for your response. The output from the dump is:
>
> |
> <isomsg>
> <field id="0" value="0000"/>
> <field id="2" value="50"/>
> <field id="3" value="011310"/>
> <field id="4" value="230000001488"/>
> <field id="5" value="101101012200"/>
> <field id="6" value="1T00000001&#0;&#0;"/>
> </isomsg>
> |
Yes, I thought it would match, I was just letting you know about the
method to allow you to replace some of your code :-)

>
> Answering your questions:
>
> Q: How do you form 'myIPMFileBytes'?
> A: This is how I read the bytes from the file:
>
> |
> File file = new File("path/to/myIPMFile.ipm");
> myIPMFileBytes = new byte[(int) file.length()];
> InputStream in = new FileInputStream(file);
> in.read(myIPMFileBytes);
> in.close();
You will need to get the data a record at a time, strip of any file
headers or trailers, remove each record header (if there is one) since
in normal network flow, it is the Channel that deals with these and pass
the single record into your unpack.

>
> |
>
> Q: Is it the first data record in the file? Do these bytes have any
> structure? Is there a header? Can you share a sample of the data?
> R: I really don't know about these things.
Ok, then you need to read the documentation from MasterCard to determine
this.

> I only know the file is
> encoded with EBCDIC and I read the bytes directly from it. I also know
> that there are more fields on it, I only didn't configure all of them,
> as I saw that data in the first fields are not logical for me.
Ok, but you do intend to define the whole set of fields (including the
ones that are conditionally present yes?

> I'm not
> sure if I can share the original file, but I can ask for permission to
> share it with you.
That's fine. Please get and read all the specifications of the file you
can get to find the file structure and in turn the record structure you
are wishing to process.

I have to think that close by the field definitions that you used for
your Packager will be the file definitions.

--
Mark

Ramses Vidor

unread,
Mar 27, 2014, 12:57:40 PM3/27/14
to jpos-...@googlegroups.com
Well, no success so far.

Now, I have a file with a single message. If I open the file, I can see that it's ok. The unpacked bit map content by jPOS is not what I see in the file if I open it in an hex editor.

I attached the file. The implementation is the same I described before.
test.ipm

Ramses Vidor

unread,
Mar 27, 2014, 1:13:36 PM3/27/14
to jpos-...@googlegroups.com
Just to clearify what's happening with this file:

jPOS unpacked Bit Map: {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ...}

<isomsg>
  <field id="0" value="1240"/>
  <field id="2" value="0000000000000"/>
  <field id="3" value="060000"/>
  <field id="4" value="000000060000"/>
  <field id="5" value="000000060006"/>
  <field id="6" value="100000061000"/>
</isomsg>

According to the file content, the expected result should be:

Bit map hex: FC D4 07 C3 8C E1 E2 02 02 00 00 0C 10 00 00 00
Hex converted to binary: 1111110011010100...
Bit map content: {1, 2, 3, 4, 5, 6, 9, 10, 12, 14, ...}

<isomsg>
  <field id="0" value="1240"/>
  <field id="2" value="5345207000018113"/>
  <field id="3" value="000000"/>
  <field id="4" value="000000006000"/>
  <field id="5" value="000000006000"/>
  <field id="6" value="000000006000"/>
</isomsg>


Regards,
Ramses

Mark Salter

unread,
Mar 27, 2014, 6:33:55 PM3/27/14
to jpos-...@googlegroups.com
On 27/03/2014 16:57, Ramses Vidor wrote:
> Well, no success so far.
What have you changed?

Nothing?

>
> Now, I have a file with a single message. If I open the file, I can see
> that it's ok.
I can see ASCII data and a binary bitmap, which does not match your
packager.

> The unpacked bit map content by jPOS is not what I see in
> the file if I open it in an hex editor.
You need to make a Packager that matches the file, otherwise all bets
are off.

Please take note and apply my previous guidance. What you are trying to
achieve is possible, you simply need to do the work on using the file
specification and documentation to produce a Packager - that's all.

--
Mark

Ramses Vidor

unread,
Mar 27, 2014, 7:21:58 PM3/27/14
to jpos-...@googlegroups.com
Mark,


Indeed! I figured out that the bitmap was not unpacking correctly and changed to IFB_BITMAP and voilá!

Got it to work now.

Thanks for all your help and support, dude!


Ramses

Mark Salter

unread,
Mar 27, 2014, 7:23:52 PM3/27/14
to jpos-...@googlegroups.com
On 27/03/2014 23:21, Ramses Vidor wrote:
> Indeed! I figured out that the bitmap was not unpacking correctly and
> changed to IFB_BITMAP and voilá!
>
> Got it to work now.
How did you get the ASCII/EBCDIC difference sorted?
>
> Thanks for all your help and support, dude!
No problem, did you have a working Packager to share at all?

:-)

--
Mark

rishi raj

unread,
May 24, 2017, 8:00:19 AM5/24/17
to jPOS Users
Hi Mark
if i am passing the whole input stream in unpack method it is parsing only first data in ipm file.
can you guide me how to deal with this issue?
As i am new to this Jpos.

Alejandro Revilla

unread,
May 24, 2017, 8:15:12 AM5/24/17
to jPOS Users
There's a length indicator in every record, you need to read that length, then call unpack, then read your next record length and so on.


rishi raj

unread,
May 26, 2017, 1:50:34 AM5/26/17
to jPOS Users
Thanks Alejandro one more question for you if iso message is in multipart how to deal with that using jpos.

Alejandro Revilla

unread,
May 26, 2017, 5:20:00 PM5/26/17
to jPOS Users
You need to concat them first.


Reply all
Reply to author
Forward
0 new messages