Esempio n. 1
0
        public override PrivatbankAccountStatement Parse(string xml)
        {
            XmlDocument document = new XmlDocument();

            document.LoadXml(xml);
            XmlNode statementsNode = document.SelectSingleNode("response/data/info/statements");

            string      status       = GetAttributeText(statementsNode, "status");
            string      creditString = GetAttributeText(statementsNode, "credit");
            string      debetString  = GetAttributeText(statementsNode, "debet");
            XmlNodeList statements   = statementsNode.ChildNodes;

            decimal?credit = NullableDecimalConverter.Convert(creditString);
            decimal?debet  = NullableDecimalConverter.Convert(debetString);
            List <PrivatbankAccountTransaction> items = ParseItems(statements);

            return(new PrivatbankAccountStatement(status, credit, debet, items));
        }
Esempio n. 2
0
        /// <summary>
        /// Parses amount string returned by Privatbank API.
        /// Returns null if failed to parse currency or value.
        /// </summary>
        /// <param name="amount">Amount string in format '-0.10 UAH'</param>
        /// <returns></returns>
        public override PrivatbankAmount Parse(string s)
        {
            if (string.IsNullOrWhiteSpace(s))
            {
                return(null);
            }

            string[] amountParts = s.Split(' ');

            if (amountParts.Length != 2)
            {
                return(null);
            }

            string  currency = ISO4217CurrencyCompatibility.GetActive(amountParts[1]);
            decimal?amount   = NullableDecimalConverter.Convert(amountParts[0]);

            if (string.IsNullOrWhiteSpace(currency) || !amount.HasValue)
            {
                return(null);
            }

            return(new PrivatbankAmount(currency, amount.Value));
        }