Esempio n. 1
0
        /// <summary>
        /// Retrieves the accounts for this client
        /// </summary>
        /// <param name="tanDialog">The TAN Dialog</param>
        /// <returns>Gets informations about the accounts</returns>
        public async Task <HBCIDialogResult <List <AccountInformation> > > Accounts(TANDialog tanDialog)
        {
            var result = await InitializeConnection();

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

            result = await ProcessSCA(result, tanDialog);

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

            return(new HBCIDialogResult <List <AccountInformation> >(result.Messages, UPD.Value, UPD.AccountList));
        }
Esempio n. 2
0
        private async Task <HBCIDialogResult> ProcessSCA(HBCIDialogResult result, TANDialog tanDialog)
        {
            tanDialog.DialogResult = result;
            if (result.IsSCARequired)
            {
                string tan = await Helper.WaitForTanAsync(this, result, tanDialog);

                if (tan == null)
                {
                    string BankCode = await Transaction.HKEND(this, HNHBK);

                    result = new HBCIDialogResult(Helper.Parse_BankCode(BankCode), BankCode);
                }
                else
                {
                    result = await TAN(tan);
                }
            }

            return(result);
        }
Esempio n. 3
0
        public async Task <HBCIDialogResult> ModifyBankersOrder(TANDialog tanDialog, string OrderId, string receiverName, string receiverIBAN,
                                                                string receiverBIC, decimal amount, string purpose, DateTime firstTimeExecutionDay, TimeUnit timeUnit, string rota,
                                                                int executionDay, DateTime?lastExecutionDay, string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKCDN(this, OrderId, receiverName, receiverIBAN, receiverBIC, amount, purpose, firstTimeExecutionDay, timeUnit, rota, executionDay, lastExecutionDay);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 4
0
        /// <summary>
        /// Collect money from another account - General method
        /// </summary>
        /// <param name="payerName">Name of the payer</param>
        /// <param name="payerIBAN">IBAN of the payer</param>
        /// <param name="payerBIC">BIC of the payer</param>
        /// <param name="amount">Amount to transfer</param>
        /// <param name="purpose">Short description of the transfer (dt. Verwendungszweck)</param>
        /// <param name="settlementDate"></param>
        /// <param name="mandateNumber"></param>
        /// <param name="mandateDate"></param>
        /// <param name="creditorIdNumber"></param>
        /// <param name="HIRMS">Numerical SecurityMode; e.g. 911 for "Sparkasse chipTan optisch"</param>
        /// <param name="pictureBox">Picturebox which shows the TAN</param>
        /// <param name="flickerImage">(Out) reference to an image object that shall receive the FlickerCode as GIF image</param>
        /// <param name="flickerWidth">Width of the flicker code</param>
        /// <param name="flickerHeight">Height of the flicker code</param>
        /// <param name="renderFlickerCodeAsGif">Renders flicker code as GIF, if 'true'</param>
        /// <returns>
        /// Bank return codes
        /// </returns>
        public async Task <HBCIDialogResult> Collect(TANDialog tanDialog, string payerName, string payerIBAN, string payerBIC,
                                                     decimal amount, string purpose, DateTime settlementDate, string mandateNumber, DateTime mandateDate, string creditorIdNumber,
                                                     string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKDSE(this, payerName, payerIBAN, payerBIC, amount, purpose, settlementDate, mandateNumber, mandateDate, creditorIdNumber);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 5
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));
        }
Esempio n. 6
0
        /// <summary>
        /// Transfer money - General method
        /// </summary>
        /// <param name="receiverName">Name of the recipient</param>
        /// <param name="receiverIBAN">IBAN of the recipient</param>
        /// <param name="receiverBIC">BIC of the recipient</param>
        /// <param name="amount">Amount to transfer</param>
        /// <param name="purpose">Short description of the transfer (dt. Verwendungszweck)</param>
        /// <param name="HIRMS">Numerical SecurityMode; e.g. 911 for "Sparkasse chipTan optisch"</param>
        /// <param name="pictureBox">Picturebox which shows the TAN</param>
        /// <param name="flickerImage">(Out) reference to an image object that shall receive the FlickerCode as GIF image</param>
        /// <param name="flickerWidth">Width of the flicker code</param>
        /// <param name="flickerHeight">Height of the flicker code</param>
        /// <param name="renderFlickerCodeAsGif">Renders flicker code as GIF, if 'true'</param>
        /// <returns>
        /// Bank return codes
        /// </returns>
        public async Task <HBCIDialogResult> Transfer(TANDialog tanDialog, string receiverName, string receiverIBAN, string receiverBIC,
                                                      decimal amount, string purpose, string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKCCS(this, receiverName, receiverIBAN, receiverBIC, amount, purpose);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 7
0
        public async Task <HBCIDialogResult> DeleteTerminatedTransfer(TANDialog tanDialog, string orderId, string receiverName, string receiverIBAN,
                                                                      string receiverBIC, decimal amount, string usage, DateTime executionDay, string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKCSL(this, orderId, receiverName, receiverIBAN, receiverBIC, amount, usage, executionDay);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 8
0
        /// <summary>
        /// Collective transfer money terminated - General method
        /// </summary>
        /// <param name="painData"></param>
        /// <param name="numberOfTransactions"></param>
        /// <param name="totalAmount"></param>
        /// <param name="ExecutionDay"></param>
        /// <param name="HIRMS">Numerical SecurityMode; e.g. 911 for "Sparkasse chipTan optisch"</param>
        /// <param name="pictureBox">Picturebox which shows the TAN</param>
        /// <param name="flickerImage">(Out) reference to an image object that shall receive the FlickerCode as GIF image</param>
        /// <param name="flickerWidth">Width of the flicker code</param>
        /// <param name="flickerHeight">Height of the flicker code</param>
        /// <param name="renderFlickerCodeAsGif">Renders flicker code as GIF, if 'true'</param>
        /// <returns>
        /// Bank return codes
        /// </returns>
        public async Task <HBCIDialogResult> CollectiveTransfer_Terminated(TANDialog tanDialog, List <Pain00100203CtData> painData,
                                                                           string numberOfTransactions, decimal totalAmount, DateTime executionDay, string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKCME(this, painData, numberOfTransactions, totalAmount, executionDay);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 9
0
        /// <summary>
        /// Load mobile phone prepaid card - General method
        /// </summary>
        /// <param name="mobileServiceProvider"></param>
        /// <param name="phoneNumber"></param>
        /// <param name="amount">Amount to transfer</param>
        /// <param name="HIRMS">Numerical SecurityMode; e.g. 911 for "Sparkasse chipTan optisch"</param>
        /// <param name="pictureBox">Picturebox which shows the TAN</param>
        /// <param name="flickerImage">(Out) reference to an image object that shall receive the FlickerCode as GIF image</param>
        /// <param name="flickerWidth">Width of the flicker code</param>
        /// <param name="flickerHeight">Height of the flicker code</param>
        /// <param name="renderFlickerCodeAsGif">Renders flicker code as GIF, if 'true'</param>
        /// <returns>
        /// Bank return codes
        /// </returns>
        public async Task <HBCIDialogResult> Prepaid(TANDialog tanDialog, int mobileServiceProvider, string phoneNumber,
                                                     int amount, string hirms)
        {
            var result = await InitializeConnection();

            if (!result.IsSuccess)
            {
                return(result);
            }

            result = await ProcessSCA(result, tanDialog);

            if (!result.IsSuccess)
            {
                return(result);
            }

            TransactionConsole.Output = string.Empty;

            if (!string.IsNullOrEmpty(hirms))
            {
                HIRMS = hirms;
            }

            string BankCode = await Transaction.HKPPD(this, mobileServiceProvider, phoneNumber, amount);

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

            result = await ProcessSCA(result, tanDialog);

            return(result);
        }
Esempio n. 10
0
        /// <summary>
        /// Fill given <code>TANDialog</code> and wait for user to enter a TAN.
        /// </summary>
        /// <param name="BankCode"></param>
        /// <param name="pictureBox"></param>
        /// <param name="flickerImage"></param>
        /// <param name="flickerWidth"></param>
        /// <param name="flickerHeight"></param>
        /// <param name="renderFlickerCodeAsGif"></param>
        public static async Task <string> WaitForTanAsync(FinTsClient client, HBCIDialogResult dialogResult, TANDialog tanDialog)
        {
            var BankCode_ = "HIRMS" + Parse_String(dialogResult.RawData, "'HIRMS", "'");

            string[] values = BankCode_.Split('+');
            foreach (var item in values)
            {
                if (!item.StartsWith("HIRMS"))
                {
                    TransactionConsole.Output = item.Replace("::", ": ");
                }
            }

            var HITAN = "HITAN" + Parse_String(dialogResult.RawData.Replace("?'", "").Replace("?:", ":").Replace("<br>", Environment.NewLine).Replace("?+", "??"), "'HITAN", "'");

            string HITANFlicker = string.Empty;

            var processes = TanProcesses.Items;

            var processname = string.Empty;

            if (processes != null)
            {
                foreach (var item in processes)
                {
                    if (item.ProcessNumber.Equals(client.HIRMS))
                    {
                        processname = item.ProcessName;
                    }
                }
            }

            // Smart-TAN plus optisch
            // chipTAN optisch
            if (processname.Equals("Smart-TAN plus optisch") || processname.Contains("chipTAN optisch"))
            {
                HITANFlicker = HITAN;
            }

            String[] values_ = HITAN.Split('+');

            int i = 1;

            foreach (var item in values_)
            {
                i = i + 1;

                if (i == 6)
                {
                    TransactionConsole.Output = TransactionConsole.Output + "??" + item.Replace("::", ": ").TrimStart();

                    TransactionConsole.Output = TransactionConsole.Output.Replace("??", " ")
                                                .Replace("0030: ", "")
                                                .Replace("1.", Environment.NewLine + "1.")
                                                .Replace("2.", Environment.NewLine + "2.")
                                                .Replace("3.", Environment.NewLine + "3.")
                                                .Replace("4.", Environment.NewLine + "4.")
                                                .Replace("5.", Environment.NewLine + "5.")
                                                .Replace("6.", Environment.NewLine + "6.")
                                                .Replace("7.", Environment.NewLine + "7.")
                                                .Replace("8.", Environment.NewLine + "8.");
                }
            }

            // chipTAN optisch
            if (processname.Contains("chipTAN optisch"))
            {
                string FlickerCode = string.Empty;

                FlickerCode = "CHLGUC" + Helper.Parse_String(HITAN, "CHLGUC", "CHLGTEXT") + "CHLGTEXT";

                FlickerCode flickerCode = new FlickerCode(FlickerCode);
                flickerCodeRenderer = new FlickerRenderer(flickerCode.Render(), tanDialog.PictureBox);
                if (!tanDialog.RenderFlickerCodeAsGif)
                {
                    RUN_flickerCodeRenderer();

                    Action   action = STOP_flickerCodeRenderer;
                    TimeSpan span   = new TimeSpan(0, 0, 0, 50);

                    ThreadStart start  = delegate { RunAfterTimespan(action, span); };
                    Thread      thread = new Thread(start);
                    thread.Start();
                }
                else
                {
                    tanDialog.FlickerImage = flickerCodeRenderer.RenderAsGif(tanDialog.FlickerWidth, tanDialog.FlickerHeight);
                }
            }

            // Smart-TAN plus optisch
            if (processname.Equals("Smart-TAN plus optisch"))
            {
                HITANFlicker = HITAN.Replace("?@", "??");

                string FlickerCode = string.Empty;

                String[] values__ = HITANFlicker.Split('@');

                int ii = 1;

                foreach (var item in values__)
                {
                    ii = ii + 1;

                    if (ii == 4)
                    {
                        FlickerCode = item;
                    }
                }

                FlickerCode flickerCode = new FlickerCode(FlickerCode.Trim());
                flickerCodeRenderer = new FlickerRenderer(flickerCode.Render(), tanDialog.PictureBox);
                if (!tanDialog.RenderFlickerCodeAsGif)
                {
                    RUN_flickerCodeRenderer();

                    Action   action = STOP_flickerCodeRenderer;
                    TimeSpan span   = new TimeSpan(0, 0, 0, 50);

                    ThreadStart start  = delegate { RunAfterTimespan(action, span); };
                    Thread      thread = new Thread(start);
                    thread.Start();
                }
                else
                {
                    tanDialog.FlickerImage = flickerCodeRenderer.RenderAsGif(tanDialog.FlickerWidth, tanDialog.FlickerHeight);
                }
            }

            // Smart-TAN photo
            if (processname.Equals("Smart-TAN photo"))
            {
                var PhotoCode = Parse_String(dialogResult.RawData, ".+@", "'HNSHA");

                var mCode = new MatrixCode(PhotoCode.Substring(5, PhotoCode.Length - 5));

                tanDialog.MatrixImage = mCode.CodeImage;
                mCode.Render(tanDialog.PictureBox);
            }

            // PhotoTAN
            if (processname.Equals("photoTAN-Verfahren"))
            {
                // HITAN:5:5:4+4++nmf3VmGQDT4qZ20190130091914641+Bitte geben Sie die photoTan ein+@3031@       image/pngʉPNG
                var match = Regex.Match(dialogResult.RawData, @"HITAN.+@\d+@(.+)'HNHBS", RegexOptions.Singleline);
                if (match.Success)
                {
                    var PhotoBinary = match.Groups[1].Value;

                    var mCode = new MatrixCode(PhotoBinary);

                    tanDialog.MatrixImage = mCode.CodeImage;
                    mCode.Render(tanDialog.PictureBox);
                }
            }

            return(await tanDialog.WaitForTanAsync());
        }
Esempio n. 11
0
        /// <summary>
        /// Account transactions in SWIFT-format
        /// </summary>
        /// <param name="connectionDetails">ConnectionDetails object must atleast contain the fields: Url, HBCIVersion, UserId, Pin, Blz, Account, IBAN, BIC</param>
        /// <param name="anonymous"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns>
        /// Transactions
        /// </returns>
        public async Task <HBCIDialogResult <List <SwiftStatement> > > Transactions(TANDialog tanDialog, DateTime?startDate = null, DateTime?endDate = null, bool saveMt940File = false)
        {
            var result = await InitializeConnection();

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

            result = await ProcessSCA(result, tanDialog);

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

            string startDateStr = startDate?.ToString("yyyyMMdd");
            string endDateStr   = endDate?.ToString("yyyyMMdd");

            // Success
            string BankCode = await Transaction.HKKAZ(this, startDateStr, endDateStr, null);

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

            result = await ProcessSCA(result, tanDialog);

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

            BankCode = result.RawData;
            var TransactionsMt940 = new StringBuilder();
            var TransactionsMt942 = new StringBuilder();

            Regex regex = new Regex(@"HIKAZ:.+?@\d+@(?<mt940>.+?)(\+@\d+@(?<mt942>.+?))?('{1,2}H[A-Z]{4}:\d+:\d+)", RegexOptions.Singleline);
            Match match = regex.Match(BankCode);

            if (match.Success)
            {
                TransactionsMt940.Append(match.Groups["mt940"].Value);
                TransactionsMt942.Append(match.Groups["mt942"].Value);
            }

            string BankCode_ = BankCode;

            while (BankCode_.Contains("+3040::"))
            {
                Helper.Parse_Message(this, BankCode_);

                string Startpoint = new Regex(@"\+3040::[^:]+:(?<startpoint>[^']+)'").Match(BankCode_).Groups["startpoint"].Value;

                BankCode_ = await Transaction.HKKAZ(this, startDateStr, endDateStr, Startpoint);

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

                result = await ProcessSCA(result, tanDialog);

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

                BankCode_ = result.RawData;
                match     = regex.Match(BankCode_);
                if (match.Success)
                {
                    TransactionsMt940.Append(match.Groups["mt940"].Value);
                    TransactionsMt942.Append(match.Groups["mt942"].Value);
                }
            }

            var swiftStatements = new List <SwiftStatement>();

            swiftStatements.AddRange(MT940.Serialize(TransactionsMt940.ToString(), ConnectionDetails.Account, saveMt940File));
            swiftStatements.AddRange(MT940.Serialize(TransactionsMt942.ToString(), ConnectionDetails.Account, saveMt940File, true));

            return(result.TypedResult(swiftStatements));
        }
Esempio n. 12
0
        /// <summary>
        /// Account transactions in simplified libfintx-format
        /// </summary>
        /// <param name="connectionDetails">ConnectionDetails object must atleast contain the fields: Url, HBCIVersion, UserId, Pin, Blz, Account, IBAN, BIC</param>
        /// <param name="anonymous"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns>
        /// Transactions
        /// </returns>
        public async Task <HBCIDialogResult <List <AccountTransaction> > > TransactionsSimple(TANDialog tanDialog, DateTime?startDate = null, DateTime?endDate = null)
        {
            var result = await Transactions(tanDialog, startDate, endDate);

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

            var transactionList = new List <AccountTransaction>();

            foreach (var swiftStatement in result.Data)
            {
                foreach (var swiftTransaction in swiftStatement.SwiftTransactions)
                {
                    transactionList.Add(new AccountTransaction()
                    {
                        OwnerAccount    = swiftStatement.AccountCode,
                        OwnerBankCode   = swiftStatement.BankCode,
                        PartnerBic      = swiftTransaction.BankCode,
                        PartnerIban     = swiftTransaction.AccountCode,
                        PartnerName     = swiftTransaction.PartnerName,
                        RemittanceText  = swiftTransaction.Description,
                        TransactionType = swiftTransaction.Text,
                        TransactionDate = swiftTransaction.InputDate,
                        ValueDate       = swiftTransaction.ValueDate
                    });
                }
            }

            return(result.TypedResult(transactionList));
        }
Esempio n. 13
0
        /// <summary>
        /// Account transactions in camt format
        /// </summary>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns>
        /// Transactions
        /// </returns>
        public async Task <HBCIDialogResult <List <CamtStatement> > > Transactions_camt(TANDialog tanDialog, CamtVersion camtVers,
                                                                                        DateTime?startDate = null, DateTime?endDate = null, bool saveCamtFile = false)
        {
            var result = await InitializeConnection();

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

            result = await ProcessSCA(result, tanDialog);

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

            // Plain camt message
            string camt = string.Empty;

            string startDateStr = startDate?.ToString("yyyyMMdd");
            string endDateStr   = endDate?.ToString("yyyyMMdd");

            // Success
            string BankCode = await Transaction.HKCAZ(this, startDateStr, endDateStr, null, camtVers);

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

            result = await ProcessSCA(result, tanDialog);

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

            BankCode = result.RawData;
            var statements = new List <CamtStatement>();

            Camt052Parser camt052Parser = null;
            Camt053Parser camt053Parser = null;
            var           encoding      = Encoding.GetEncoding("ISO-8859-1");

            string BankCode_ = BankCode;

            // Es kann sein, dass in der payload mehrere Dokumente enthalten sind
            int xmlStartIdx = BankCode_.IndexOf("<?xml version=");
            int xmlEndIdx   = BankCode_.IndexOf("</Document>") + "</Document>".Length;

            while (xmlStartIdx >= 0)
            {
                if (xmlStartIdx > xmlEndIdx)
                {
                    break;
                }

                camt = "<?xml version=" + Helper.Parse_String(BankCode_, "<?xml version=", "</Document>") + "</Document>";

                switch (camtVers)
                {
                case CamtVersion.Camt052:
                    if (camt052Parser == null)
                    {
                        camt052Parser = new Camt052Parser();
                    }

                    if (saveCamtFile)
                    {
                        // Save camt052 statement to file
                        string camt052f = Camt052File.Save(ConnectionDetails.Account, camt, encoding);

                        // Process the camt052 file
                        camt052Parser.ProcessFile(camt052f);
                    }
                    else
                    {
                        camt052Parser.ProcessDocument(camt, encoding);
                    }

                    statements.AddRange(camt052Parser.statements);
                    break;

                case CamtVersion.Camt053:
                    if (camt053Parser == null)
                    {
                        camt053Parser = new Camt053Parser();
                    }

                    if (saveCamtFile)
                    {
                        // Save camt053 statement to file
                        string camt053f = Camt053File.Save(ConnectionDetails.Account, camt, encoding);

                        // Process the camt053 file
                        camt053Parser.ProcessFile(camt053f);
                    }
                    else
                    {
                        camt053Parser.ProcessDocument(camt, encoding);
                    }

                    statements.AddRange(camt053Parser.statements);
                    break;
                }

                BankCode_   = BankCode_.Substring(xmlEndIdx);
                xmlStartIdx = BankCode_.IndexOf("<?xml version");
                xmlEndIdx   = BankCode_.IndexOf("</Document>") + "</Document>".Length;
            }

            BankCode_ = BankCode;

            while (BankCode_.Contains("+3040::"))
            {
                string Startpoint = new Regex(@"\+3040::[^:]+:(?<startpoint>[^']+)'").Match(BankCode_).Groups["startpoint"].Value;
                BankCode_ = await Transaction.HKCAZ(this, startDateStr, endDateStr, Startpoint, camtVers);

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

                BankCode_ = result.RawData;

                // Es kann sein, dass in der payload mehrere Dokumente enthalten sind
                xmlStartIdx = BankCode_.IndexOf("<?xml version=");
                xmlEndIdx   = BankCode_.IndexOf("</Document>") + "</Document>".Length;

                while (xmlStartIdx >= 0)
                {
                    if (xmlStartIdx > xmlEndIdx)
                    {
                        break;
                    }

                    camt = "<?xml version=" + Helper.Parse_String(BankCode_, "<?xml version=", "</Document>") + "</Document>";

                    switch (camtVers)
                    {
                    case CamtVersion.Camt052:
                        // Save camt052 statement to file
                        string camt052f_ = Camt052File.Save(ConnectionDetails.Account, camt);

                        // Process the camt052 file
                        camt052Parser.ProcessFile(camt052f_);

                        // Add all items
                        statements.AddRange(camt052Parser.statements);
                        break;

                    case CamtVersion.Camt053:
                        // Save camt053 statement to file
                        string camt053f_ = Camt053File.Save(ConnectionDetails.Account, camt);

                        // Process the camt053 file
                        camt053Parser.ProcessFile(camt053f_);

                        // Add all items to existing statement
                        statements.AddRange(camt053Parser.statements);
                        break;
                    }

                    BankCode_   = BankCode_.Substring(xmlEndIdx);
                    xmlStartIdx = BankCode_.IndexOf("<?xml version");
                    xmlEndIdx   = BankCode_.IndexOf("</Document>") + "</Document>".Length;
                }
            }

            return(result.TypedResult(statements));
        }
Esempio n. 14
0
        /// <summary>
        /// Get banker's orders
        /// </summary>
        /// <param name="tanDialog">The TAN dialog</param>
        /// <returns>
        /// Banker's orders
        /// </returns>
        public async Task <HBCIDialogResult <List <BankersOrder> > > GetBankersOrders(TANDialog tanDialog)
        {
            var result = await InitializeConnection();

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

            result = await ProcessSCA(result, tanDialog);

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

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

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

            result = await ProcessSCA(result, tanDialog);

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

            BankCode = result.RawData;
            int startIdx = BankCode.IndexOf("HICDB");

            if (startIdx < 0)
            {
                return(result.TypedResult <List <BankersOrder> >());
            }

            var data = new List <BankersOrder>();

            string BankCode_ = BankCode.Substring(startIdx);

            for (; ;)
            {
                var match = Regex.Match(BankCode_, @"HICDB.+?(?<xml><\?xml.+?</Document>)\+(?<orderid>.*?)\+(?<firstdate>\d*):(?<turnus>[MW]):(?<rota>\d+):(?<execday>\d+)(:(?<lastdate>\d+))?", RegexOptions.Singleline);
                if (match.Success)
                {
                    string xml = match.Groups["xml"].Value;
                    // xml ist UTF-8
                    xml = Converter.ConvertEncoding(xml, Encoding.GetEncoding("ISO-8859-1"), Encoding.UTF8);

                    string orderId = match.Groups["orderid"].Value;

                    string firstExecutionDateStr = match.Groups["firstdate"].Value;
                    var    firstExecutionDate    = !string.IsNullOrWhiteSpace(firstExecutionDateStr) ? DateTime.ParseExact(firstExecutionDateStr, "yyyyMMdd", CultureInfo.InvariantCulture) : default(DateTime?);

                    string timeUnitStr = match.Groups["turnus"].Value;
                    var    timeUnit    = timeUnitStr == "M" ? TimeUnit.Monthly : TimeUnit.Weekly;

                    string rota = match.Groups["rota"].Value;

                    string executionDayStr = match.Groups["execday"].Value;
                    int    executionDay    = Convert.ToInt32(executionDayStr);

                    string lastExecutionDateStr = match.Groups["lastdate"].Value;
                    var    lastExecutionDate    = !string.IsNullOrWhiteSpace(lastExecutionDateStr) ? DateTime.ParseExact(lastExecutionDateStr, "yyyyMMdd", CultureInfo.InvariantCulture) : default(DateTime?);

                    var painData = Pain00100103CtData.Create(xml);

                    if (firstExecutionDate.HasValue && executionDay > 0)
                    {
                        var item = new BankersOrder(orderId, painData, firstExecutionDate.Value, timeUnit, rota, executionDay, lastExecutionDate);
                        data.Add(item);
                    }
                }

                int endIdx = BankCode_.IndexOf("'");
                if (BankCode_.Length <= endIdx + 1)
                {
                    break;
                }

                BankCode_ = BankCode_.Substring(endIdx + 1);
                startIdx  = BankCode_.IndexOf("HICDB");
                if (startIdx < 0)
                {
                    break;
                }
            }

            // Success
            return(result.TypedResult(data));
        }
Esempio n. 15
0
        /// <summary>
        /// Get terminated transfers
        /// </summary>
        /// <returns>
        /// Banker's orders
        /// </returns>
        public async Task <HBCIDialogResult <List <TerminatedTransfer> > > GetTerminatedTransfers(TANDialog tanDialog)
        {
            var result = await InitializeConnection();

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

            result = await ProcessSCA(result, tanDialog);

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

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

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

            result = await ProcessSCA(result, tanDialog);

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

            BankCode = result.RawData;
            int startIdx = BankCode.IndexOf("HICSB");

            if (startIdx < 0)
            {
                return(result.TypedResult <List <TerminatedTransfer> >());
            }

            var data = new List <TerminatedTransfer>();

            string BankCode_ = BankCode.Substring(startIdx);

            for (; ;)
            {
                var match = Regex.Match(BankCode_, @"HICSB.+?(?<xml><\?xml.+?</Document>)\+(?<orderid>.*?)(\+(?<deleteable>j|n))?(\+(?<modifiable>j|n))?'", RegexOptions.Singleline | RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    string xml = match.Groups["xml"].Value;
                    // xml ist UTF-8
                    xml = Converter.ConvertEncoding(xml, Encoding.GetEncoding("ISO-8859-1"), Encoding.UTF8);

                    string orderId    = match.Groups["orderid"].Value;
                    bool?  deleteable = null;
                    if (match.Groups["deleteable"].Success)
                    {
                        deleteable = match.Groups["deleteable"].Value.Equals("j", StringComparison.OrdinalIgnoreCase) ? true : false;
                    }

                    bool?modifiable = null;
                    if (match.Groups["modifiable"].Success)
                    {
                        modifiable = match.Groups["modifiable"].Value.Equals("j", StringComparison.OrdinalIgnoreCase) ? true : false;
                    }

                    var painData = Pain00100103CtData.Create(xml);

                    var item = new TerminatedTransfer(orderId, deleteable, modifiable, painData);
                    data.Add(item);
                }

                int endIdx = BankCode_.IndexOf("'");
                if (BankCode_.Length <= endIdx + 1)
                {
                    break;
                }

                BankCode_ = BankCode_.Substring(endIdx + 1);
                startIdx  = BankCode_.IndexOf("HICSB");
                if (startIdx < 0)
                {
                    break;
                }
            }

            // Success
            return(result.TypedResult(data));
        }