Example #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(TanRequest tanDialog)
        {
            HBCIDialogResult result = await InitializeConnection();

            if (result.HasError)
            {
                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.HasError)
            {
                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));
        }
Example #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(':');
                if (hisalAccountParts.Length == 4)
                {
                    balance.AccountType = new AccountInformation()
                    {
                        AccountNumber   = hisalAccountParts[0],
                        AccountBankCode = hisalAccountParts.Length > 3 ? hisalAccountParts[3] : null,
                        AccountType     = hisalParts[2],
                        AccountCurrency = hisalParts[3],
                        AccountBic      = !string.IsNullOrEmpty(hisalAccountParts[1]) ? hisalAccountParts[1] : null
                    };
                }
                else if (hisalAccountParts.Length == 2)
                {
                    balance.AccountType = new AccountInformation()
                    {
                        AccountIban = hisalAccountParts[0],
                        AccountBic  = hisalAccountParts[1]
                    };
                }

                var hisalBalanceParts = hisalParts[4].Split(':');
                if (hisalBalanceParts[1].IndexOf("e-9", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    balance.Balance = 0; // Deutsche Bank liefert manchmal "E-9", wenn der Kontostand 0 ist. Siehe Test_Parse_Balance und https://homebanking-hilfe.de/forum/topic.php?t=24155
                }
                else
                {
                    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 && hisalParts[5].Contains(":"))
                {
                    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);
        }