From 41e8dfae41147923e8a2d40650fe94e9bf94affc Mon Sep 17 00:00:00 2001 From: dankl Date: Thu, 3 Oct 2019 23:39:53 +0200 Subject: [PATCH] Started rudimentary version of FinTsClient --- .../kotlin/net/dankito/fints/FinTsClient.kt | 42 +++++++++++++++++++ .../dankito/fints/model/AccountCredentials.kt | 9 ++++ .../net/dankito/fints/model/BankInfo.kt | 8 ++++ .../net/dankito/fints/model/ProductInfo.kt | 7 ++++ 4 files changed, 66 insertions(+) create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountCredentials.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/model/BankInfo.kt create mode 100644 fints4javaLib/src/main/kotlin/net/dankito/fints/model/ProductInfo.kt diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt new file mode 100644 index 00000000..97c48e62 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/FinTsClient.kt @@ -0,0 +1,42 @@ +package net.dankito.fints + +import net.dankito.fints.messages.nachrichten.implementierte.DialoginitialisierungAnonym +import net.dankito.fints.model.BankInfo +import net.dankito.fints.model.ProductInfo +import net.dankito.fints.util.IBase64Service +import net.dankito.utils.web.client.IWebClient +import net.dankito.utils.web.client.OkHttpWebClient +import net.dankito.utils.web.client.RequestParameters + + +open class FinTsClient( + protected val base64Service: IBase64Service, + protected val webClient: IWebClient = OkHttpWebClient() +) { + + + fun getBankInfo(bankInfo: BankInfo, productInfo: ProductInfo) { + val dialogInit = DialoginitialisierungAnonym(bankInfo.countryCode, bankInfo.bankCode, + productInfo.productName, productInfo.productVersion) + + val requestBody = dialogInit.format() + val encodedRequestBody = base64Service.encode(requestBody) + + val response = webClient.post(RequestParameters(bankInfo.finTsServerAddress, encodedRequestBody, "application/octet-stream")) + + val responseBody = response.body + if (response.isSuccessful && responseBody != null) { + + val decodedResponse = decodeBase64Response(responseBody) + + if (decodedResponse != null) { + + } + } + } + + protected open fun decodeBase64Response(responseBody: String): String { + return base64Service.decode(responseBody.replace("\r", "").replace("\n", "")) + } + +} \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountCredentials.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountCredentials.kt new file mode 100644 index 00000000..e2a789d2 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/AccountCredentials.kt @@ -0,0 +1,9 @@ +package net.dankito.fints.model + + +open class AccountCredentials @JvmOverloads constructor( + val bankCode: String, + val customerId: String, + val pin: String, + val userId: String = customerId +) \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/BankInfo.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/BankInfo.kt new file mode 100644 index 00000000..68d8349c --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/BankInfo.kt @@ -0,0 +1,8 @@ +package net.dankito.fints.model + + +open class BankInfo( + val bankCode: String, + val countryCode: Int, + val finTsServerAddress: String +) \ No newline at end of file diff --git a/fints4javaLib/src/main/kotlin/net/dankito/fints/model/ProductInfo.kt b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/ProductInfo.kt new file mode 100644 index 00000000..bac47565 --- /dev/null +++ b/fints4javaLib/src/main/kotlin/net/dankito/fints/model/ProductInfo.kt @@ -0,0 +1,7 @@ +package net.dankito.fints.model + + +open class ProductInfo( + val productName: String, + val productVersion: String +) \ No newline at end of file