Imports System.IO Imports System.Xml.Linq Imports com.sun.xml.internal.rngom.parse.compact Imports Org.BouncyCastle.Ocsp Imports Polly Imports CC015B_TR_EXT_V4_3 Imports CC304A_v10_0 Imports CC305A_v10_0 Imports CC316A_v10_0 Imports CC328A_v10_0 Imports ENS_CC315A Imports VERAG_PROG_ALLGEMEIN.ENS_CC315A Imports VERAG_PROG_ALLGEMEIN.CC304A_v10_0 Imports VERAG_PROG_ALLGEMEIN.CC316A_v10_0 Imports VERAG_PROG_ALLGEMEIN.CC328A_v10_0 Imports VERAG_PROG_ALLGEMEIN.CC305A_v10_0 Public Class cHMRC_ENS '---> VERAG AG!!! GVMS use 26 86 22 45 50 78? Public Shared ApplicationName = "AVISO_ENS" Public Shared ApplicationID = "af3dc225-6726-4cba-98e6-9b8df39b4c20" Public Shared Client_ID = "Qbwx6C1YYdc6q4XM0aWOKZGH0zyO" Public Shared Client_Secret = "143a33cc-33c8-43bb-bcca-51186ac52855" Public Shared TEST As Boolean = True Shared Function helloWorldENS(ByVal response As String) As Boolean Try VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS_HELLOWORLD") If TOKEN.hasEntry Then ' HTTP-Client initialisieren Dim http As New Chilkat.Http ' Falls das Token fehlt, Hinweis ausgeben If String.IsNullOrEmpty(TOKEN.token_BEARER_TOKEN) Then Console.WriteLine("Fehler: Kein OAuth2-Token gefunden!") Return False End If ' Setze die benötigten Header http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") http.SetRequestHeader("Content-Type", "application/xml; charset=UTF-8") http.SetRequestHeader("Authorization", "Bearer " & TOKEN.token_BEARER_TOKEN) ' API-Endpunkt für User-Restricted Hello API Dim url As String = "https://test-api.service.hmrc.gov.uk/hello/application" 'Dim url As String = "https://test-api.service.hmrc.gov.uk/hello/user" ' API-Anfrage senden response = http.QuickGetStr(url) ' Fehlerbehandlung If (http.LastMethodSuccess <> True) Then Console.WriteLine("Fehler: " & http.LastErrorText) MsgBox("Fehler: " & http.LastErrorText) Else Console.WriteLine("Antwort von HMRC API: " & response) MsgBox("Antwort von HMRC API: " & response) End If Return True End If Catch ex As Exception cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return False End Function Shared Function insertENS(ENS_CC315A As CC315AType, ByVal responseStr As String, Optional forceRefrehtoken As Boolean = False) As Boolean Try ' Chilkat-Objekt initialisieren ' Dim http As New Chilkat.Http() ' EORI-Nummer für die Überprüfung 'Dim eoriNumber As String = "GB123456789000" Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() '------------------------------------------------------- 'TEEST::: ENS_CC315A = CC315AType.LoadFromFile("D:\Andreas\TMP\CC315A_Example1.xml") ENS_CC315A.DatOfPreMES9 = Now.ToString("yyMMdd") ENS_CC315A.TimOfPreMES10 = Now.ToString("HHmm") If False Then If ENS_CC315A Is Nothing Then 'Return False 'FEHLER!??!? ENS_CC315A = New CC315AType '-> nur zum testen End If If ENS_CC315A.MesSenMES3 Is Nothing OrElse ENS_CC315A.MesSenMES3 = "" Then ENS_CC315A.MesSenMES3 = "GB552556002342" 'TEST USER 790949012321 End If ENS_CC315A.DatOfPreMES9 = Now.ToString("yyMMdd") ENS_CC315A.TimOfPreMES10 = Now.ToString("HHmm") ENS_CC315A.MesIdeMES19 = "ABCD1234" 'ENS_CC315A.MesTypMES20 = "CC315A" ENS_CC315A.HEAHEA.RefNumHEA4 = "ABCD1234" ENS_CC315A.HEAHEA.TraModAtBorHEA76 = "4" ENS_CC315A.HEAHEA.TotNumOfIteHEA305 = "1" End If '------------------------------------------------------- Dim TOKEN = cHMRC.getTOKEN("ENS", forceRefrehtoken) If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Setzen des Content-Type-Headers für die Anfrage If cHMRC_ENS.TEST Then Dim mode = "Accept" http.SetRequestHeader("simulateRiskingResponse", mode) http.SetRequestHeader("simulateInterventionResponse", True) End If http.SetRequestHeader("Content-Type", "application/xml; charset=UTF-8") ' Definieren Sie die URL für die POST-Anfrage Dim urlHTTP As String = url & "/customs/imports/declarations" Dim xmlContent As String = ENS_CC315A.Serialize xmlContent = File.ReadAllText("D:\Andreas\TMP\CC315A_Example1.xml") MsgBox(xmlContent) ' Senden Sie die POST-Anfrage mit dem XML-Inhalt Dim response As Chilkat.HttpResponse = http.PostXml(urlHTTP, xmlContent, "utf-8") If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return False End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 202) Then Console.WriteLine("Entry Summary Declaration erfolgreich eingereicht.") Console.WriteLine("Antwort:") Console.WriteLine(response.BodyStr) Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim RESP = SuccessResponse_v2_0.SuccessResponse.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return True ElseIf (response.StatusCode = 400) Then Console.WriteLine("Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Dim errTxt = "" Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim RESP = errorresponse_v2_0.ErrorResponse.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try For Each Erline In RESP.Error errTxt &= String.Join(", ", Erline.Text) & vbNewLine & vbNewLine Next MsgBox(errTxt) Return False Else Console.WriteLine("Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return False End If 'Dim req As New Chilkat.HttpRequest() '' Setze deine HMRC API-Credentials 'http.AuthToken = TOKEN.token_BEARER_TOKEN 'req.HttpVerb = "POST" 'req.Path = "/customs/imports/declarations" 'req.ContentType = "application/xml" 'req.Charset = "utf-8" 'req.SendCharset = True '' Füge das XML als Body hinzu 'req.LoadBodyFromString(ENS_CC315A.Serialize, "utf-8") '' Füge benötigte Header hinzu 'req.AddHeader("Accept", "application/vnd.hmrc.1.0+xml") '"application/vnd.hmrc.1.0+xml") 'req.AddHeader("Content-Type", "application/xml; charset=UTF-8") '"application/xml") 'req.AddHeader("Authorization", "Bearer " & TOKEN.token_BEARER_TOKEN) 'MsgBox(TOKEN.token_BEARER_TOKEN) '' Sende die Anfrage 'Dim resp As Chilkat.HttpResponse = http.SynchronousRequest(url, 443, True, req) 'If resp Is Nothing Then ' Console.WriteLine("Fehler: " & http.LastErrorText) 'Else ' Console.WriteLine("Status Code: " & resp.StatusCode) ' Console.WriteLine("Antwort: " & resp.BodyStr) 'End If 'Return True End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return False End Function Shared Function amendENS(MRN As String, ByRef CC313AResponse As CC315AType) As Boolean Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http ' Token hinzufügen (z. B. Bearer Token für Authentifizierung) http.SetRequestHeader("Authorization", "Bearer " & TOKEN.token_BEARER_TOKEN) ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Setzen des Content-Type-Headers (kann erforderlich sein) http.SetRequestHeader("Content-Type", "application/xml; charset=UTF-8") If cHMRC_ENS.TEST Then Dim mode = "Accept" http.SetRequestHeader("simulateRiskingResponse", mode) End If ' Definieren Sie die URL für die PUT-Anfrage Dim urlHttp As String = url & "/customs/imports/declarations/" & MRN & "" ' Senden Sie die PUT-Anfrage ohne Body Dim xmlContent = File.ReadAllText("D:\Andreas\TMP\example_Amend.xml") MsgBox(xmlContent) ' Senden Sie die POST-Anfrage mit dem XML-Inhalt ' Sende die PUT-Anfrage mit XML-Daten Dim response As Chilkat.HttpResponse = http.PText("PUT", urlHttp, xmlContent, "utf-8", "application/xml", False, False) ' Dim response As Chilkat.HttpResponse = http.QuickRequest("PUT", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return False End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 200) Then Console.WriteLine("Entry Summary Declaration erfolgreich geändert.") Console.WriteLine("Antwort:") Console.WriteLine(response.BodyStr) ' XML-Ausgabe der Antwort Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) CC313AResponse = CC315AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return True Else Console.WriteLine("❌ Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return False End If End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return False End Function Shared Function getListOfENSOutcomes() As List(Of HmrcOutcomes) Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Definieren Sie die URL für die GET-Anfrage Dim urlHttp As String = url & "/customs/imports/outcomes/" ' Senden Sie die GET-Anfrage Dim response As Chilkat.HttpResponse = http.QuickRequest("GET", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return Nothing End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 204) Then Console.WriteLine("Ergebnis: Kein Inhalt!") Console.WriteLine(response.BodyStr) Return Nothing End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 200) Then Console.WriteLine("Liste der Outcomes erfolgreich abgerufen:") Console.WriteLine(response.BodyStr) ' XML-Ausgabe der Antwort Dim HmrcOutcomesList As List(Of HmrcOutcomes) = ParseHmrcXmlResponseOutcomes(response.BodyStr) Return HmrcOutcomesList Else Console.WriteLine("Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return Nothing End If End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return Nothing End Function Shared Function retrieveENSOutcome(correlationId, ByRef TypeOfResonse, ByRef ResponseClass) As Boolean Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Definieren Sie die URL für die GET-Anfrage 'If cHMRC_ENS.TEST Then ' Dim mode = "Accept" ' http.SetRequestHeader("simulateRiskingResponse", mode) 'End If Dim urlHttp As String = url & "/customs/imports/outcomes/" & correlationId & "" MsgBox(urlHttp) ' Senden Sie die GET-Anfrage Dim response As Chilkat.HttpResponse = http.QuickRequest("GET", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return Nothing End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 200) Then Console.WriteLine("Outcome erfolgreich abgerufen:") Console.WriteLine(response.BodyStr) ' XML-Ausgabe der Antwort If response.BodyStr.Contains("CC328A") Then ' ANTWORT OK New submission accepted: Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim CC328A = CC328AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try TypeOfResonse = "CC328A" ResponseClass = CC328A Return True ElseIf response.BodyStr.Contains("CC316A") Then ' ANTWORT OK New submission rejected: Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim CC316A = CC316AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try TypeOfResonse = "CC316A" ResponseClass = CC316A Return True ElseIf response.BodyStr.Contains("CC304A") Then ' Amended submission accepted Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim CC304A = CC304AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try TypeOfResonse = "CC304A" ResponseClass = CC304A Return True ElseIf response.BodyStr.Contains("CC305A") Then ' Amended submission rejected Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim CC305A = CC305AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try TypeOfResonse = "CC305A" ResponseClass = CC305A Return True End If Else Console.WriteLine("Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return Nothing End If ' The Outcome for the Correlation ID (schema here). 'An accepted outcome which Is successful will contain a Movement Reference Number. A rejected outcome will contain one Or more errors. Accordingly, the content of response element will be based on one of the following schemas: ' New submission accepted schema http //ics.dgtaxud.ec/CC328A. ' New submission rejected: schema http: //ics.dgtaxud.ec/CC316A. ' Amended submission accepted: schema http: //ics.dgtaxud.ec/CC304A. ' Amended submission rejected: schema http: //ics.dgtaxud.ec/CC305A. End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return Nothing End Function Shared Function acknowlageENSOutcome(correlationId) As Boolean Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Setzen des Content-Type-Headers für die Anfrage http.SetRequestHeader("Content-Type", "application/xml") ' Definieren Sie die URL für die POST-Anfrage Dim urlHttp As String = url & "/customs/imports/outcomes/" & correlationId & "" ' Senden Sie die POST-Anfrage ohne Body Dim response As Chilkat.HttpResponse = http.QuickRequest("DELETE", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return False End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 200) Then Console.WriteLine("✅ Benachrichtigung erfolgreich bestätigt.") Return True Else Console.WriteLine("❌ Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return False End If End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return False End Function Shared Function getENSNotifications() As List(Of HmrcNotification) Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Falls eine Authentifizierung erforderlich ist, setzen Sie den API-Schlüssel oder andere Authentifizierungsheader http.SetRequestHeader("Authorization", "Bearer " & TOKEN.token_BEARER_TOKEN) ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Definieren Sie die URL für die GET-Anfrage Dim urlHttpReq As String = url & "/customs/imports/notifications/" ' Senden Sie die GET-Anfrage und erhalten Sie die Antwort Dim response As Chilkat.HttpResponse = http.QuickRequest("GET", urlHttpReq) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return Nothing End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 204) Then Console.WriteLine("Ergebnis: Kein Inhalt!") Console.WriteLine(response.BodyStr) Return Nothing End If If (response.StatusCode <> 200) Then Console.WriteLine("Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return Nothing End If ' Verarbeiten Sie den Antworttext (XML) Dim xmlResponse As String = response.BodyStr Console.WriteLine("Antwort erhalten:") Console.WriteLine(xmlResponse) Dim NotificationList As List(Of HmrcNotification) = ParseHmrcXmlResponse(xmlResponse) Return NotificationList End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return Nothing End Function Public Shared Function ParseHmrcXmlResponse(xmlResponse As String) As List(Of HmrcNotification) Dim notifications As New List(Of HmrcNotification) Try ' XML in ein XElement-Objekt laden Dim xml As XElement = XElement.Parse(xmlResponse) ' Alle -Elemente durchlaufen For Each response As XElement In xml.Elements("response") Dim notification As New HmrcNotification With { .CorrelationId = response.Element("correlationId")?.Value, .NotificationId = response.Element("notificationId")?.Value, .Link = response.Element("link")?.Value } notifications.Add(notification) Next Catch ex As Exception Console.WriteLine("Fehler beim Parsen der XML-Antwort: " & ex.Message) End Try Return notifications End Function Public Shared Function ParseHmrcXmlResponseOutcomes(xmlResponse As String) As List(Of HmrcOutcomes) Dim outcomes As New List(Of HmrcOutcomes) Try ' XML in ein XElement-Objekt laden Dim xml As XElement = XElement.Parse(xmlResponse) ' Alle -Elemente durchlaufen For Each response As XElement In xml.Elements("response") Dim notification As New HmrcOutcomes With { .CorrelationId = response.Element("correlationId")?.Value, .MRN = response.Element("MRN")?.Value, .Link = response.Element("link")?.Value } outcomes.Add(notification) Next Catch ex As Exception Console.WriteLine("Fehler beim Parsen der XML-Antwort: " & ex.Message) End Try Return outcomes End Function Shared Function acknowlageENSNotification(notificationID) As Boolean Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Setzen des Content-Type-Headers für die Anfrage http.SetRequestHeader("Content-Type", "application/xml") ' Definieren Sie die URL für die POST-Anfrage Dim urlHttp As String = url & "/customs/imports/notifications/" & notificationID & "" ' Senden Sie die POST-Anfrage ohne Body Dim response As Chilkat.HttpResponse = http.QuickRequest("DELETE", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText) Return False End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 204) Then Console.WriteLine("✅ Benachrichtigung erfolgreich bestätigt.") Return True Else Console.WriteLine("❌ Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return False End If End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return False End Function Shared Function readENSNotification(notificationID) As CC315AType Try Dim CREDENTIALS = cHMRC.getCredentials(ApplicationName) Dim url As String = CREDENTIALS.API_STRING ' URL Setzenen https://api.service.hmrc.gov.uk / https://test-api.service.hmrc.gov.uk VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat() Dim TOKEN = cHMRC.getTOKEN("ENS") If TOKEN.hasEntry Then ' Erstellen Sie eine Instanz des Http-Objekts Dim http As New Chilkat.Http() ' Authentifizierung: Setzen des Bearer-Tokens http.AuthToken = TOKEN.token_BEARER_TOKEN ' Setzen des Accept-Headers für die erwartete Antwort im XML-Format http.SetRequestHeader("Accept", "application/vnd.hmrc.1.0+xml") ' Definieren Sie die URL für die GET-Anfrage Dim urlHttp As String = url & "/customs/imports/notifications/" & notificationID & "" ' Senden Sie die GET-Anfrage Dim response As Chilkat.HttpResponse = http.QuickRequest("GET", urlHttp) If (http.LastMethodSuccess = False) Then Console.WriteLine("❌ Fehler bei der Anfrage: " & http.LastErrorText) Return Nothing End If ' Überprüfen Sie den HTTP-Statuscode der Antwort If (response.StatusCode = 200) Then Console.WriteLine("✅ Benachrichtigung erfolgreich abgerufen:") Console.WriteLine(response.BodyStr) ' XML-Ausgabe Dim tempFilePath As String = Path.GetTempFileName() File.WriteAllText(tempFilePath, response.BodyStr) Dim ENS_CC315A = CC315AType.LoadFromFile(tempFilePath) Try File.Delete(tempFilePath) ' Bereinigen nach der Verwendung Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return ENS_CC315A Else Console.WriteLine("❌ Fehler: HTTP Statuscode " & response.StatusCode) Console.WriteLine(response.BodyStr) Return Nothing End If End If Catch ex As Exception VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) End Try Return Nothing End Function ' Klasse zur Speicherung einer einzelnen Notification Public Class HmrcNotification Public Property CorrelationId As String Public Property NotificationId As String Public Property Link As String End Class ' Klasse zur Speicherung einer einzelnen Notification Public Class HmrcOutcomes Public Property CorrelationId As String Public Property MRN As String Public Property Link As String End Class End Class