CBAM Auswertung; Verzollungspreise; T2 aus EXG manuell

This commit is contained in:
2025-02-24 15:10:30 +01:00
parent 44f746b1c5
commit ac33d5e1d1
9 changed files with 1699 additions and 291 deletions

View File

@@ -333,7 +333,7 @@ Public Class cHMRC
' genGVMS_GMR(AccessToken)
'End If
End Sub
Shared Sub grantAccess(ByRef AccessToken, scope, HMRC_APPLICATION)
Shared Sub grantAccess(ByRef AccessToken, ByRef RefreshToken, scope, HMRC_APPLICATION)
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
@@ -458,6 +458,7 @@ Public Class cHMRC
' MsgBox("OAuth2 authorization granted!")
Debug.WriteLine("OAuth2 authorization granted!")
Debug.WriteLine("Access Token = " & oauth2.AccessToken)
Debug.WriteLine("Refresh Token = " & oauth2.RefreshToken)
Dim json As Chilkat.JsonObject = New Chilkat.JsonObject()
json.Load(oauth2.AccessTokenResponse)
json.EmitCompact = False
@@ -495,6 +496,10 @@ Public Class cHMRC
'fac.WriteEntireTextFile("qa_data/tokens/hmrc.json", json.Emit(), "utf-8", False)
' fac.WriteEntireTextFile("C:\Users\DEVELOPER1\Desktop\hmrc.json", json.Emit(), "utf-8", False)
AccessToken = oauth2.AccessToken
RefreshToken = oauth2.RefreshToken
Catch ex As Exception
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
@@ -503,7 +508,7 @@ Public Class cHMRC
Shared Sub HMRC_RefreshToken(ByRef TOKEN As cHMRCToken, HMRC_APPLICATION As String)
If DateDiff(DateInterval.Minute, TOKEN.token_refresh_datetime, Now) < 230 Then 'bis 240 MIN / 4hr
If DateDiff(DateInterval.Minute, TOKEN.token_accestoken_datetime, Now) < 230 Then 'bis 240 MIN / 4hr
'Token ist noch frisch
Exit Sub
End If
@@ -527,11 +532,10 @@ Public Class cHMRC
Dim CREDENTIALS = getCredentials(HMRC_APPLICATION)
Dim TOKEN_NEW = ""
req.AddParam("client_secret", CREDENTIALS.CLIENT_SECRET)
req.AddParam("client_id", CREDENTIALS.CLIENT_ID)
req.AddParam("grant_type", "client_credentials")
req.AddParam("refresh_token", TOKEN_NEW)
req.AddParam("refresh_token", TOKEN.token_REFRESH_TOKEN)
@@ -565,8 +569,9 @@ Public Class cHMRC
'json.EmitCompact = False
'json.WriteFile(tokenFile)
TOKEN.token_BEARER_TOKEN = If(accessToken <> "", accessToken, newRefreshToken)
TOKEN.token_refresh_datetime = Now
TOKEN.token_REFRESH_TOKEN = newRefreshToken
TOKEN.token_BEARER_TOKEN = accessToken
TOKEN.token_accestoken_datetime = Now
TOKEN.SAVE()
Console.WriteLine("Tokens wurden in TokenDB gespeichert.")
@@ -1538,13 +1543,18 @@ Public Class cHMRC
If forceNewToken OrElse TOKEN.hasEntry = False OrElse TOKEN.token_BEARER_TOKEN Is Nothing OrElse TOKEN.token_BEARER_TOKEN = "" Then
'Neuer Token
Dim AccessToken = ""
grantAccess(AccessToken, appl, HMRC_APPLICATION)
Dim RefreshToken = ""
grantAccess(AccessToken, RefreshToken, appl, HMRC_APPLICATION)
TOKEN.token_Application = APPLICATION
TOKEN.token_BEARER_TOKEN = AccessToken
TOKEN.token_REFRESH_TOKEN = RefreshToken
TOKEN.token_refresh_datetime = Now
TOKEN.token_accestoken_datetime = Now
TOKEN.SAVE()
Else
'Refresh
HMRC_RefreshToken(TOKEN, HMRC_APPLICATION)
End If

View File

@@ -3,12 +3,13 @@ Imports System.Reflection
Public Class cHMRCToken
Property token_id As Integer
Property token_BEARER_TOKEN As String = ""
Property token_BEARER_TOKEN As String = "" 'Accesstoken
Property token_datetime As Date = Now
Property token_Firma As String = VERAG_PROG_ALLGEMEIN.cAllgemein.FIRMA
Property token_Application As String = ""
Property token_refresh_datetime As Object = Nothing
Property token_refresh_datetime As Object = Nothing ' tmstmp für generelles refresh -> 18 Monate
Property token_accestoken_datetime As Object = Nothing ' Accesstoken 4 Std gültig
Property token_REFRESH_TOKEN As Object = Nothing ' wird wirds refresh benötigt
Public hasEntry = False
@@ -32,6 +33,8 @@ Public Class cHMRCToken
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_Firma", token_Firma))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_Application", token_Application))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_refresh_datetime", token_refresh_datetime))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_accestoken_datetime", token_accestoken_datetime))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("token_REFRESH_TOKEN", token_REFRESH_TOKEN))
Return list
End Function

View File

@@ -78,7 +78,7 @@ Public Class cHMRC_ENS
Return False
End Function
Shared Function insertENS(ENS_CC315A As CC315AType, ByVal responseStr As String) As Boolean
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()
@@ -128,7 +128,7 @@ Public Class cHMRC_ENS
Dim TOKEN = cHMRC.getTOKEN("ENS")
Dim TOKEN = cHMRC.getTOKEN("ENS", forceRefrehtoken)
If TOKEN.hasEntry Then
@@ -143,13 +143,22 @@ Public Class cHMRC_ENS
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")
xmlContent = File.ReadAllText("D:\Andreas\TMP\CC315A_Example1.xml")
MsgBox(xmlContent)
' Senden Sie die POST-Anfrage mit dem XML-Inhalt
@@ -275,31 +284,46 @@ Public Class cHMRC_ENS
' Erstellen Sie eine Instanz des Http-Objekts
Dim http As New Chilkat.Http()
Dim http As New Chilkat.Http
' Authentifizierung: Setzen des Bearer-Tokens
http.AuthToken = TOKEN.token_BEARER_TOKEN
' 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")
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 & "}"
Dim urlHttp As String = url & "/customs/imports/declarations/" & MRN & ""
' Senden Sie die PUT-Anfrage ohne Body
Dim response As Chilkat.HttpResponse = http.QuickRequest("PUT", urlHttp)
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)
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("Entry Summary Declaration erfolgreich geändert.")
Console.WriteLine("Antwort:")
Console.WriteLine(response.BodyStr) ' XML-Ausgabe der Antwort
@@ -432,8 +456,15 @@ Public Class cHMRC_ENS
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/{" & correlationId & "}"
'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)
@@ -572,10 +603,10 @@ Public Class cHMRC_ENS
' 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 & "}"
' 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("POST", urlHttp)
Dim response As Chilkat.HttpResponse = http.QuickRequest("DELETE", urlHttp)
If (http.LastMethodSuccess = False) Then
Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText)
@@ -583,7 +614,7 @@ Public Class cHMRC_ENS
End If
' Überprüfen Sie den HTTP-Statuscode der Antwort
If (response.StatusCode = 204) Then
If (response.StatusCode = 200) Then
Console.WriteLine("✅ Benachrichtigung erfolgreich bestätigt.")
Return True
Else
@@ -746,10 +777,10 @@ Public Class cHMRC_ENS
' 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 & "}/acknowledge"
' 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("POST", urlHttp)
Dim response As Chilkat.HttpResponse = http.QuickRequest("DELETE", urlHttp)
If (http.LastMethodSuccess = False) Then
Console.WriteLine("Fehler bei der Anfrage: " & http.LastErrorText)
@@ -803,7 +834,8 @@ Public Class cHMRC_ENS
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 & "}"
Dim urlHttp As String = url & "/customs/imports/notifications/" & notificationID & ""
' Senden Sie die GET-Anfrage
Dim response As Chilkat.HttpResponse = http.QuickRequest("GET", urlHttp)