Пример #1
0
        /// <summary>
        /// Account balance
        /// </summary>
        /// <param name="tanDialog">The TAN Dialog</param>
        /// <returns>The balance for this account</returns>
        public async Task <HBCIDialogResult <AccountBalance> > Balance(TANDialog tanDialog)
        {
            HBCIDialogResult result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result.TypedResult <AccountBalance>());
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result.TypedResult <AccountBalance>());
            }

            // Success
            string BankCode = await Transaction.HKSAL(this);

            result = new HBCIDialogResult(Helper.Parse_BankCode(BankCode), BankCode);
            if (!result.IsSuccess)
            {
                return(result.TypedResult <AccountBalance>());
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result.TypedResult <AccountBalance>());
            }

            BankCode = result.RawData;
            AccountBalance balance = Helper.Parse_Balance(BankCode);

            return(result.TypedResult(balance));
        }
Пример #2
0
        /// <summary>
        /// Parse balance
        /// </summary>
        /// <param name="Message"></param>
        /// <returns></returns>
        public static AccountBalance Parse_Balance(string Message)
        {
            var hirms = Message.Substring(Message.IndexOf("HIRMS") + 5);

            hirms = hirms.Substring(0, (hirms.Contains("'") ? hirms.IndexOf('\'') : hirms.Length));
            var hirmsParts = hirms.Split(':');

            AccountBalance balance = new AccountBalance();

            balance.Message = hirmsParts[hirmsParts.Length - 1];

            if (Message.Contains("+0020::"))
            {
                var hisal = Message.Substring(Message.IndexOf("HISAL") + 5);
                hisal = hisal.Substring(0, (hisal.Contains("'") ? hisal.IndexOf('\'') : hisal.Length));
                var hisalParts = hisal.Split('+');

                balance.Successful = true;

                var hisalAccountParts = hisalParts[1].Split(':');
                balance.AccountType = new AccountInformations()
                {
                    Accountnumber   = hisalAccountParts[0],
                    Accountbankcode = hisalAccountParts.Length > 3 ? hisalAccountParts[3] : null,
                    Accounttype     = hisalParts[2],
                    Accountcurrency = hisalParts[3],
                    Accountbic      = !string.IsNullOrEmpty(hisalAccountParts[1]) ? hisalAccountParts[1] : null
                };

                var hisalBalanceParts = hisalParts[4].Split(':');
                balance.Balance = Convert.ToDecimal($"{(hisalBalanceParts[0] == "D" ? "-" : "")}{hisalBalanceParts[1]}");


                //from here on optional fields / see page 46 in "FinTS_3.0_Messages_Geschaeftsvorfaelle_2015-08-07_final_version.pdf"
                if (hisalParts.Length > 5)
                {
                    var hisalMarkedBalanceParts = hisalParts[5].Split(':');
                    balance.MarkedTransactions = Convert.ToDecimal($"{(hisalMarkedBalanceParts[0] == "D" ? "-" : "")}{hisalMarkedBalanceParts[1]}");
                }

                if (hisalParts.Length > 6 && hisalParts[6].Contains(":"))
                {
                    balance.CreditLine = Convert.ToDecimal(hisalParts[6].Split(':')[0].TrimEnd(','));
                }

                if (hisalParts.Length > 7 && hisalParts[7].Contains(":"))
                {
                    balance.AvailableBalance = Convert.ToDecimal(hisalParts[7].Split(':')[0].TrimEnd(','));
                }

                /* ---------------------------------------------------------------------------------------------------------
                 * In addition to the above fields, the following fields from HISAL could also be implemented:
                 *
                 * - 9/Bereits verfügter Betrag
                 * - 10/Überziehung
                 * - 11/Buchungszeitpunkt
                 * - 12/Fälligkeit
                 *
                 * Unfortunately I'm missing test samples. So I drop support unless we get test messages for this fields.
                 * ------------------------------------------------------------------------------------------------------------ */
            }
            else
            {
                balance.Successful = false;

                string msg = string.Empty;
                for (int i = 1; i < hirmsParts.Length; i++)
                {
                    msg = msg + "??" + hirmsParts[i].Replace("::", ": ");
                }
                Log.Write(msg);
            }

            return(balance);
        }