mseAPI, KundeBearbeiten (DatevExport).
This commit is contained in:
@@ -25,37 +25,23 @@ Public Class cMSEAPI
|
||||
Public Function createJWT(ByRef failureText As String) As String
|
||||
Try
|
||||
|
||||
If apiSettingsloaded = False Then Return False
|
||||
|
||||
Dim jwt As New Chilkat.Jwt
|
||||
|
||||
' Build the JOSE header
|
||||
Dim jose As New Chilkat.JsonObject
|
||||
' Use HS256. Pass the string "HS384" or "HS512" to use a different algorithm.
|
||||
Dim success As Boolean = jose.AppendString("alg", "HS256")
|
||||
success = jose.AppendString("typ", "JWT")
|
||||
|
||||
' Now build the JWT claims (also known as the payload)
|
||||
Dim claims As New Chilkat.JsonObject
|
||||
success = claims.AppendString("iss", API.Rows(0).Item("api_user"))
|
||||
'success = claims.AppendString("sub", "")
|
||||
'success = claims.AppendString("aud", "http://example.com")
|
||||
|
||||
' Set the timestamp of when the JWT was created to now.
|
||||
Dim curDateTime As Integer = jwt.GenNumericDate(0)
|
||||
'success = claims.AddIntAt(-1, "iat", curDateTime)
|
||||
|
||||
' Set the "not process before" timestamp to now.
|
||||
'success = claims.AddIntAt(-1, "nbf", curDateTime)
|
||||
|
||||
' Set the timestamp defining an expiration time (end time) for the token
|
||||
' to be now + 1 hour (3600 seconds)
|
||||
success = claims.AddIntAt(-1, "exp", curDateTime + 3600)
|
||||
|
||||
' Produce the smallest possible JWT:
|
||||
jwt.AutoCompact = True
|
||||
|
||||
Dim strJwt As String = jwt.CreateJwt(jose.Emit(), claims.Emit(), API.Rows(0).Item("api_passwort"))
|
||||
Dim strJwt As String = jwt.CreateJwt(jose.Emit(), claims.Emit(), API.Rows(0).Item("api_password"))
|
||||
|
||||
Debug.WriteLine(strJwt)
|
||||
Return strJwt
|
||||
@@ -66,30 +52,48 @@ Public Class cMSEAPI
|
||||
|
||||
End Function
|
||||
|
||||
Public Function getTransactions(jwt As String) As String
|
||||
Public Function getNewestTransactions(jwt As String, dt As DataTable) As String
|
||||
Try
|
||||
Dim returnText As String = ""
|
||||
Dim failureText As String = ""
|
||||
|
||||
|
||||
|
||||
Dim success As Boolean
|
||||
|
||||
rest.VerboseLogging = True
|
||||
Dim bTls As Boolean = True
|
||||
Dim port As Integer = 443
|
||||
Dim bAutoReconnect As Boolean = True
|
||||
success = rest.Connect(API_STRING, port, bTls, bAutoReconnect)
|
||||
If (success <> True) Then
|
||||
Debug.WriteLine("ConnectFailReason: " & rest.ConnectFailReason)
|
||||
Debug.WriteLine(rest.LastErrorText)
|
||||
failureText = rest.LastErrorText
|
||||
Return False
|
||||
End If
|
||||
|
||||
If (success <> True) Then
|
||||
Debug.WriteLine("BAFailReason: " & rest.ConnectFailReason)
|
||||
Debug.WriteLine(rest.LastErrorText)
|
||||
failureText = rest.LastErrorText
|
||||
Return False
|
||||
End If
|
||||
|
||||
rest.ClearAllQueryParams()
|
||||
|
||||
rest.AddHeader("X_API_KEY", jwt)
|
||||
rest.AddHeader("X-API-Key", jwt)
|
||||
|
||||
rest.IdleTimeoutMs = 5000
|
||||
rest.IdleTimeoutMs = 500000
|
||||
|
||||
Dim responseJson As String = rest.FullRequestNoBody("GET", "/v1/transactions/new")
|
||||
If (rest.LastMethodSuccess <> True) Then
|
||||
Debug.WriteLine(rest.LastErrorText)
|
||||
rest.IdleTimeoutMs = 30000 'defualt
|
||||
Return "Fehler"
|
||||
Return "rest.LastErrorText"
|
||||
End If
|
||||
|
||||
If (rest.ResponseStatusCode <> 200) Then
|
||||
Debug.WriteLine(rest.ResponseHeader)
|
||||
Return "Fehler"
|
||||
Return "rest.LastErrorText"
|
||||
End If
|
||||
|
||||
Debug.WriteLine(responseJson)
|
||||
@@ -104,6 +108,83 @@ Public Class cMSEAPI
|
||||
Debug.WriteLine(json)
|
||||
|
||||
|
||||
Dim jsonArray As New Chilkat.JsonArray
|
||||
success = jsonArray.Load(responseJson)
|
||||
If (success <> True) Then
|
||||
Return jsonArray.LastErrorText
|
||||
End If
|
||||
|
||||
|
||||
Dim num As Integer = jsonArray.Size
|
||||
If num = -1 Then
|
||||
Return "FEHLER"
|
||||
End If
|
||||
|
||||
|
||||
Dim j As Integer = 0
|
||||
|
||||
If dt IsNot Nothing And Not dt.Columns.Contains("transaction_id") Then
|
||||
|
||||
dt.Columns.Add("transaction_id", GetType(String))
|
||||
dt.Columns.Add("partner_haulier_id", GetType(Integer))
|
||||
dt.Columns.Add("supplier_name", GetType(String))
|
||||
dt.Columns.Add("transaction_country", GetType(String))
|
||||
dt.Columns.Add("transaction_domain", GetType(String))
|
||||
|
||||
dt.Columns.Add("purchase_datetime", GetType(DateTime))
|
||||
dt.Columns.Add("entry_point_name", GetType(String))
|
||||
dt.Columns.Add("entry_datetime", GetType(DateTime))
|
||||
dt.Columns.Add("exit_point_name", GetType(String))
|
||||
dt.Columns.Add("exit_datetime", GetType(DateTime))
|
||||
|
||||
dt.Columns.Add("device_product_type", GetType(String))
|
||||
dt.Columns.Add("device_product_number", GetType(String))
|
||||
dt.Columns.Add("transaction_product_id", GetType(Integer))
|
||||
dt.Columns.Add("transaction_product_name", GetType(String))
|
||||
dt.Columns.Add("license_plate_number", GetType(String))
|
||||
|
||||
dt.Columns.Add("vehicle_country", GetType(Integer))
|
||||
dt.Columns.Add("original_currency", GetType(String))
|
||||
dt.Columns.Add("original_net_amount", GetType(String))
|
||||
dt.Columns.Add("original_gross_amount", GetType(String))
|
||||
dt.Columns.Add("original_vat_percentage", GetType(Boolean))
|
||||
|
||||
dt.Columns.Add("transaction_net_amount", GetType(Integer))
|
||||
dt.Columns.Add("transaction_gross_amount", GetType(String))
|
||||
dt.Columns.Add("exempt_amount", GetType(String))
|
||||
dt.Columns.Add("msts_fee_amount", GetType(String))
|
||||
dt.Columns.Add("msts_vat_amount", GetType(Boolean))
|
||||
|
||||
dt.Columns.Add("msts_vat_percentage", GetType(Integer))
|
||||
dt.Columns.Add("total_gross_amount", GetType(String))
|
||||
dt.Columns.Add("transaction_status", GetType(String))
|
||||
dt.Columns.Add("original_transaction_id", GetType(String))
|
||||
dt.Columns.Add("credit_comment", GetType(Boolean))
|
||||
dt.Columns.Add("loading_date", GetType(Date))
|
||||
dt.Columns.Add("batch_seq_nr", GetType(Integer))
|
||||
|
||||
|
||||
While j < num
|
||||
|
||||
Dim transaction As Chilkat.JsonObject = jsonArray.ObjectAt(j)
|
||||
|
||||
Dim R As DataRow = dt.NewRow
|
||||
'R("id") = groups.IntOf("id")
|
||||
'R("name") = groups.StringOf("name")
|
||||
'R("groupType") = groups.StringOf("groupType")
|
||||
'R("info") = groups.StringOf("info")
|
||||
|
||||
dt.Rows.Add(R)
|
||||
j = j + 1
|
||||
End While
|
||||
|
||||
|
||||
dt = dt.DefaultView.ToTable()
|
||||
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
Catch ex As WebException
|
||||
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
|
||||
|
||||
Reference in New Issue
Block a user