a2800276 / 8583

ruby implementation of iso 8583 financial messages
http://www.kuriositaet.de
MIT License
41 stars 44 forks source link

Message.parse (Serialize - Deserialize Message) Question #4

Closed dlbirch closed 9 years ago

dlbirch commented 11 years ago

Hello,

I have a question about how to take a message instance, serialize it (via to_b or to_s) and then, read that back into a message via Message.parse.

So, for the following message:

require 'iso8583'

module ISO8583

class Ums_Message < Message mti_format N, :length => 4 mti 1100, "Authorization Request Acquirer Gateway"

bmp  2, "Primary Account Number (PAN)",               LLVAR_N,   :max    => 19
bmp  3, "Processing Code",                            N,         :length =>  6

bmp_alias  2, :pan
bmp_alias  3, :proc_code

end

end

I run this code and it breaks with the error message at the bottom. What am I doing wrong?

mes = ISO8583::Ums_Message.new("Reversal Advice Repeat Acquirer Gateway") mes[2] = 1234567890123456789 mes["Processing Code"] = "123456"

outbound_msg_str = mes.to_s #serialize to a string outbound_msg = ISO8583::Ums_Message.new("Reversal Advice Repeat Acquirer Gateway") #create new message instance outbound_msg = ISO8583::Ums_Message.parse outbound_msg_str #de-serialize into new instance

ISO8583::ISO8583Exception: MTI: 0 not allowed!

dlbirch commented 11 years ago

The class example I listed above left out the definition of: mti 1421, "Reversal Advice Repeat Acquirer Gateway"

it is in the class ... I just left it off when I copied it to this board.

dlbirch commented 11 years ago

Ok, I have this working ... I'm creating a message and sending it over a TCP/IP Socket and then re-constructing the message on the server.

From my client:

@client = TCPSocket.new(host, port) payload_bytes = payload.to_b @client.write(payload_bytes)

On the tcp server side:

payload = connection.read(msg_length[0]) message_received = ISO8583::Ums_Message.parse payload

a2800276 commented 11 years ago

Happy to hear you managed to sort it out! Only have a tablet to type. On til the weekend :-)