Creditsafe_API

This commit is contained in:
2023-03-28 16:48:20 +02:00
parent 5d088a3d87
commit ad459e0765
22 changed files with 1479 additions and 494 deletions

View File

@@ -12,6 +12,7 @@ Public Class cAvisoAnhaenge
Property anh_Reihenfolge As Integer = 99
Property anh_LaufzettelDruck As Boolean = False
Property anh_GestellungslisteAnfuegen As Boolean = False
Property anh_markiert As Boolean = False
Public hasEntry As Boolean = False
@@ -37,6 +38,12 @@ Public Class cAvisoAnhaenge
Me.anh_Typ = anh_Typ
Me.anh_Reihenfolge = anh_Reihenfolge
If anh_Art.ToString.Equals("Auftrag") Then
anh_markiert = True
End If
End Sub
@@ -52,6 +59,7 @@ Public Class cAvisoAnhaenge
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("anh_Reihenfolge", anh_Reihenfolge))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("anh_LaufzettelDruck", anh_LaufzettelDruck))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("anh_GestellungslisteAnfuegen", anh_GestellungslisteAnfuegen))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("anh_markiert", anh_markiert))
Return list
End Function

View File

@@ -52,6 +52,8 @@ Public Class cKundenErweitert
Property kde_CreditSaveBonitaetsklasse As Object = Nothing
Property kde_CreditSaveBonitaetsIndex As Object = Nothing
Property kde_CreditSaveBonitaetsScore As Object = Nothing
Property kde_CreditSaveId As String = ""
Property kde_Inkasso_Uebergeben As Boolean = False
Property kde_Inkasso_UebergebenAm As Object = Nothing
Property kde_Inkasso_GemeldeterBetrag As Object = Nothing
@@ -140,6 +142,7 @@ Public Class cKundenErweitert
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("kde_CreditSaveBonitaetsklasse", kde_CreditSaveBonitaetsklasse))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("kde_CreditSaveBonitaetsIndex", kde_CreditSaveBonitaetsIndex))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("kde_CreditSaveBonitaetsScore", kde_CreditSaveBonitaetsScore))
list.Add(New VERAG_PROG_ALLGEMEIN.SQLVariable("kde_CreditSaveId", kde_CreditSaveId))
Return list
End Function

View File

@@ -0,0 +1,271 @@
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Web.UI.WebControls
Imports System.Windows.Forms
Imports Microsoft.Office.Interop.Outlook
Imports Newtonsoft.Json
Imports Spire.Pdf.Lists
Imports VERAG_PROG_ALLGEMEIN.IDEV_Intrastat
Imports VERAG_PROG_ALLGEMEIN.TESTJSON
Public Class cCreditSafeAPI
'Test
Shared API_STRING As String = "https://connect.sandbox.creditsafe.com"
'PROD
'Shared API_STRING As String = "https://connect.creditsafe.com"
Shared token As String = ""
Public dataTable As New DataTable()
Shared Function SendRequestAuthentificationToken(myuri As String, user As CreditSafeUser, contentType As String, method As String) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim success As Boolean
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)
Return rest.LastErrorText
End If
Dim json As New Chilkat.JsonObject
json.UpdateString("username", user.username)
json.UpdateString("password", user.password)
rest.AddHeader("Content-Type", contentType)
Dim sbRequestBody As New Chilkat.StringBuilder
json.EmitSb(sbRequestBody)
Dim sbResponseBody As New Chilkat.StringBuilder
Dim ResponseStr = rest.FullRequestSb(method, myuri, sbRequestBody, sbResponseBody)
If (rest.ResponseStatusCode <> 200) Then
Return rest.ResponseStatusCode
End If
Dim jsonResp = New Chilkat.JsonObject()
jsonResp.LoadSb(sbResponseBody)
token = jsonResp.StringOf("token")
Return rest.ResponseStatusCode
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
Shared Function SendGetRequestWithAuthHeader(url As String, company As Company, method As String, authenticationToken As String) As String
Try
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim rest As New Chilkat.Rest
Dim success As Boolean
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)
End If
rest.ClearAllQueryParams()
If company IsNot Nothing Then
If company.vatNo <> "" Then
rest.AddQueryParam("vatNo", company.vatNo)
Else
If company.name <> "" Then
rest.AddQueryParam("name", company.name)
End If
End If
If company.country <> "" Then
rest.AddQueryParam("countries", company.country)
End If
End If
rest.AddHeader("Content-Type", "application/json")
rest.AddHeader("Authorization", "Bearer " & authenticationToken)
If company IsNot Nothing Then
rest.AddHeader("Accept", "application/vnd.hmrc.1.0+json")
Else
rest.AddHeader("Accept", "application/json+pdf")
End If
Dim responseJson As String = rest.FullRequestNoBody(method, url)
If (rest.LastMethodSuccess <> True) Then
Debug.WriteLine(rest.LastErrorText)
MsgBox(rest.LastErrorText)
End If
Return responseJson
Catch ex As WebException
VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name)
End Try
End Function
Shared Function authenticate(username As String, passwort As String) As String
Dim myUri As String = API_STRING & "/v1/authenticate"
Dim csUser = New CreditSafeUser(username, passwort)
Dim response = SendRequestAuthentificationToken(myUri, csUser, "application/json", "POST")
Return response
End Function
Shared Function searchCompanies(conpanyname As String, vatNo As String, country As String, ByRef dataTable As DataTable) As String
VERAG_PROG_ALLGEMEIN.cChilkat_Helper.UnlockCilkat()
Dim myUrl As String = API_STRING & "/v1/companies"
Dim company = New Company(conpanyname, vatNo, country)
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "GET", token)
'Dim test As String = "{""correlationId"":""9194edd0-1a4a-4520-a332-7306b7c027ca"",""totalSize"":1,""companies"":[{""id"":""AT-X-7256130"",""country"":""AT"",""regNo"":""FN 410356 s"",""vatNo"":[""ATU 68490714""],""safeNo"":""AT05607514"",""name"":""Imex Customs Service GmbH"",""address"":{""simpleValue"":""Autobahngrenze 15, 4975, Suben"",""street"":""Autobahngrenze 15"",""city"":""Suben"",""postCode"":""4975""},""status"":""active"",""officeType"":""headOffice"",""type"":""Ltd"",""dateOfLatestAccounts"":""2021-12-31T00:00:00.000000Z"",""dateOfLatestChange"":""2023-03-03T02:38:30.000Z""}]}"
'jsonRespString = test
Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(jsonRespString)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
Return "Verbindungsfehler"
End If
Dim num As Integer = json.SizeOfArray("companies")
If num = 0 Then
Return json.StringOf("messages[0].text")
End If
Dim companies As Chilkat.JsonArray = json.ArrayOf("companies")
If (json.LastMethodSuccess = False) Then
Return "companies member not found."
End If
Dim numCompanies As Integer = companies.Size
Dim j As Integer = 0
While j < numCompanies
Dim compObj As Chilkat.JsonObject = companies.ObjectAt(j)
Dim index = companies.FindString("address", False)
Dim adressObj As Chilkat.JsonObject = compObj.ObjectOf("address")
'Debug.WriteLine(adressObj.StringOf("simpleValue"))
Debug.WriteLine(compObj.StringOf("id") & " " & compObj.StringOf("phoneNo") & " " & compObj.StringOf("phoneNumbers[0]"))
Dim R As DataRow = dataTable.NewRow
R("id") = compObj.StringOf("id")
R("name") = compObj.StringOf("name")
R("country") = compObj.StringOf("country")
R("safeNo") = compObj.StringOf("safeNo")
R("vatNo") = compObj.StringOf("vatNo[0]")
R("regNo") = compObj.StringOf("regNo")
R("street") = adressObj.StringOf("street")
R("city") = adressObj.StringOf("city")
R("postCode") = adressObj.StringOf("postCode")
R("status") = compObj.StringOf("status")
R("dateOfLatestChange") = compObj.StringOf("dateOfLatestChange")
R("phoneNo") = compObj.StringOf("phoneNumbers[0]")
dataTable.Rows.Add(R)
j = j + 1
End While
Return "Anzahl gefundener Datensätze: " & numCompanies
End Function
Shared Function companyCreditreport(id As String) As String
Dim myUrl As String = API_STRING & "/v1/companies/" & id
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, "GET", token)
Dim json As New Chilkat.JsonObject
Dim success As Boolean = json.Load(jsonRespString)
If (success <> True) Then
Debug.WriteLine(json.LastErrorText)
Return "Verbindungsfehler"
End If
Dim num As Integer = json.SizeOfArray("companies")
If num = -1 Then
Return json.StringOf("details")
End If
Return "test"
End Function
Public Class CreditSafeUser
Public Property username As String
Public Property password As String
Public Property token As String
Public Sub New(_username As String, _password As String)
username = _username
password = _password
End Sub
Public Sub New(_username As String, _password As String, _token As String)
username = _username
password = _password
End Sub
End Class
Public Class Company
Public Property name As String
Public Property vatNo As String
Public Property country As String
Public Sub New(_name As String, _vatNo As String, _country As String)
name = _name
vatNo = _vatNo
country = _country
End Sub
End Class
End Class

View File

@@ -572,6 +572,7 @@
<Compile Include="RKSV_DE\cServerClient_RKSV_DE.vb" />
<Compile Include="Schnittstellen\ATEZ\cATEZ_NCTS.vb" />
<Compile Include="Schnittstellen\cBMD_Interface.vb" />
<Compile Include="Schnittstellen\cCreditSafeAPI.vb" />
<Compile Include="Schnittstellen\cDatev_Interface.vb" />
<Compile Include="Schnittstellen\cDeeplAPI.vb" />
<Compile Include="Schnittstellen\cDVO_Interface.vb" />
@@ -1199,7 +1200,7 @@
<Version>3.8.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.2</Version>
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>