From 527fd1c115365577cfd0628dae4cc5a0e38f7ffb Mon Sep 17 00:00:00 2001 From: "d.breimaier" Date: Fri, 28 Apr 2023 12:32:27 +0200 Subject: [PATCH] =?UTF-8?q?credtisafe=20->=20korrekter=20bericht=20wird=20?= =?UTF-8?q?nun=20als=20pdf=20angef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SDL/kunden/usrCntlKundenuebersicht.vb | 9 +- .../Schnittstellen/cCreditSafeAPI.vb | 89 +++++++++++++++---- 2 files changed, 78 insertions(+), 20 deletions(-) diff --git a/SDL/kunden/usrCntlKundenuebersicht.vb b/SDL/kunden/usrCntlKundenuebersicht.vb index 9091dff8..c8a2dab3 100644 --- a/SDL/kunden/usrCntlKundenuebersicht.vb +++ b/SDL/kunden/usrCntlKundenuebersicht.vb @@ -2795,18 +2795,21 @@ Public Class usrCntlKundenuebersicht If cs.checkDateOfLastRequest(company) < lastChecked Then Dim a As MsgBoxResult = MsgBox("Seit der letzen Abfrage (" & lastChecked.ToShortDateString & ") wurde bei Creditsafe keine Änderung gemacht!" & vbNewLine & "Trotzdem Creditreport-Daten aktualisieren?", vbYesNo) If a = vbYes Then - cs.getReport(company, True, pdfObject) + cs.getReport(company, True) + pdfObject = cs.getPDF(company) setCreditSafeEntry(company, pdfObject, kdNr) End If Else - cs.getReport(company, True, pdfObject) + cs.getReport(company, True) + pdfObject = cs.getPDF(company) setCreditSafeEntry(company, pdfObject, kdNr) End If Else - cs.getReport(company, True, pdfObject) + cs.getReport(company, True) + pdfObject = cs.getPDF(company) setCreditSafeEntry(company, pdfObject, kdNr) End If diff --git a/VERAG_PROG_ALLGEMEIN/Schnittstellen/cCreditSafeAPI.vb b/VERAG_PROG_ALLGEMEIN/Schnittstellen/cCreditSafeAPI.vb index 43d0a5f6..84dfa131 100644 --- a/VERAG_PROG_ALLGEMEIN/Schnittstellen/cCreditSafeAPI.vb +++ b/VERAG_PROG_ALLGEMEIN/Schnittstellen/cCreditSafeAPI.vb @@ -107,15 +107,32 @@ Public Class cCreditSafeAPI rest.AddHeader("Accept", acceptContentType) + Dim responseJson As String + Dim pdfData As New Chilkat.BinData - Dim responseJson As String = rest.FullRequestNoBody(method, url) - If (rest.LastMethodSuccess <> True) Then - Debug.WriteLine(rest.LastErrorText) - MsgBox(rest.LastErrorText) + If acceptContentType.Contains("application/pdf") Then + + responseJson = rest.FullRequestNoBodyBd(method, url, pdfData) + If (rest.LastMethodSuccess <> True) Then + Debug.WriteLine(rest.LastErrorText) + MsgBox(rest.LastErrorText) + Else + Return pdfData.ToString + End If + + Else + + responseJson = rest.FullRequestNoBody(method, url) + If (rest.LastMethodSuccess <> True) Then + Debug.WriteLine(rest.LastErrorText) + MsgBox(rest.LastErrorText) + + Else + Return responseJson + End If End If - Return responseJson Catch ex As WebException VERAG_PROG_ALLGEMEIN.cErrorHandler.ERR(ex.Message, ex.StackTrace, System.Reflection.MethodInfo.GetCurrentMethod.Name) @@ -205,7 +222,7 @@ Public Class cCreditSafeAPI End Function - Shared Function getReport(ByRef company As Company, withPDF As Boolean, ByRef bytes As Byte()) As String + Shared Function getReport(ByRef 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 & "/" If company.country = "DE" Then 'Abfragen für DE benötigen einen Reason-Code @@ -217,9 +234,9 @@ Public Class cCreditSafeAPI End If Dim acceptContentType = "application/json" - If withPDF Then - acceptContentType &= "+pdf" - End If + 'If withPDF Then + ' acceptContentType &= "+pdf" + 'End If @@ -314,23 +331,61 @@ Public Class cCreditSafeAPI company.csFailure = json.StringOf("details") End If - If withPDF Then - Dim sb As New Chilkat.StringBuilder - json.StringOfSb("pdfReportStream", sb) + 'If withPDF Then + ' Dim sb As New Chilkat.StringBuilder + ' json.StringOfSb("pdfReportStream", sb) - Dim bd As New Chilkat.BinData - bd.AppendEncodedSb(sb, "base64") + ' Dim bd As New Chilkat.BinData + ' bd.AppendEncodedSb(sb, "base64") - bytes = Convert.FromBase64String(sb.ToString) + ' bytes = Convert.FromBase64String(sb.ToString) - Return "mitPDF" + ' Return "mitPDF" - End If + 'End If Return "ohnePDF" End Function + Shared Function getPDF(ByRef company As Company) As Byte() + + Dim myUrl As String = API_STRING & "/v1/companies/" & company.creditSafeId & "/" + If company.country = "DE" Then + 'Abfragen für DE benötigen einen Reason-Code + myUrl &= "?customData=de_reason_code::2" + myUrl &= "&?language=DE" + Else + + myUrl &= "?language=DE" + End If + + Dim acceptContentType = "application/pdf" + + Dim jsonRespString = SendGetRequestWithAuthHeader(myUrl, Nothing, acceptContentType, "GET", token) + + 'Dim json As New Chilkat.JsonObject + 'Dim success As Boolean = json.Load(jsonRespString) + 'If (success <> True) Then + ' Debug.WriteLine(json.LastErrorText) + + 'End If + + 'Dim sb As New Chilkat.StringBuilder + 'json.StringOfSb("pdfReportStream", sb) + + 'Dim bd As New Chilkat.BinData + 'bd.AppendEncodedSb(sb, "base64") + + 'Return Convert.FromBase64String(sb.ToString) + If jsonRespString IsNot Nothing Then + Return Convert.FromBase64String(jsonRespString) + End If + + + End Function + + Shared Sub setSearchParam(ByRef rest As Chilkat.Rest, ByRef company As Company)