Files
SDL/VERAG_PROG_ALLGEMEIN/Schnittstellen/WISE/cWiseBankApi.vb
2025-12-09 14:58:21 +01:00

144 lines
5.1 KiB
VB.net

Imports System.Net
Imports System.IO
Imports System.Text
Imports Newtonsoft.Json
Public Class cWiseBankApi
' {
' "id": 21853903,
' "publicId": "f0a7f4dd-dab2-4486-8c19-7828d305362b",
' "userId": 29518224,
' "type": "BUSINESS",
' "address": {
' "id": 43822076,
' "addressFirstLine": "Office Suite 3:1 1 Cannon Street",
' "city": "Dover",
' "countryIso2Code": "GB",
' "countryIso3Code": "gbr",
' "postCode": "CT16 1BY",
' "stateCode": null
' },
' "email": "al@verag-unisped.uk",
' "createdAt": "2021-07-12T15:29:50",
' "updatedAt": "2021-07-12T15:29:50",
' "version": 4,
' "obfuscated": false,
' "avatar": "https://tw-avatar.s3.eu-central-1.amazonaws.com/d51ac74d-c619-45da-8fc1-283ac43431a5",
' "currentState": "VISIBLE",
' "contactDetails": {
' "email": "al@verag-unisped.uk",
' "phoneNumber": "+436644178557"
' },
' "businessName": "Verag-unisped Ltd",
' "registrationNumber": "13107151",
' "descriptionOfBusiness": "TRANSPORT",
' "companyType": "LIMITED",
' "firstLevelCategory": "TRAVEL_TRANSPORT_TOUR_AGENCIES",
' "secondLevelCategory": "TRANSPORT",
' "operationalAddresses": [
' {
' "id": 43822077,
' "addressFirstLine": "Office Suite 3:1 1 Cannon Street",
' "city": "Dover",
' "countryIso2Code": "GB",
' "countryIso3Code": "gbr",
' "postCode": "CT16 1BY",
' "stateCode": null
' }
' ],
' "dataObfuscated": false,
' "fullName": "Verag-unisped Ltd",
' "partner": false,
' "contractingWithWise": true,
' "partnerCustomer": false
' },
' {
' "id": 21853958,
' "publicId": "3e16db56-1ed0-48d6-9a6d-5dacfe9035be",
' "userId": 29518224,
' "type": "PERSONAL",
' "address": {
' "id": 43822145,
' "addressFirstLine": "Hackenbuch 27",
' "city": "Sankt Marienkirchen bei Schaerding",
' "countryIso2Code": "AT",
' "countryIso3Code": "aut",
' "postCode": "4774",
' "stateCode": null
' },
' "email": "al@verag-unisped.uk",
' "createdAt": "2021-07-12T15:32:28",
' "updatedAt": "2021-07-12T15:34:33",
' "version": 1,
' "obfuscated": false,
' "currentState": "HIDDEN",
' "contactDetails": {
' "email": "al@verag-unisped.uk",
' "phoneNumber": "+436644178557"
' },
' "firstName": "Andreas",
' "lastName": "LUXBAUER",
' "dateOfBirth": "1990-07-22",
' "phoneNumber": "+436644178557",
' "secondaryAddresses": [],
' "partner": false,
' "dataObfuscated": false,
' "fullName": "Andreas LUXBAUER",
' "contractingWithWise": true,
' "partnerCustomer": false
' }
']
Private ReadOnly apiToken As String '245a89e8-b8e3-4ceb-8326-ad7cd4d19eda
Private ReadOnly profileId As String '
Private ReadOnly balanceId As String
'AVISO
Public Sub New(token As String, profile As String, balance As String)
apiToken = token
profileId = profile
balanceId = balance
End Sub
''' <summary>
''' Ruft die Kontoumsätze der letzten 7 Tage ab.
''' </summary>
Public Function example() As String
Dim client As New cWiseBankApi(
"DEIN_API_TOKEN",
"DEINE_PROFILE_ID",
"DEINE_BALANCE_ID"
)
Dim json As String = client.GetLast7DaysStatement()
Console.WriteLine(json)
End Function
Public Function GetLast7DaysStatement() As String
Dim fromDate As String = DateTime.UtcNow.AddDays(-7).ToString("yyyy-MM-dd")
Dim toDate As String = DateTime.UtcNow.ToString("yyyy-MM-dd")
Dim url As String =
$"https://api.wise.com/v4/profiles/{profileId}/balance-statements/{balanceId}/statement.json?intervalStart={fromDate}&intervalEnd={toDate}"
Dim request As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
request.Method = "GET"
request.Headers.Add("Authorization", "Bearer " & apiToken)
Try
Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using reader As New StreamReader(response.GetResponseStream())
Return reader.ReadToEnd()
End Using
End Using
Catch ex As WebException
Using sr As New StreamReader(ex.Response.GetResponseStream())
Dim errorText = sr.ReadToEnd()
Throw New Exception("Wise API Fehler: " & errorText)
End Using
End Try
End Function
End Class