Ejemplo n.º 1
0
        private static void ParseTrack3Data(ref MagCard card, string track3Data)
        {
            //throw new NotImplementedException();

            //No op. Drop data on the floor
        }
Ejemplo n.º 2
0
        private static void ParseTrack2Data(ref MagCard card, string track2Data)
        {
            string[] tokenized = track2Data.Split(_track2FieldSeparator);

            if (tokenized.Length != 2)
            {
                throw new InvalidDataException("Track 2 data has invalid format! Data: " + track2Data);
            }

            string track2PrimaryAccountNumber = tokenized[0];

            if (!string.IsNullOrEmpty(track2PrimaryAccountNumber) &&
                (null == card.PrimaryAccountNumber || !track2PrimaryAccountNumber.Equals(card.PrimaryAccountNumber)))
            {
                card.PrimaryAccountNumber = track2PrimaryAccountNumber;
            }

            string expirationEtc = tokenized[1];

            string track2ExpirationDate = ParseExpirationDate(expirationEtc);

            if (!string.IsNullOrEmpty(track2ExpirationDate) &&
                (null == card.ExpirationDate || !track2ExpirationDate.Equals(card.ExpirationDate)))
            {
                card.ExpirationDate = track2ExpirationDate;
            }

            string track2ServiceCode = ParseServiceCode(expirationEtc);

            if (!string.IsNullOrEmpty(track2ServiceCode) &&
                (null == card.ServiceCode || !track2ServiceCode.Equals(card.ServiceCode)))
            {
                card.ServiceCode = track2ServiceCode;
            }

            string track2DiscretionaryData = ParseDiscretionaryData(expirationEtc);

            if (!string.IsNullOrEmpty(track2DiscretionaryData) &&
                (null == card.DiscretionaryData.Track2 ||
                 !track2DiscretionaryData.Equals(card.DiscretionaryData.Track2)))
            {
                card.DiscretionaryData.Track2 = track2DiscretionaryData;
            }
        }
Ejemplo n.º 3
0
        private static void ParseTrack1Data(ref MagCard card, string track1Data)
        {
            string[] tokenized = track1Data.Split(_track1FieldSeparator);

            card.PrimaryAccountNumber = tokenized[0];

            ParseNameComponents(ref card, tokenized[1]);

            string expirationEtc = tokenized[2];

            card.ExpirationDate = ParseExpirationDate(expirationEtc);
            card.ServiceCode = ParseServiceCode(expirationEtc);
            card.DiscretionaryData.Track1 = ParseDiscretionaryData(expirationEtc);

            // DEBUG
            System.Diagnostics.Debug.Assert(string.Concat(card.ExpirationDate,
                                                          card.ServiceCode,
                                                          card.DiscretionaryData).Equals(expirationEtc));
            // END DEBUG
        }
Ejemplo n.º 4
0
        private static void ParseNameComponents(ref MagCard card, string fullName)
        {
            card.Name = fullName;

            string[] nameComponents = card.Name.Split(NAME_SEPARATOR_CHAR);

            if (nameComponents.Length > 0)
            {
                card.LastName = nameComponents[0].Trim();

                if (nameComponents.Length > 1)
                {
                    string[] firstNameMiddleInitial = nameComponents[1].Split(INITIAL_SEPARATOR_CHAR);

                    if (firstNameMiddleInitial.Length > 0)
                    {
                        card.FirstName = firstNameMiddleInitial[0].Trim();

                        if (firstNameMiddleInitial.Length > 1)
                        {
                            card.MiddleInitial = firstNameMiddleInitial[1].Trim();
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static void ParseData(ref MagCard card, string magCardData)
        {
            string[] tracks = magCardData.Split(new char[] {_trackEndSentinel}, StringSplitOptions.None);

            foreach (string track in tracks)
            {
                if (track.Length < 1)
                {
                    continue;
                }

                char firstChar = track[0];

                if (firstChar.Equals(_track1StartSentinel))
                {
                    ParseTrack1Data(ref card, track.TrimStart(_track1StartSentinel).TrimStart(_formatCode));
                }
                else if (firstChar.Equals(_track2StartSentinel))
                {
                    ParseTrack2Data(ref card, track.TrimStart(_track2StartSentinel));
                }
                else
                {
                    ParseTrack3Data(ref card, track);
                }
            }
        }
Ejemplo n.º 6
0
        public static MagCard Parse(string magCardData)
        {
            if (string.IsNullOrEmpty(magCardData))
            {
                throw new ArgumentException("No data to parse!", magCardData);
            }

            MagCard card = new MagCard();

            try
            {
                MagCard.ParseData(ref card, magCardData);
            }
            catch (Exception ex)
            {
                throw new ArgumentException("Invalid Magnetic Card Data!", ex);
            }

            return card;
        }