Creditsafe-API

This commit is contained in:
2023-04-19 17:42:49 +02:00
parent da44967f54
commit ea00c17833
7 changed files with 354 additions and 130 deletions

View File

@@ -3,6 +3,7 @@ Imports System.Net
Imports System.Text
Imports System.Web.UI.WebControls
Imports System.Windows.Forms
Imports Chilkat
Imports Microsoft.Office.Interop.Outlook
Imports Newtonsoft.Json
Imports Spire.Pdf.Lists
@@ -12,10 +13,10 @@ Imports VERAG_PROG_ALLGEMEIN.TESTJSON
Public Class cCreditSafeAPI
'Test
Shared API_STRING As String = "https://connect.sandbox.creditsafe.com"
'Shared API_STRING As String = "https://connect.sandbox.creditsafe.com"
'PROD
'Shared API_STRING As String = "https://connect.creditsafe.com"
Shared API_STRING As String = "https://connect.creditsafe.com"
Shared token As String = ""
Public dataTable As New DataTable()
@@ -144,9 +145,6 @@ Public Class cCreditSafeAPI
Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, company, "application/json", "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
@@ -207,8 +205,10 @@ Public Class cCreditSafeAPI
End Function
Shared Function getReport(company As Company, withPDF As Boolean) As String
Shared Function getReport(ByRef company As Company, withPDF As Boolean, ByRef bytes As Byte()) As String
Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId
myUrl &= "/?language=DE"
myUrl &= "&?template=full"
Dim acceptContentType = "application/json"
If withPDF Then
acceptContentType &= "+pdf"
@@ -222,13 +222,103 @@ Public Class cCreditSafeAPI
Return "Verbindungsfehler"
End If
Dim num As Integer = json.SizeOfArray("companies")
If num = -1 Then
Return json.StringOf("details")
'Aubbau JSON Object
' "report" {
' "companyIdentification" : {
' "basicInformation" : {
' "companyRegistrationDate" : "01.01.2022",
' "creditScore" : {
' "currentCreditRating" : {
' "commonValue" : "A",
' "providerValue" : {
' "value" : "350",
'....}
' "pdfReportStream": "base64"
'},
Dim reportObj As Chilkat.JsonObject = json.ObjectOf("report")
If (json.LastMethodSuccess = True) Then
Dim companyIDObj As Chilkat.JsonObject = reportObj.ObjectOf("companyIdentification")
If (json.LastMethodSuccess = True) Then
Dim basicInfoObj As Chilkat.JsonObject = companyIDObj.ObjectOf("basicInformation")
If (json.LastMethodSuccess = True) Then
Dim dateTime As New Chilkat.CkDateTime
Dim getAsLocal As Boolean = False
basicInfoObj.DateOf("companyRegistrationDate", DateTime)
company.csDFoundingDate = dateTime.GetAsTimestamp(getAsLocal)
Debug.WriteLine(dateTime)
Else
Debug.WriteLine("basicInfoObj object not found.")
End If
Else
Debug.WriteLine("companyIDObj object not found.")
End If
Dim creditScoreObj As Chilkat.JsonObject = reportObj.ObjectOf("creditScore")
If (json.LastMethodSuccess = True) Then
Dim creditRatingObj As Chilkat.JsonObject = creditScoreObj.ObjectOf("currentCreditRating")
If (json.LastMethodSuccess = True) Then
company.csRiskclass = creditRatingObj.StringOf("commonValue")
Dim creditLimitObj As Chilkat.JsonObject = creditRatingObj.ObjectOf("creditLimit")
If (json.LastMethodSuccess = True) Then
company.csMaxCreditAmount = creditLimitObj.StringOf("value")
Else
Debug.WriteLine("creditRating object not found.")
End If
Dim providerValueObj As Chilkat.JsonObject = creditRatingObj.ObjectOf("providerValue")
If (json.LastMethodSuccess = True) Then
company.csIndex = providerValueObj.StringOf("value")
Else
Debug.WriteLine("providerValue object not found.")
End If
Else
Debug.WriteLine("currentCreditRating object not found.")
End If
Else
Debug.WriteLine("creditScore object not found.")
Return "creditScore object not found"
End If
Else
Debug.WriteLine("report object not found.")
Return "report object not found"
End If
Return "test"
If withPDF Then
Dim sb As New Chilkat.StringBuilder
json.StringOfSb("pdfReportStream", sb)
Dim bd As New Chilkat.BinData
bd.AppendEncodedSb(sb, "base64")
bytes = Convert.FromBase64String(sb.ToString)
Return "mitPDF"
End If
Return "ohnePDF"
End Function
@@ -307,6 +397,11 @@ Public Class cCreditSafeAPI
Public Property country As String
Public Property creditsafeNo As String
Public Property lastChecked As Date
Public Property csIndex As String
Public Property csRiskclass As String
Public Property csMaxCreditAmount As Double
Public Property csDFoundingDate As Date
Public Property csPDF As String
Public Sub New(_name As String, _vatNo As String, _country As String, _creditsafeNo As String, _creditSafeId As String, _lastChecked As Date)