public static async Task <String> HKEND(FinTsClient client, string dialogId) { return(await Init_HKEND(client, dialogId)); }
public static async Task <String> HKCAZ(FinTsClient client, string FromDate, string ToDate, string Startpoint, CamtVersion camtVers) { return(await Init_HKCAZ(client, FromDate, ToDate, Startpoint, camtVers)); }
public static async Task <String> INI(FinTsClient client) { return(await Init_INI(client)); }
/// <summary> /// Create FinTS message /// </summary> /// <param name="client"></param> /// <param name="MsgNum"></param> /// /// <param name="DialogID"></param> /// <param name="Segments"></param> /// /// <param name="HIRMS_TAN"></param> /// <param name="SegmentNum"></param> /// /// <param name="SystemID"></param> /// <returns></returns> /// /// (iwen65) First redesign to make things easier and more readable. All important params were values that had been stored as properties of the FinTsClient /// If this is connected as close as this it is better to pass the client as ref parameter, that makes the hole method much more flexible and extensible /// without breaking changes. /// ConnectionDetails are a part of the client too. We can handle the new added ServiceProtocolType inside the common connectioninfo without breaking changes too. /// Mostly it will be TLS12 but who knows. /// I'm pretty sure the method can be simplified even more. /// public static string Create(FinTsClient client, string MsgNum, string DialogID, string Segments, string HIRMS_TAN, string SystemID = null) { int Version = client.ConnectionDetails.HbciVersion; int BLZ = client.ConnectionDetails.BlzPrimary; string UserID = client.ConnectionDetails.UserId; string PIN = client.ConnectionDetails.Pin; int SegmentNum = client.SEGNUM; if (SystemID == null) { SystemID = client.SystemId; } if (String.IsNullOrEmpty(MsgNum)) { MsgNum = "1"; } DialogID += ""; var HEAD_LEN = 29; var TRAIL_LEN = 11; Random Rnd = new Random(); int RndNr = Rnd.Next(); var encHead = string.Empty; var sigHead = string.Empty; var sigTrail = string.Empty; var secRef = Math.Round(Convert.ToDecimal(RndNr.ToString().Replace("-", "")) * 999999 + 1000000); string date = Convert.ToString(DateTime.Now.Year) + DateTime.Now.ToString("MM") + DateTime.Now.ToString("dd"); string time = Convert.ToString(DateTime.Now.TimeOfDay).Substring(0, 8).Replace(":", ""); string TAN_ = string.Empty; if (HIRMS_TAN != null) { if (HIRMS_TAN.Length >= 10) { var split = HIRMS_TAN.Split(':'); if (split.Length == 2) { HIRMS_TAN = split[0]; TAN_ = ":" + split[1]; } } } if (Version == 220) { encHead = "HNVSK:" + Enc.SECFUNC_ENC_PLAIN + ":2+998+1+1::" + SystemID + "+1:" + date + ":" + time + "+2:2:13:@8@00000000:5:1+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":V:0:0+0'"; Log.Write(encHead.Replace(UserID, "XXXXXX")); sigHead = string.Empty; if (HIRMS_TAN == null) { sigHead = "HNSHK:2:3+" + "900" + "+" + secRef + "+1+1+1::" + SystemID + "+1+1:" + date + ":" + time + "+1:999:1+6:10:16+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":S:0:0'"; Log.Write(sigHead.Replace(UserID, "XXXXXX")); } else { sigHead = "HNSHK:2:3+" + HIRMS_TAN + "+" + secRef + "+1+1+1::" + SystemID + "+1+1:" + date + ":" + time + "+1:999:1+6:10:16+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":S:0:0'"; Log.Write(sigHead.Replace(UserID, "XXXXXX")); } if (String.IsNullOrEmpty(TAN_)) { sigTrail = "HNSHA:" + Convert.ToString(SegmentNum + 1) + ":1+" + secRef + "++" + PIN + "'"; Log.Write("HNSHA:" + Convert.ToString(SegmentNum + 1) + ":1+" + secRef + "++" + "XXXXXX" + "'"); } else { sigTrail = "HNSHA:" + Convert.ToString(SegmentNum + 1) + ":1+" + secRef + "++" + PIN + TAN_ + "'"; Log.Write("HNSHA:" + Convert.ToString(SegmentNum + 1) + ":1+" + secRef + "++" + "XXXXXX" + "XXXXXX" + "'"); } } else if (Version == 300) { if (HIRMS_TAN == null) { encHead = "HNVSK:998:3+PIN:1+" + Enc.SECFUNC_ENC_PLAIN + "+1+1::" + SystemID + "+1:" + date + ":" + time + "+2:2:13:@8@00000000:5:1+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":V:0:0+0'"; } else { encHead = "HNVSK:998:3+PIN:2+" + Enc.SECFUNC_ENC_PLAIN + "+1+1::" + SystemID + "+1:" + date + ":" + time + "+2:2:13:@8@00000000:5:1+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":V:0:0+0'"; } Log.Write(encHead.Replace(UserID, "XXXXXX")); if (HIRMS_TAN == null) { sigHead = "HNSHK:2:4+PIN:1+" + Sig.SECFUNC_SIG_PT_1STEP + "+" + secRef + "+1+1+1::" + SystemID + "+1+1:" + date + ":" + time + "+1:999:1+6:10:16+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":S:0:0'"; Log.Write(sigHead.Replace(UserID, "XXXXXX")); } else { var SECFUNC = HIRMS_TAN.Equals("999") ? "1" : "2"; sigHead = "HNSHK:2:4+PIN:" + SECFUNC + "+" + HIRMS_TAN + "+" + secRef + "+1+1+1::" + SystemID + "+1+1:" + date + ":" + time + "+1:999:1+6:10:16+" + SEG_Country.Germany + ":" + BLZ + ":" + UserID + ":S:0:0'"; Log.Write(sigHead.Replace(UserID, "XXXXXX")); } if (String.IsNullOrEmpty(TAN_)) { sigTrail = "HNSHA:" + Convert.ToString(SegmentNum + 1) + ":2+" + secRef + "++" + PIN + "'"; Log.Write("HNSHA:" + Convert.ToString(SegmentNum + 1) + ":2+" + secRef + "++" + "XXXXXX" + "'"); } else { sigTrail = "HNSHA:" + Convert.ToString(SegmentNum + 1) + ":2+" + secRef + "++" + PIN + TAN_ + "'"; Log.Write("HNSHA:" + Convert.ToString(SegmentNum + 1) + ":2+" + secRef + "++" + "XXXXXX" + "XXXXXX" + "'"); } } else { Log.Write("HBCI version not supported"); return(string.Empty); } Segments = sigHead + Segments + sigTrail; var payload = Helper.Encrypt(Segments); if (HIRMS_TAN == null) { Log.Write(payload.Replace(UserID, "XXXXXX").Replace(PIN, "XXXXXX")); } else if (!String.IsNullOrEmpty(TAN_)) { Log.Write(payload.Replace(UserID, "XXXXXX").Replace(PIN, "XXXXXX").Replace(TAN_, "XXXXXX")); } var msgLen = HEAD_LEN + TRAIL_LEN + MsgNum.Length * 2 + DialogID.Length + payload.Length + encHead.Length; var paddedLen = ("000000000000").Substring(0, 12 - Convert.ToString(msgLen).Length) + Convert.ToString(msgLen); var msgHead = string.Empty; if (Version == 220) { msgHead = "HNHBK:1:3+" + paddedLen + "+" + ("220") + "+" + DialogID + "+" + MsgNum + "'"; Log.Write(msgHead); } else if (Version == 300) { msgHead = "HNHBK:1:3+" + paddedLen + "+" + ("300") + "+" + DialogID + "+" + MsgNum + "'"; Log.Write(msgHead); } else { Log.Write("HBCI version not supported"); return(string.Empty); } var msgEnd = "HNHBS:" + Convert.ToString(SegmentNum + 2) + ":1+" + MsgNum + "'"; Log.Write(msgEnd); UserID = string.Empty; PIN = null; return(msgHead + encHead + payload + msgEnd); }
public static async Task <String> TAN4(FinTsClient client, string TAN, string MediumName) { return(await Send_TAN4(client, TAN, MediumName)); }
public static async Task <String> HKCSE(FinTsClient client, string Receiver, string ReceiverIBAN, string ReceiverBIC, decimal Amount, string Usage, DateTime ExecutionDay) { return(await Init_HKCSE(client, Receiver, ReceiverIBAN, ReceiverBIC, Amount, Usage, ExecutionDay)); }
public static async Task <String> HKCUM(FinTsClient client, string Receiver, string ReceiverIBAN, string ReceiverBIC, decimal Amount, string Usage) { return(await Init_HKCUM(client, Receiver, ReceiverIBAN, ReceiverBIC, Amount, Usage)); }
public static async Task <String> HKDSE(FinTsClient client, string Payer, string PayerIBAN, string PayerBIC, decimal Amount, string Usage, DateTime SettlementDate, string MandateNumber, DateTime MandateDate, string CeditorIDNumber) { return(await Init_HKDSE(client, Payer, PayerIBAN, PayerBIC, Amount, Usage, SettlementDate, MandateNumber, MandateDate, CeditorIDNumber)); }
public static async Task <String> HKDME(FinTsClient client, DateTime SettlementDate, List <Pain00800202CcData> PainData, string NumberofTransactions, decimal TotalAmount) { return(await Init_HKDME(client, SettlementDate, PainData, NumberofTransactions, TotalAmount)); }
/// <summary> /// Parsing segment -> UPD, BPD /// </summary> /// <param name="UserID"></param> /// <param name="BLZ"></param> /// <param name="HBCIVersion"></param> /// <param name="Message"></param> /// <returns></returns> public static List <HBCIBankMessage> Parse_Segment(FinTsClient client, string Message) { try { var connDetails = client.ConnectionDetails; List <HBCIBankMessage> result = new List <HBCIBankMessage>(); string[] values = Message.Split('\''); string msg = string.Join(Environment.NewLine, values); string bpd = string.Empty; string upd = string.Empty; var bpaMatch = Regex.Match(msg, @"(HIBPA.+?)\b(HNHBS|HISYN|HIUPA)\b", RegexOptions.Singleline); if (bpaMatch.Success) { bpd = bpaMatch.Groups[1].Value; } var upaMatch = Regex.Match(msg, @"(HIUPA.+?)\b(HITAN|HNHBS)\b", RegexOptions.Singleline); if (upaMatch.Success) { upd = upaMatch.Groups[1].Value; } // BPD SaveBPD(connDetails.Blz, bpd); BPD.ParseBpd(bpd); // UPD SaveUPD(connDetails.Blz, connDetails.UserId, upd); UPD.ParseUpd(upd); foreach (var item in values) { if (item.Contains("HIRMG")) { // HIRMG:2:2+9050::Die Nachricht enthält Fehler.+9800::Dialog abgebrochen+9010::Initialisierung fehlgeschlagen, Auftrag nicht bearbeitet. // HIRMG:2:2+9800::Dialogabbruch. string[] HIRMG_messages = item.Split('+'); foreach (var HIRMG_message in HIRMG_messages) { var message = Parse_BankCode_Message(HIRMG_message); if (message != null) { result.Add(message); } } } if (item.Contains("HIRMS")) { // HIRMS:3:2:2+9942::PIN falsch. Zugang gesperrt.' string[] HIRMS_messages = item.Split('+'); foreach (var HIRMS_message in HIRMS_messages) { var message = Parse_BankCode_Message(HIRMS_message); if (message != null) { result.Add(message); } } var securityMessage = result.FirstOrDefault(m => m.Code == "3920"); if (securityMessage != null) { string message = securityMessage.Message; string TAN = string.Empty; string TANf = string.Empty; string[] procedures = Regex.Split(message, @"\D+"); foreach (string value in procedures) { if (!string.IsNullOrEmpty(value) && int.TryParse(value, out int i)) { if (Convert.ToString(i).StartsWith("9")) { if (string.IsNullOrEmpty(TAN)) { TAN = i.ToString(); } if (string.IsNullOrEmpty(TANf)) { TANf = i.ToString(); } else { TANf += $";{i}"; } } } } if (string.IsNullOrEmpty(client.HIRMS)) { client.HIRMS = TAN; } else { if (!TANf.Contains(client.HIRMS)) { throw new Exception($"Invalid HIRMS/Tan-Mode {client.HIRMS} detected. Please choose one of the allowed modes: {TANf}"); } } client.HIRMSf = TANf; // Parsing TAN processes if (!string.IsNullOrEmpty(client.HIRMS)) { Parse_TANProcesses(client, bpd); } } } if (item.Contains("HNHBK")) { var ID = Parse_String(item.ToString(), "+1+", ":1"); client.HNHBK = ID; } if (item.Contains("HISYN")) { var ID = item.Substring(item.IndexOf("+") + 1); client.SystemId = ID; Log.Write("Customer System ID: " + ID); } if (item.Contains("HNHBS")) { var item_ = item + "'"; var MSG = Parse_String(item_.Replace("HNHBS:", ""), "+", "'"); if (MSG.Equals("0") || MSG == null) { client.HNHBS = "2"; } else { client.HNHBS = Convert.ToString(Convert.ToInt16(MSG) + 1); } } if (item.Contains("HISALS")) { var SEG = Parse_String(item.Replace("HISALS:", ""), ":", ":"); client.HISALS = SEG; client.HISALSf = item; } if (item.Contains("HITANS")) { var TAN = Parse_String(item.Replace("HITANS:", ""), ":", "+").Replace(":", "+"); if (!string.IsNullOrEmpty(client.HITANS) && TAN == "7+4") { ; // Ignore HKTAN version 7 if other version is available and version 7 isn't implemented in libfintx } else { client.HITANS = TAN; } } if (item.Contains("HKKAZ")) { string pattern = @"HKKAZ;.*?;"; Regex rgx = new Regex(pattern); string sentence = item; foreach (Match match in rgx.Matches(sentence)) { var VER = Parse_String(match.Value, "HKKAZ;", ";"); if (string.IsNullOrEmpty(client.HKKAZ)) { client.HKKAZ = VER; } else { if (int.Parse(VER) > int.Parse(client.HKKAZ)) { client.HKKAZ = VER; } } } } if (item.Contains("HISPAS")) { if (item.Contains("pain.001.001.03")) { client.HISPAS = 1; } else if (item.Contains("pain.001.002.03")) { client.HISPAS = 2; } else if (item.Contains("pain.001.003.03")) { client.HISPAS = 3; } if (client.HISPAS == 0) { client.HISPAS = 3; // -> Fallback. Most banks accept the newest pain version } } } // Fallback if HKKAZ is not delivered by BPD (eg. Postbank) if (string.IsNullOrEmpty(client.HKKAZ)) { client.HKKAZ = "5"; } return(result); } catch (Exception ex) { Log.Write(ex.ToString()); throw new InvalidOperationException($"Software error.", ex); } }
/// <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; 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> /// Transactions in camt053 format /// </summary> public static async Task <String> Init_HKCAZ(FinTsClient client, string FromDate, string ToDate, string Startpoint, CamtVersion camtVers) { string segments = string.Empty; var connectionDetails = client.ConnectionDetails; client.SEGNUM = SEGNUM.SETInt(3); switch (camtVers) { case CamtVersion.Camt052: Log.Write("Starting job HKCAZ: Request transactions in camt052 format"); if (string.IsNullOrEmpty(FromDate)) { if (string.IsNullOrEmpty(Startpoint)) { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt052 + "+N'"; } else { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt052 + "+N++++" + Startpoint + "'"; } } else { if (string.IsNullOrEmpty(Startpoint)) { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt052 + "+N+" + FromDate + "+" + ToDate + "'"; } else { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt052 + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } } client.SEGNUM = SEGNUM.SETInt(3); break; case CamtVersion.Camt053: Log.Write("Starting job HKCAZ: Request transactions in camt053 format"); if (string.IsNullOrEmpty(FromDate)) { if (string.IsNullOrEmpty(Startpoint)) { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt053 + "+N'"; } else { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt053 + "+N++++" + Startpoint + "'"; } } else { if (string.IsNullOrEmpty(Startpoint)) { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt053 + "+N+" + FromDate + "+" + ToDate + "'"; } else { segments = "HKCAZ:" + client.SEGNUM + ":" + client.HICAZS + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+" + CamtScheme.Camt053 + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } } break; default: // -> Will never happen, only for compiler return(string.Empty); } if (Helper.IsTANRequired("HKCAZ")) { client.SEGNUM = SEGNUM.SETInt(4); segments = HKTAN.Init_HKTAN(client, segments, "HKCAZ"); } string message = FinTSMessage.Create(client, client.HNHBS, client.HNHBK, segments, client.HIRMS); string response = await FinTSMessage.Send(client, message); Helper.Parse_Message(client, response); return(response); }
/// <summary> /// Transactions /// </summary> public static async Task <String> Init_HKKAZ(FinTsClient client, string FromDate, string ToDate, string Startpoint) { Log.Write("Starting job HKKAZ: Request transactions"); var connectionDetails = client.ConnectionDetails; string segments = string.Empty; client.SEGNUM = SEGNUM.SETInt(3); if (string.IsNullOrEmpty(FromDate)) { if (string.IsNullOrEmpty(Startpoint)) { if (Convert.ToInt16(client.HKKAZ) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N'"; } } else { if (Convert.ToInt16(client.HKKAZ) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N++++" + Startpoint + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N++++" + Startpoint + "'"; } } } else { if (string.IsNullOrEmpty(Startpoint)) { if (Convert.ToInt16(client.HKKAZ) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N+" + FromDate + "+" + ToDate + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N+" + FromDate + "+" + ToDate + "'"; } } else { if (Convert.ToInt16(client.HKKAZ) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HKKAZ + "+" + connectionDetails.Iban + ":" + connectionDetails.Bic + ":" + connectionDetails.Account + "::280:" + connectionDetails.Blz + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } } } if (Helper.IsTANRequired("HKKAZ")) { client.SEGNUM = SEGNUM.SETInt(4); segments = HKTAN.Init_HKTAN(client, segments); } string message = FinTSMessage.Create(client, client.HNHBS, client.HNHBK, segments, client.HIRMS); string response = await FinTSMessage.Send(client, message); client.HITAN = Helper.Parse_String(Helper.Parse_String(response, "HITAN", "'").Replace("?+", "??"), "++", "+").Replace("??", "?+"); Helper.Parse_Message(client, response); return(response); }
/// <summary> /// Parsing segment -> UPD, BPD /// </summary> /// <param name="UserID"></param> /// <param name="BLZ"></param> /// <param name="HBCIVersion"></param> /// <param name="Message"></param> /// <returns></returns> public static List <HBCIBankMessage> Parse_Segments(FinTsClient client, string Message) { try { var connDetails = client.ConnectionDetails; List <HBCIBankMessage> result = new List <HBCIBankMessage>(); List <string> values = SplitSegments(Message); List <Segment> segments = new List <Segment>(); foreach (var item in values) { Segment segment = Parse_Segment(item); if (segment != null) { segments.Add(segment); } } string msg = string.Join(Environment.NewLine, values); string bpd = string.Empty; string upd = string.Empty; var bpaMatch = Regex.Match(msg, @"(HIBPA.+?)\b(HNHBS|HISYN|HIUPA)\b", RegexOptions.Singleline); if (bpaMatch.Success) { bpd = bpaMatch.Groups[1].Value; } var upaMatch = Regex.Match(msg, @"(HIUPA.+?)\b(HITAN|HNHBS)\b", RegexOptions.Singleline); if (upaMatch.Success) { upd = upaMatch.Groups[1].Value; } // BPD SaveBPD(connDetails.Blz, bpd); BPD.ParseBpd(bpd); // UPD SaveUPD(connDetails.Blz, connDetails.UserId, upd); UPD.ParseUpd(upd); //Add BIC to Account information (Not retrieved bz UPD??) foreach (AccountInformation accInfo in UPD.HIUPD.AccountList) { accInfo.AccountBic = connDetails.Bic; } foreach (var segment in segments) { if (segment.Name == "HIRMG") { // HIRMG:2:2+9050::Die Nachricht enthält Fehler.+9800::Dialog abgebrochen+9010::Initialisierung fehlgeschlagen, Auftrag nicht bearbeitet. // HIRMG:2:2+9800::Dialogabbruch. string[] HIRMG_messages = segment.Payload.Split('+'); foreach (var HIRMG_message in HIRMG_messages) { var message = Parse_BankCode_Message(HIRMG_message); if (message != null) { result.Add(message); } } } if (segment.Name == "HIRMS") { // HIRMS:3:2:2+9942::PIN falsch. Zugang gesperrt.' string[] HIRMS_messages = segment.Payload.Split('+'); foreach (var HIRMS_message in HIRMS_messages) { var message = Parse_BankCode_Message(HIRMS_message); if (message != null) { result.Add(message); } } var securityMessage = result.FirstOrDefault(m => m.Code == "3920"); if (securityMessage != null) { string message = securityMessage.Message; string TAN = string.Empty; string TANf = string.Empty; string[] procedures = Regex.Split(message, @"\D+"); foreach (string value in procedures) { if (!string.IsNullOrEmpty(value) && int.TryParse(value, out int i)) { if (Convert.ToString(i).StartsWith("9")) { if (string.IsNullOrEmpty(TAN)) { TAN = i.ToString(); } if (string.IsNullOrEmpty(TANf)) { TANf = i.ToString(); } else { TANf += $";{i}"; } } } } if (string.IsNullOrEmpty(client.HIRMS)) { client.HIRMS = TAN; } else { if (!TANf.Contains(client.HIRMS)) { throw new Exception($"Invalid HIRMS/Tan-Mode {client.HIRMS} detected. Please choose one of the allowed modes: {TANf}"); } } client.HIRMSf = TANf; // Parsing TAN processes if (!string.IsNullOrEmpty(client.HIRMS)) { Parse_TANProcesses(client, bpd); } } } if (segment.Name == "HNHBK") { var ID = Parse_String(segment.Payload, "+1+", ":1"); client.HNHBK = ID; } if (segment.Name == "HISYN") { client.SystemId = segment.Payload; Log.Write("Customer System ID: " + client.SystemId); } if (segment.Name == "HNHBS") { if (segment.Payload == null || segment.Payload == "0") { client.HNHBS = 2; } else { client.HNHBS = Convert.ToInt32(segment.Payload) + 1; } } if (segment.Name == "HISALS") { client.HISALS = segment.Version; } if (segment.Name == "HITANS") { if (client.HITANS != 0 && segment.Version == 7) { ; // Ignore HKTAN version 7 if other version is available and version 7 isn't implemented in libfintx } else { client.HITANS = segment.Version; } } if (segment.Name == "HITAN") { client.HITAN = Parse_String(segment.Payload.Replace("?+", "??"), "++", "+").Replace("??", "?+"); } if (segment.Name == "HIKAZS") { if (client.HIKAZS == 0) { client.HIKAZS = segment.Version; } else { if (segment.Version > client.HIKAZS) { client.HIKAZS = segment.Version; } } } if (segment.Name == "HISPAS") { if (segment.Payload.Contains("pain.001.001.03")) { client.HISPAS = 1; } else if (segment.Payload.Contains("pain.001.002.03")) { client.HISPAS = 2; } else if (segment.Payload.Contains("pain.001.003.03")) { client.HISPAS = 3; } if (client.HISPAS == 0) { client.HISPAS = 3; // -> Fallback. Most banks accept the newest pain version } } } // Fallback if HIKAZS is not delivered by BPD (eg. Postbank) if (client.HIKAZS == 0) { client.HIKAZS = 0; } return(result); } catch (Exception ex) { Log.Write(ex.ToString()); throw new InvalidOperationException($"Software error.", ex); } }
public static async Task <String> HKSAL(FinTsClient client) { return(await Init_HKSAL(client)); }
public static async Task <String> HKPPD(FinTsClient client, int MobileServiceProvider, string PhoneNumber, int Amount) { return(await Init_HKPPD(client, MobileServiceProvider, PhoneNumber, Amount)); }
public static async Task <String> HKKAZ(FinTsClient client, string FromDate, string ToDate, string Startpoint) { return(await Init_HKKAZ(client, FromDate, ToDate, Startpoint)); }
public static async Task <String> HKCDL(FinTsClient client, string OrderId, string Receiver, string ReceiverIBAN, string ReceiverBIC, decimal Amount, string Usage, DateTime FirstTimeExecutionDay, TimeUnit TimeUnit, string Rota, int ExecutionDay, DateTime?LastExecutionDay) { return(await Init_HKCDL(client, OrderId, Receiver, ReceiverIBAN, ReceiverBIC, Amount, Usage, FirstTimeExecutionDay, TimeUnit, Rota, ExecutionDay, LastExecutionDay)); }
public static async Task <String> HKCME(FinTsClient client, List <Pain00100203CtData> PainData, string NumberofTransactions, decimal TotalAmount, DateTime ExecutionDay) { return(await Init_HKCME(client, PainData, NumberofTransactions, TotalAmount, ExecutionDay)); }
public static async Task <String> TAN(FinTsClient client, string TAN) { return(await Send_TAN(client, TAN)); }
/// <summary> /// Transactions /// </summary> public static async Task <String> Init_HKKAZ(FinTsClient client, string FromDate, string ToDate, string Startpoint) { Log.Write("Starting job HKKAZ: Request transactions"); var connectionDetails = client.ConnectionDetails; string segments = string.Empty; AccountInformation activeAccount; if (client.activeAccount != null) { activeAccount = client.activeAccount; } else { activeAccount = new AccountInformation() { AccountNumber = connectionDetails.Account, AccountBankCode = connectionDetails.Blz.ToString(), AccountIban = connectionDetails.Iban, AccountBic = connectionDetails.Bic, } }; client.SEGNUM = SEGNUM.SETInt(3); if (string.IsNullOrEmpty(FromDate)) { if (string.IsNullOrEmpty(Startpoint)) { if (Convert.ToInt16(client.HIKAZS) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountIban + ":" + activeAccount.AccountBic + ":" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N'"; } } else { if (Convert.ToInt16(client.HIKAZS) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N++++" + Startpoint + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountIban + ":" + activeAccount.AccountBic + ":" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N++++" + Startpoint + "'"; } } } else { if (string.IsNullOrEmpty(Startpoint)) { if (Convert.ToInt16(client.HIKAZS) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N+" + FromDate + "+" + ToDate + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountIban + ":" + activeAccount.AccountBic + ":" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N+" + FromDate + "+" + ToDate + "'"; } } else { if (Convert.ToInt16(client.HIKAZS) < 7) { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } else { segments = "HKKAZ:" + client.SEGNUM + ":" + client.HIKAZS + "+" + activeAccount.AccountIban + ":" + activeAccount.AccountBic + ":" + activeAccount.AccountNumber + "::280:" + activeAccount.AccountBankCode + "+N+" + FromDate + "+" + ToDate + "++" + Startpoint + "'"; } } } if (Helper.IsTANRequired("HKKAZ")) { client.SEGNUM = SEGNUM.SETInt(4); segments = HKTAN.Init_HKTAN(client, segments, "HKKAZ"); } string message = FinTSMessage.Create(client, client.HNHBS, client.HNHBK, segments, client.HIRMS); string response = await FinTSMessage.Send(client, message); Helper.Parse_Message(client, response); return(response); } }
/// <summary> /// Create FinTS message /// </summary> /// <param name="client"></param> /// <param name="Segments"></param> /// <param name="SegmentNum"></param> /// <returns></returns> public static string CreateSync(FinTsClient client, string Segments) { return(Create(client, "1", "0", Segments, null, "0")); }