moov-io / iso8583

A golang implementation to marshal and unmarshal iso8583 message.
https://moov.io
Apache License 2.0
353 stars 105 forks source link

odd value parsing issue in ISOMessage #327

Open anilgorgec opened 6 days ago

anilgorgec commented 6 days ago

Hello,

I have a question regarding odd numbers. for example the Track 2 Data field has a length of 37 characters, which is an odd number. Since ISO 8583 messages are often processed in hexadecimal or BCD format, they need to be byte-aligned.

I tried to parse the iso message in the example below.but I could not get the output as expected output.

Can you help me with this issue?

ISO Message: 020030200580208000000000000000000015001079890071002100375111111211111111d11110000000000000000f5445535430303031

output

MTI..........: 0200
Bitmap HEX...: 3020058020800000
Bitmap bits..:
    [1-8]00110000    [9-16]00100000   [17-24]00000101   [25-32]10000000
  [33-40]00100000   [41-48]10000000   [49-56]00000000   [57-64]00000000
F0   Message Type Indicator.................: 0200
F3   Processing Code........................: 0
F4   Transaction Amount.....................: 1500
F11  Systems Trace Audit Number (STAN)......: 107989
F22  Point of Sale (POS) Entry Mode.........: 007
F24  Function Code..........................: 100
F25  Point of Service Condition Code........: 21
F35  Track 2 Data...........................: =^^
F41  Card Acceptor Terminal Identification..: 37511111

expected output


MTI..........: 0200
Bitmap HEX...: 3020058020800000
Bitmap bits..:
    [1-8]00110000    [9-16]00100000   [17-24]00000101   [25-32]10000000
  [33-40]00100000   [41-48]10000000   [49-56]00000000   [57-64]00000000
F0   Message Type Indicator.................: 0200
F3   Processing Code........................: 0
F4   Transaction Amount.....................: 1500
F11  Systems Trace Audit Number (STAN)......: 107989
F22  Point of Sale (POS) Entry Mode.........: 0071
F24  Function Code..........................: 0021
F25  Point of Service Condition Code........: 00
F35  Track 2 Data...........................: 5111111211111111d11110000000000000000
F41  Card Acceptor Terminal Identification..: TEST0001 ```
alovak commented 1 day ago

Could you please share your (Go) spec here?

carlosmgc2003 commented 21 hours ago

I've had exactly this problem and solved it by creating a custom Hex field and a custom BCD prefix:

        35: custom.NewTrack2(&field.Spec{
            Length:      37,
            Description: "Track 2 Data",
            Enc:         encoding.Binary,
            Pref:        custom.BCD.LL,
        }),

I could'nt manage to use moov/iso8583 built in types (perhaps it is possible to do so). I can share you this implementation here if you want and moderators allow.

anilgorgec commented 21 hours ago

Could you please share your (Go) spec here?

The spec is as follows.

var Spec87 = &iso8583.MessageSpec{
    Name: "ISO",
    Fields: map[int]field.Field{
        0: field.NewString(&field.Spec{
            Length:      4,
            Description: "Message Type Indicator",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        1: field.NewBitmap(&field.Spec{
            Length:      8,
            Description: "Bitmap",
            Enc:         encoding.BytesToASCIIHex,
            Pref:        prefix.Hex.Fixed,
        }),
        3: field.NewNumeric(&field.Spec{
            Length:      6,
            Description: "Processing Code",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        4: field.NewString(&field.Spec{
            Length:      12,
            Description: "Transaction Amount",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
            Pad:         padding.Left('0'),
        }),

        11: field.NewString(&field.Spec{
            Length:      6,
            Description: "Systems Trace Audit Number (STAN)",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        12: field.NewString(&field.Spec{
            Length:      6,
            Description: "Local Transaction Time",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        13: field.NewString(&field.Spec{
            Length:      4,
            Description: "Local Transaction Date",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        22: field.NewString(&field.Spec{
            Length:      3,
            Description: "Point of Sale (POS) Entry Mode",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),

        24: field.NewString(&field.Spec{
            Length:      3,
            Description: "Function Code",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        25: field.NewString(&field.Spec{
            Length:      2,
            Description: "Point of Service Condition Code",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
        35: field.NewTrack2(&field.Spec{
            Length:      37,
            Description: "Track 2 Data",
            Enc:         encoding.ASCIIHexToBytes,
            Pref:        prefix.ASCII.LL,
        }),
        41: field.NewString(&field.Spec{
            Length:      8,
            Description: "Card Acceptor Terminal Identification",
            Enc:         encoding.ASCII,
            Pref:        prefix.ASCII.Fixed,
        }),
    },
}
anilgorgec commented 20 hours ago

I've had exactly this problem and solved it by creating a custom Hex field and a custom BCD prefix:

      35: custom.NewTrack2(&field.Spec{
          Length:      37,
          Description: "Track 2 Data",
          Enc:         encoding.Binary,
          Pref:        custom.BCD.LL,
      }),

I could'nt manage to use moov/iso8583 built in types (perhaps it is possible to do so). I can share you this implementation here if you want and moderators allow.

if they allows, I wanna see it. It will give idea at least.