/// <summary> /// Request tan medium name /// </summary> /// <param name="connectionDetails">ConnectionDetails object must atleast contain the fields: Url, HBCIVersion, UserId, Pin, Blz</param> /// <returns> /// TAN Medium Name /// </returns> public async Task <HBCIDialogResult <List <string> > > RequestTANMediumName() { HBCIDialogResult result = await InitializeConnection("HKTAB"); if (!result.IsSuccess) { return(result.TypedResult <List <string> >()); } // Should not be needed when processing HKTAB //result = ProcessSCA(connectionDetails, result, tanDialog); //if (!result.IsSuccess) // return result.TypedResult<List<string>>(); string BankCode = await Transaction.HKTAB(this); result = new HBCIDialogResult <List <string> >(Helper.Parse_BankCode(BankCode), BankCode); if (!result.IsSuccess) { return(result.TypedResult <List <string> >()); } // Should not be needed when processing HKTAB //result = ProcessSCA(connectionDetails, result, tanDialog); //if (!result.IsSuccess) // return result.TypedResult<List<string>>(); BankCode = result.RawData; string BankCode_ = "HITAB" + Helper.Parse_String(BankCode, "'HITAB", "'"); return(result.TypedResult(Helper.Parse_TANMedium(BankCode_))); }
internal async Task <HBCIDialogResult> InitializeConnection(string hkTanSegmentId = "HKIDN") { HBCIDialogResult result; string BankCode; // Check if the user provided a SystemID if (ConnectionDetails.CustomerSystemId == null) { result = await Synchronization(); if (!result.IsSuccess) { Log.Write("Synchronisation failed."); return(result); } } else { SystemId = ConnectionDetails.CustomerSystemId; } BankCode = await Transaction.INI(this, hkTanSegmentId); var bankMessages = Helper.Parse_BankCode(BankCode); result = new HBCIDialogResult(bankMessages, BankCode); if (!result.IsSuccess) { Log.Write("Initialisation failed: " + result); } return(result); }
/// <summary> /// Confirm order with TAN /// </summary> /// <param name="TAN"></param> /// <param name="MediumName"></param> /// <returns> /// Bank return codes /// </returns> public async Task <HBCIDialogResult> TAN4(string TAN, string MediumName) { string BankCode = await Transaction.TAN4(this, TAN, MediumName); var result = new HBCIDialogResult(Helper.Parse_BankCode(BankCode), BankCode); return(result); }
private async Task <HBCIDialogResult> ProcessSCA(HBCIDialogResult result, TanRequest tanDialog) { tanDialog.DialogResult = result; if (result.IsTanRequired) { 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); } } else if (result.IsApprovalRequired) { await Helper.WaitForTanAsync(this, result, tanDialog); const int delay = 2000; // Der minimale Zeitraum zwischen zwei Statusabfragen steht in HITANS, wir nehmen einfach 2 Sek await Task.Delay(delay); result = await TAN(null); while (!result.IsSuccess && !result.HasError && result.IsWaitingForApproval) // Freigabe wurde noch nicht erteilt { await Task.Delay(delay); if (tanDialog.IsCancelWaitForApproval) { string bankCode = await Transaction.HKEND(this, HNHBK); result = new HBCIDialogResult(Helper.Parse_BankCode(bankCode), bankCode); } else { result = await TAN(null); } } await tanDialog.OnTransactionEndedAsync(result.IsSuccess); // Dem Benutzer signalisieren, dass die Transaktion beendet ist } return(result); }
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); }
/// <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(TanRequest 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.HasError) { 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.HasError) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
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); }
/// <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)); }
/// <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(TanRequest tanDialog, string receiverName, string receiverIBAN, string receiverBIC, decimal amount, string purpose, string hirms) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
public async Task <HBCIDialogResult> DeleteTerminatedTransfer(TanRequest tanDialog, string orderId, string receiverName, string receiverIBAN, string receiverBIC, decimal amount, string usage, DateTime executionDay, string hirms) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
/// <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(TanRequest tanDialog, List <Pain00100203CtData> painData, string numberOfTransactions, decimal totalAmount, DateTime executionDay, string hirms) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
/// <summary> /// Collective collect money from other accounts - General method /// </summary> /// <param name="settlementDate"></param> /// <param name="painData"></param> /// <param name="numberOfTransactions"></param> /// <param name="totalAmount"></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> CollectiveCollect(TANDialog tanDialog, DateTime settlementDate, List <Pain00800202CcData> painData, string numberOfTransactions, decimal totalAmount, 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.HKDME(this, settlementDate, painData, numberOfTransactions, totalAmount); result = new HBCIDialogResult(Helper.Parse_BankCode(BankCode), BankCode); if (!result.IsSuccess) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
/// <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(TanRequest tanDialog, int mobileServiceProvider, string phoneNumber, int amount, string hirms) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
/// <summary> /// Transfer money at a certain time - 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="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> Transfer_Terminated(TANDialog tanDialog, string receiverName, string receiverIBAN, string receiverBIC, decimal amount, string purpose, 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.HKCSE(this, receiverName, receiverIBAN, receiverBIC, amount, purpose, executionDay); result = new HBCIDialogResult(Helper.Parse_BankCode(BankCode), BankCode); if (!result.IsSuccess) { return(result); } result = await ProcessSCA(result, tanDialog); return(result); }
/// <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()); }
/// <summary> /// INI /// </summary> public static async Task <String> Init_INI(FinTsClient client, string hkTanSegmentId = null) { var connectionDetails = client.ConnectionDetails; if (!client.Anonymous) { /// <summary> /// Sync /// </summary> try { string segments; /// <summary> /// INI /// </summary> if (connectionDetails.HbciVersion == Convert.ToInt16(HBCI.v220)) { string segments_ = "HKIDN:" + SEG_NUM.Seg3 + ":2+" + SEG_Country.Germany + ":" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + client.SystemId + "+1'" + "HKVVB:" + SEG_NUM.Seg4 + ":2+0+0+0+" + FinTsGlobals.ProductId + "+" + FinTsGlobals.Version + "'"; segments = segments_; } else if (connectionDetails.HbciVersion == Convert.ToInt16(HBCI.v300)) { string segments_ = "HKIDN:" + SEG_NUM.Seg3 + ":2+" + SEG_Country.Germany + ":" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + client.SystemId + "+1'" + "HKVVB:" + SEG_NUM.Seg4 + ":3+0+0+0+" + FinTsGlobals.ProductId + "+" + FinTsGlobals.Version + "'"; if (client.HITANS == 6) { client.SEGNUM = Convert.ToInt16(SEG_NUM.Seg5); segments_ = HKTAN.Init_HKTAN(client, segments_, hkTanSegmentId); } else { client.SEGNUM = Convert.ToInt16(SEG_NUM.Seg4); } segments = segments_; } else { //Since connectionDetails is a re-usable object, this shouldn't be cleared. //connectionDetails.UserId = string.Empty; //connectionDetails.Pin = null; Log.Write("HBCI version not supported"); throw new Exception("HBCI version not supported"); } var message = FinTSMessage.Create(client, 1, "0", segments, client.HIRMS); var response = await FinTSMessage.Send(client, message); Helper.Parse_Segments(client, response); return(response); } catch (Exception ex) { //Since connectionDetails is a re-usable object, this shouldn't be cleared. //connectionDetails.UserId = string.Empty; //connectionDetails.Pin = null; Log.Write(ex.ToString()); throw new Exception("Software error", ex); } } else { /// <summary> /// Sync /// </summary> try { Log.Write("Starting Synchronisation anonymous"); string segments; if (connectionDetails.HbciVersion == Convert.ToInt16(HBCI.v300)) { string segments_ = "HKIDN:" + SEG_NUM.Seg2 + ":2+" + SEG_Country.Germany + ":" + connectionDetails.BlzPrimary + "+" + "9999999999" + "+0+0'" + "HKVVB:" + SEG_NUM.Seg3 + ":3+0+0+1+" + FinTsGlobals.ProductId + "+" + FinTsGlobals.Version + "'"; segments = segments_; } else { //Since connectionDetails is a re-usable object, this shouldn't be cleared. //connectionDetails.UserId = string.Empty; //connectionDetails.Pin = null; Log.Write("HBCI version not supported"); throw new Exception("HBCI version not supported"); } client.SEGNUM = Convert.ToInt16(SEG_NUM.Seg4); string message = FinTsMessageAnonymous.Create(connectionDetails.HbciVersion, "1", "0", connectionDetails.Blz, connectionDetails.UserId, connectionDetails.Pin, "0", segments, null, client.SEGNUM); string response = await FinTSMessage.Send(client, message); var messages = Helper.Parse_Segments(client, response); var result = new HBCIDialogResult(messages, response); if (!result.IsSuccess) { Log.Write("Synchronisation anonymous failed. " + result); return(response); } // Sync OK Log.Write("Synchronisation anonymous ok"); /// <summary> /// INI /// </summary> if (connectionDetails.HbciVersion == Convert.ToInt16(HBCI.v300)) { string segments__ = "HKIDN:" + SEG_NUM.Seg3 + ":2+" + SEG_Country.Germany + ":" + connectionDetails.BlzPrimary + "+" + connectionDetails.UserId + "+" + client.SystemId + "+1'" + "HKVVB:" + SEG_NUM.Seg4 + ":3+0+0+0+" + FinTsGlobals.ProductId + "+" + FinTsGlobals.Version + "'" + "HKSYN:" + SEG_NUM.Seg5 + ":3+0'"; segments = segments__; } else { Log.Write("HBCI version not supported"); throw new Exception("HBCI version not supported"); } client.SEGNUM = Convert.ToInt16(SEG_NUM.Seg5); message = FinTSMessage.Create(client, 1, "0", segments, client.HIRMS); response = await FinTSMessage.Send(client, message); Helper.Parse_Segments(client, response); return(response); } catch (Exception ex) { //Since connectionDetails is a re-usable object, this shouldn't be cleared. //connectionDetails.UserId = string.Empty; //connectionDetails.Pin = null; Log.Write(ex.ToString()); DEBUG.Write("Software error: " + ex.ToString()); throw new Exception("Software error: " + ex.ToString()); } } }
/// <summary> /// Get terminated transfers /// </summary> /// <returns> /// Banker's orders /// </returns> public async Task <HBCIDialogResult <List <TerminatedTransfer> > > GetTerminatedTransfers(TanRequest tanDialog) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { 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)); }
/// <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(TanRequest tanDialog, DateTime?startDate = null, DateTime?endDate = null, bool saveMt940File = false) { var result = await InitializeConnection(); if (result.HasError) { 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.HasError) { 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.HasError) { 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)); }
/// <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(TanRequest 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.HasError) { 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.HasError) { 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)); }
/// <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)); }
/// <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, TanRequest tanRequest) { 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 tanMethods = BPD.HITANS.Where(h => h.Version == client.HITANS).SelectMany(t => t.TanProcesses); var tanMethod = string.Empty; foreach (var item in tanMethods) { if (item.TanCode == Convert.ToInt32(client.HIRMS)) { tanMethod = item.Name; } } Log.Write($"Processing TAN process '{tanMethod}' ..."); // Smart-TAN plus optisch // chipTAN optisch if (tanMethod.Equals("Smart-TAN plus optisch") || tanMethod.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 (tanMethod.Contains("chipTAN optisch")) { string FlickerCode = string.Empty; FlickerCode = "CHLGUC" + Helper.Parse_String(HITAN, "CHLGUC", "CHLGTEXT") + "CHLGTEXT"; FlickerCode flickerCode = new FlickerCode(FlickerCode); var flickerCodeRenderer = new FlickerCodeRenderer(flickerCode.Render()); return(await tanRequest.WithFlickerAsync(flickerCodeRenderer)); } // Smart-TAN plus optisch if (tanMethod.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()); var flickerCodeRenderer = new FlickerCodeRenderer(flickerCode.Render()); return(await tanRequest.WithFlickerAsync(flickerCodeRenderer)); } // Smart-TAN photo if (tanMethod.Equals("Smart-TAN photo")) { var PhotoCode = Parse_String(dialogResult.RawData, ".+@", "'HNSHA"); var mCode = new MatrixCode(PhotoCode.Substring(5, PhotoCode.Length - 5)); return(await tanRequest.WithMatrixAsync(mCode)); } // PhotoTAN if (tanMethod.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 pichtureBinaryDataString = match.Groups[1].Value; var mCode = new MatrixCode(pichtureBinaryDataString); return(await tanRequest.WithMatrixAsync(mCode)); } } return(await tanRequest.WithUnknownAsync()); }