Ejemplo n.º 1
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
            };
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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"),
            };
        }
Ejemplo n.º 4
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")
            };
        }
Ejemplo n.º 5
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"))
            };
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
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")
            };
        }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }