Added JavaShowcase; did some adjustments so that Java users have a nicer interface
This commit is contained in:
parent
bb9c5d9c98
commit
29a2f29f72
|
@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
|
|
||||||
open class FinTsClient(
|
open class FinTsClient @JvmOverloads constructor(
|
||||||
protected val base64Service: IBase64Service,
|
protected val base64Service: IBase64Service,
|
||||||
protected val webClient: IWebClient = OkHttpWebClient(),
|
protected val webClient: IWebClient = OkHttpWebClient(),
|
||||||
protected val messageBuilder: MessageBuilder = MessageBuilder(),
|
protected val messageBuilder: MessageBuilder = MessageBuilder(),
|
||||||
|
|
|
@ -26,6 +26,11 @@ open class CustomerData(
|
||||||
val Anonymous = CustomerData(KundenID.Anonymous, "", customerSystemStatus = KundensystemStatusWerte.NichtBenoetigt)
|
val Anonymous = CustomerData(KundenID.Anonymous, "", customerSystemStatus = KundensystemStatusWerte.NichtBenoetigt)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// for Java
|
||||||
|
constructor(customerId: String, pin: String) : this(customerId, pin, customerId)
|
||||||
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return customerId
|
return customerId
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package net.dankito.fints.model
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
|
||||||
open class GetTransactionsParameter(
|
open class GetTransactionsParameter @JvmOverloads constructor(
|
||||||
val alsoRetrieveBalance: Boolean = true,
|
val alsoRetrieveBalance: Boolean = true,
|
||||||
val fromDate: Date? = null,
|
val fromDate: Date? = null,
|
||||||
val toDate: Date? = null,
|
val toDate: Date? = null,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import net.dankito.fints.response.segments.TanResponse
|
||||||
|
|
||||||
open class FinTsClientResponse(
|
open class FinTsClientResponse(
|
||||||
|
|
||||||
val successful: Boolean,
|
val isSuccessful: Boolean,
|
||||||
|
|
||||||
val isStrongAuthenticationRequired: Boolean,
|
val isStrongAuthenticationRequired: Boolean,
|
||||||
val tanRequired: TanResponse? = null,
|
val tanRequired: TanResponse? = null,
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package net.dankito.fints.java;
|
||||||
|
|
||||||
|
import net.dankito.fints.FinTsClient;
|
||||||
|
import net.dankito.fints.banks.BankFinder;
|
||||||
|
import net.dankito.fints.messages.datenelemente.implementierte.signatur.Sicherheitsfunktion;
|
||||||
|
import net.dankito.fints.model.*;
|
||||||
|
import net.dankito.fints.model.mapper.BankDataMapper;
|
||||||
|
import net.dankito.fints.response.client.GetTransactionsResponse;
|
||||||
|
import net.dankito.fints.util.Java8Base64Service;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class JavaShowcase {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
BankFinder bankFinder = new BankFinder();
|
||||||
|
|
||||||
|
// set your bank code (Bankleitzahl) here. Or create BankData manually. Required fields are:
|
||||||
|
// bankCode, bankCountryCode (Germany = 280), finTs3ServerAddress and for bank transfers bic
|
||||||
|
List<BankInfo> foundBanks = bankFinder.findBankByBankCode("10070000");
|
||||||
|
|
||||||
|
if (foundBanks.isEmpty() == false) {
|
||||||
|
BankData bank = new BankDataMapper().mapFromBankInfo(foundBanks.get(0));
|
||||||
|
// set your customer data (customerId = Kontonummer in most cases, pin = online banking pin)
|
||||||
|
CustomerData customer = new CustomerData("<customer_id>", "<pin>");
|
||||||
|
customer.setSelectedTanProcedure(new TanProcedure("", Sicherheitsfunktion.PIN_TAN_911, TanProcedureType.ChipTan));
|
||||||
|
|
||||||
|
FinTsClient finTsClient = new FinTsClient(new Java8Base64Service());
|
||||||
|
|
||||||
|
// some banks support retrieving account transactions of last 90 days without TAN
|
||||||
|
long ninetyDaysAgoMilliseconds = 90 * 24 * 60 * 60 * 1000L;
|
||||||
|
Date ninetyDaysAgo = new Date(new Date().getTime() - ninetyDaysAgoMilliseconds);
|
||||||
|
|
||||||
|
GetTransactionsResponse response = finTsClient.getTransactions(
|
||||||
|
new GetTransactionsParameter(true, ninetyDaysAgo), bank, customer);
|
||||||
|
|
||||||
|
showResponse(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void showResponse(GetTransactionsResponse response) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
System.out.println("Balance (Saldo) = " + response.getBalance());
|
||||||
|
|
||||||
|
System.out.println("Account transactions (Umsätze):");
|
||||||
|
for (AccountTransaction transaction : response.getBookedTransactions()) {
|
||||||
|
System.out.println(transaction.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (response.isStrongAuthenticationRequired()) {
|
||||||
|
System.out.println("Sorry, your bank doesn't support retrieving account " +
|
||||||
|
"transactions of last 90 days without TAN");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.println("An error occurred:");
|
||||||
|
if (response.getException() != null) { // something severe occurred
|
||||||
|
System.out.println(response.getException().getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// error messages retrieved from bank (e.g. PIN is wrong, message contains errors, ...)
|
||||||
|
for (String retrievedErrorMessage : response.getErrorsToShowToUser()) {
|
||||||
|
System.out.println(retrievedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -45,7 +45,7 @@ class FinTsClientTest {
|
||||||
val result = underTest.getAnonymousBankInfo(BankDataAnonymous)
|
val result = underTest.getAnonymousBankInfo(BankDataAnonymous)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result.successful).isTrue()
|
assertThat(result.isSuccessful).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class FinTsClientTest {
|
||||||
val result = underTest.synchronizeCustomerSystemId(Customer, Bank)
|
val result = underTest.synchronizeCustomerSystemId(Customer, Bank)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result.successful).isTrue()
|
assertThat(result.isSuccessful).isTrue()
|
||||||
assertThat(Customer.customerSystemId).isNotEqualTo(KundensystemStatus.SynchronizingCustomerSystemId) // customer system id is now set
|
assertThat(Customer.customerSystemId).isNotEqualTo(KundensystemStatus.SynchronizingCustomerSystemId) // customer system id is now set
|
||||||
assertThat(Customer.selectedLanguage).isNotEqualTo(Dialogsprache.Default) // language is set now
|
assertThat(Customer.selectedLanguage).isNotEqualTo(Dialogsprache.Default) // language is set now
|
||||||
assertThat(Customer.customerSystemStatus).isEqualTo(KundensystemStatusWerte.Benoetigt) // customerSystemStatus is set now
|
assertThat(Customer.customerSystemStatus).isEqualTo(KundensystemStatusWerte.Benoetigt) // customerSystemStatus is set now
|
||||||
|
@ -75,7 +75,7 @@ class FinTsClientTest {
|
||||||
val result = underTest.getTransactions(GetTransactionsParameter(fromDate = ninetyDaysAgo), Bank, Customer)
|
val result = underTest.getTransactions(GetTransactionsParameter(fromDate = ninetyDaysAgo), Bank, Customer)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result.successful).isTrue()
|
assertThat(result.isSuccessful).isTrue()
|
||||||
assertThat(result.bookedTransactions).isNotEmpty()
|
assertThat(result.bookedTransactions).isNotEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class FinTsClientTest {
|
||||||
val result = underTest.doBankTransfer(BankTransferData, Bank, Customer)
|
val result = underTest.doBankTransfer(BankTransferData, Bank, Customer)
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result.successful).isTrue()
|
assertThat(result.isSuccessful).isTrue()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue