Fiskaltrust, etc.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
Imports System.Net.Http
|
||||
Imports System.Text
|
||||
Imports Newtonsoft.Json
|
||||
Imports System.Threading
|
||||
Imports DocumentFormat.OpenXml.Drawing
|
||||
Imports DocumentFormat.OpenXml.Wordprocessing
|
||||
Imports Newtonsoft.Json
|
||||
|
||||
Public Class cFiskaltrustClient
|
||||
|
||||
@@ -27,17 +29,89 @@ Public Class cFiskaltrustClient
|
||||
Dim payload = BuildPayload(amount, vat, POS)
|
||||
Dim endpoint = GetEndpoint("payment")
|
||||
|
||||
Return Await SendAsync(endpoint, payload)
|
||||
Dim requestContent As StringContent
|
||||
|
||||
If _country = "AT" Then
|
||||
' Plaintext
|
||||
Dim text As String = If(payload?.ToString(), "")
|
||||
Dim json As String = JsonConvert.SerializeObject(text)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
|
||||
Else
|
||||
' JSON Objekt
|
||||
|
||||
Dim json As String = JsonConvert.SerializeObject(payload)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
End If
|
||||
|
||||
Return Await SendAsync(endpoint, payload, requestContent)
|
||||
|
||||
End Function
|
||||
Public Async Function SignReceiptAsync_test() As Task(Of String)
|
||||
|
||||
Dim LIST = New List(Of EABelegPositionen)
|
||||
Dim p = New EABelegPositionen
|
||||
p.Mandant = "VERA"
|
||||
p.Niederlassung = "SUB"
|
||||
p.Benutzer = 74
|
||||
p.BelegDat = Now
|
||||
p.BelegNr = 1
|
||||
p.PreislistenNr = 1
|
||||
p.PreislistenPos = 1
|
||||
p.LeistungsNr = 300
|
||||
p.LeistungsBez = "TEST"
|
||||
p.Preis = 10
|
||||
p.Anzahl = 1
|
||||
LIST.Add(p)
|
||||
|
||||
Dim payload = BuildPayload(100, 0, LIST)
|
||||
Dim endpoint = GetEndpoint("payment")
|
||||
|
||||
Dim requestContent As StringContent
|
||||
|
||||
If _country = "AT" Then
|
||||
' Plaintext
|
||||
'Dim text As String = If(payload?.ToString(), "")
|
||||
Dim json As String = JsonConvert.SerializeObject(payload)
|
||||
'requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
Else
|
||||
' JSON Objekt
|
||||
|
||||
Dim json As String = JsonConvert.SerializeObject(payload)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
End If
|
||||
|
||||
|
||||
Return Await SendAsync(endpoint, payload, requestContent)
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Public Async Function Echo() As Task(Of String)
|
||||
|
||||
Dim payload = "TEST"
|
||||
Dim payload = "VERBINDUNGSPRÜFUNG ERFOLGREICH"
|
||||
Dim endpoint = GetEndpoint("test")
|
||||
|
||||
Return Await SendAsync(endpoint, payload)
|
||||
Dim requestContent As StringContent
|
||||
|
||||
If _country = "AT" Then
|
||||
' Plaintext
|
||||
Dim text As String = If(payload?.ToString(), "")
|
||||
Dim json As String = JsonConvert.SerializeObject(text)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
|
||||
Else
|
||||
' JSON Objekt
|
||||
Dim obj = New With {
|
||||
.Message = payload
|
||||
}
|
||||
|
||||
Dim json As String = JsonConvert.SerializeObject(obj)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
End If
|
||||
|
||||
|
||||
|
||||
Return Await SendAsync(endpoint, payload, requestContent)
|
||||
|
||||
End Function
|
||||
|
||||
@@ -53,18 +127,30 @@ Public Class cFiskaltrustClient
|
||||
.ftReceiptCase = 4919338172267102210 ' Storno
|
||||
}
|
||||
|
||||
Return Await SendAsync(GetEndpoint("payment"), payload)
|
||||
Dim requestContent As StringContent
|
||||
|
||||
|
||||
If _country = "AT" Then
|
||||
' Plaintext
|
||||
Dim text As String = If(payload?.ToString(), "")
|
||||
Dim json As String = JsonConvert.SerializeObject(text)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "text/plain")
|
||||
Else
|
||||
' JSON Objekt
|
||||
|
||||
Dim json As String = JsonConvert.SerializeObject(payload)
|
||||
requestContent = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
End If
|
||||
|
||||
Return Await SendAsync(GetEndpoint("payment"), payload, requestContent)
|
||||
|
||||
End Function
|
||||
|
||||
' ================================
|
||||
' CORE HTTP LOGIC (RETRY!)
|
||||
' ================================
|
||||
Private Async Function SendAsync(endpoint As String, payload As Object) As Task(Of String)
|
||||
Private Async Function SendAsync(endpoint As String, payload As Object, requestContent As StringContent) As Task(Of String)
|
||||
|
||||
Dim exToThrow As Exception = Nothing
|
||||
|
||||
Dim json As String = JsonConvert.SerializeObject(payload)
|
||||
|
||||
Dim url = _baseUrl & endpoint
|
||||
|
||||
Dim retries As Integer = 3
|
||||
@@ -78,12 +164,7 @@ Public Class cFiskaltrustClient
|
||||
request.Headers.Add("cashboxid", _cashboxId)
|
||||
request.Headers.Add("accesstoken", _accessToken)
|
||||
|
||||
Select Case _country
|
||||
Case "AT"
|
||||
request.Content = New StringContent(json, Encoding.UTF8, "text/xml")
|
||||
Case Else
|
||||
request.Content = New StringContent(json, Encoding.UTF8, "application/json")
|
||||
End Select
|
||||
request.Content = requestContent
|
||||
|
||||
Dim response = Await _httpClient.SendAsync(request)
|
||||
Dim result = Await response.Content.ReadAsStringAsync()
|
||||
@@ -120,7 +201,7 @@ Public Class cFiskaltrustClient
|
||||
|
||||
|
||||
If exToThrow IsNot Nothing Then
|
||||
Await Task.Delay(1000) ' ✅ jetzt OK
|
||||
Await Task.Delay(1000)
|
||||
Throw exToThrow
|
||||
End If
|
||||
|
||||
@@ -129,11 +210,6 @@ Public Class cFiskaltrustClient
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
' ================================
|
||||
' PAYLOAD BUILDER
|
||||
' ================================
|
||||
Private Function BuildPayload(amount As Double, vat As Double, POS As List(Of EABelegPositionen)) As Object
|
||||
|
||||
' ChargeItems Liste vorbereiten
|
||||
@@ -172,9 +248,7 @@ Public Class cFiskaltrustClient
|
||||
|
||||
End Function
|
||||
|
||||
' ================================
|
||||
' ENDPOINT SWITCH
|
||||
' ================================
|
||||
|
||||
Private Function GetEndpoint(type As String) As String
|
||||
|
||||
If type = "payment" Then
|
||||
@@ -208,14 +282,7 @@ Public Class cFiskaltrustClient
|
||||
|
||||
End Function
|
||||
|
||||
' ================================
|
||||
' LOGGING (REPLACE IN PROD!)
|
||||
' ================================
|
||||
Private Sub Log(message As String)
|
||||
' 👉 Hier anschließen:
|
||||
' - Datei
|
||||
' - Datenbank
|
||||
' - Serilog / NLog
|
||||
Console.WriteLine(message)
|
||||
End Sub
|
||||
|
||||
|
||||
Reference in New Issue
Block a user