Esempio n. 1
0
        public static AuthorizationResponse Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "authorizationresult")
                throw new InvalidOperationException($"Expected AuthorizationResult message but received {reader.RootTag} message");

            AuthorizationResponse result = new AuthorizationResponse
            {
                AuthorizationId = reader.GetValue("id"),
                DocumentNumber = reader.GetValue("docnr"),
                Approved = reader.GetValue("result") == "OK",
                Text = reader.GetValue("txt"),
                CardToken = reader.GetValue("token"),
                AuthorizationCode = reader.GetValue("authcode"),
                Rrn = reader.GetValue("rrn"),
                Stan = reader.GetValue("stan"),
                CardType = reader.GetValue("cardtype"),
            };

            if (!result.Approved)
                return result;

            string amount = reader.GetValue("amount");
            long amt;
            if (long.TryParse(amount, out amt))
                result.Amount = amt;

            return result;
        }
Esempio n. 2
0
        public static GetPromptInput Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "getpromptinput")
                throw new InvalidOperationException($"Expected GetPromptInput message but received {reader.RootTag} message");

            string reasonString = reader.GetValue("reason");
            if (string.IsNullOrEmpty(reasonString))
                throw new Exception("GetPromptInput has no reason field");

            PromptReasons reason;
            switch (reasonString.ToUpper())
            {
                case "SUM": reason = PromptReasons.Amount; break;
                case "LFD": reason = PromptReasons.Last4Digits; break;
                case "MPN": reason = PromptReasons.MobilePhoneNumber; break;
                case "BAR": reason = PromptReasons.Barcode; break;
                default: throw new NotSupportedException($"GetPromptInput has not supported reason [{reasonString}]");
            }

            return new GetPromptInput
            {
                Text = reader.GetValue("prompt"),
                Rerason = reason
            };
        }
Esempio n. 3
0
        public static LoginRequest Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "login")
                throw new InvalidOperationException($"Expected Login message but received {reader.RootTag} message");

            LoginRequest login = Create(reader.GetValue("lang"), reader.GetValue("idletext"));
            login.Flags.AddFlagsList(reader.GetValue("flags"));

            return login;
        }
Esempio n. 4
0
        public static CardRemoved Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "cardremoved")
                throw new InvalidOperationException($"Expected CardRemoved message but received {reader.RootTag} message");

            return new CardRemoved
            {
                Time = DateTime.ParseExact(reader.GetValue("time"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None),
                Token = reader.GetValue("token"),
            };
        }
Esempio n. 5
0
        public static DocClosedRequest Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "docclosed")
                throw new InvalidOperationException($"Expected DocClosed message but received {reader.RootTag} message");

            return new DocClosedRequest
            {
                DocumentNumber = reader.GetValue("docnr"),
                AuthorizationId = reader.GetValue("authid")
            };
        }
Esempio n. 6
0
        public static PrintReceipt Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "printreceipt")
                throw new InvalidOperationException($"Expected PrintReceipt message but received {reader.RootTag} message");

            return new PrintReceipt
            {
                ReceiptId = reader.GetValue("id"),
                DocumentNumber = reader.GetValue("docnr"),
                ReceiptText = reader.GetValue("receipttext"),
                Flags = new Flags(reader.GetValue("flags"))
            };
        }
Esempio n. 7
0
        public static CardReader Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "cardreader")
                throw new InvalidOperationException($"Expected CardReader message but received {reader.RootTag} message");

            CardReader result = new CardReader
            {
                Time = DateTime.ParseExact(reader.GetValue("time"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None),
                Token = reader.GetValue("token"),
                Flags = new Flags(reader.GetValue("flags")),
                CardType = reader.GetValue("cardtype")
            };

            string cardReadMethod = reader.GetValue("crm");
            if (string.IsNullOrEmpty(cardReadMethod)) return result;

            switch (cardReadMethod.ToUpper())
            {
                case "INS":
                    result.CardReadMethod = CardReadMethods.Chip;
                    break;
                case "SWP":
                    result.CardReadMethod = CardReadMethods.Magnetic;
                    break;
                case "NFC":
                    result.CardReadMethod = CardReadMethods.Nfc;
                    break;
                case "MAN":
                    result.CardReadMethod = CardReadMethods.Manually;
                    break;
            }

            return result;
        }
Esempio n. 8
0
        public void Process(byte[] receivedData)
        {
            Ensure.NotNull(receivedData, nameof(receivedData));

            byte messageType = AsyncPosPacket.GetType(receivedData);
            switch (messageType)
            {
                case 0x00:
                case 0x01:
                    {
                        string packetId = AsyncPosPacket.GetId(receivedData);
                        Log.Info("Received message from Ped, length {0} bytes, packet type 0x{1}, Id {2} {3} {4}", receivedData.Length, messageType.ToString("X2"), packetId, Environment.NewLine, AsyncPosPacket.DumpF0(AsyncPosPacket.GetMsg(receivedData)));

                        string posId = AsyncPosPacket.GetPosId(receivedData);
                        if (PedId != posId)
                        {
                            Log.Error("Received posid '{1}' does not match expected '{0}'", PedId, posId);
                            return;
                        }

                        if (!AsyncPosPacket.CheckSignature(receivedData, 0, _apak))
                        {
                            Log.Error("APAK does not match");
                            _pedHub.SendData(PedId, AsyncPosPacket.PrependLength(AsyncPosPacket.BuildNak(receivedData)));
                            return;
                        }

                        Format0Reader receivedMessageReader = new Format0Reader(AsyncPosPacket.GetMsg(receivedData));
                        _pedEvents.FireEvent(receivedMessageReader.RootTag, receivedMessageReader);

                        _pedHub.SendData(PedId, AsyncPosPacket.PrependLength(AsyncPosPacket.BuildAck(receivedData)));

                        switch (receivedMessageReader.RootTag)
                        {
                            case "printreceipt":
                                {
                                    PrintReceipt printReceipt = PrintReceipt.Deserialize(new Format0Reader(AsyncPosPacket.GetMsg(receivedData)));
                                    SendPrintResult(printReceipt.ReceiptId, printReceipt.DocumentNumber);
                                    break;
                                }
                        }
                        break;
                    }

                case 0x0A:
                    {
                        string packetId = AsyncPosPacket.GetId(receivedData);
                        Log.Info("ACK from PED, Id {0}", packetId);

                        _pedEvents.FireEvent(AsyncPosEventTypes.Ack.ToString(), null);
                        break;
                    }
                case 0x0F:
                    {
                        string packetId = AsyncPosPacket.GetId(receivedData);
                        Log.Info("NAK from PED, Id {0}", packetId);

                        _pedEvents.FireEvent(AsyncPosEventTypes.Nak.ToString(), null);
                        break;
                    }

                default:
                    Log.Warn("Ignoring packet 0x{0}", messageType.ToString("X2"));
                    break;
            }
        }
Esempio n. 9
0
        public static AuthorizationRequest Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "authorize")
                throw new InvalidOperationException($"Expected authorize message but received {reader.RootTag} message");

            string cashAmount = reader.GetValue("cash");
            return new AuthorizationRequest
            {
                Amount = Int64.Parse(reader.GetValue("amount")),
                Cash = string.IsNullOrEmpty(cashAmount) ? 0 : long.Parse(cashAmount),
                Currency = Int32.Parse(reader.GetValue("currency")),
                DocumentNumber = reader.GetValue("docnr"),
                Time = DateTime.ParseExact(reader.GetValue("time"), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
                Language = reader.GetValue("lang")
            };
        }
Esempio n. 10
0
        public static DisplayText Deserialize(Format0Reader reader)
        {
            Ensure.NotNull(reader, nameof(reader));

            if (reader.RootTag != "displaytext")
                throw new InvalidOperationException($"Expected DisplayText message but received {reader.RootTag} message");

            DisplayText result = new DisplayText { Text = reader.GetValue("txt") };

            string reason = reader.GetValue("reason");
            if (string.IsNullOrEmpty(reason)) return result;

            int reasonNum;
            if (!int.TryParse(reason, out reasonNum)) return result;

            result.Reason = (DisplayTextReasons)reasonNum;
            return result;
        }
Esempio n. 11
0
 public static string DumpF0(Format0Reader msg)
 {
     return msg.Dump();
 }