Expand description
§fints-client: a FinTS 3.0 PIN/TAN client
FinTS (formerly HBCI) is the online-banking protocol of German banks. This crate reads balances, transactions and securities holdings, and sends SEPA and instant transfers with the payee name check (Verification of Payee).
Banks answer only clients registered with the Deutsche Kreditwirtschaft:
register your app at https://www.fints.org/de/hersteller/produktregistrierung
and pass its product ID to jobs::BankClient::new. The crate ships
with no product ID.
§Quick start
Every operation is async. The default http transport is reqwest and
needs a tokio runtime.
use fints_client::jobs::{self, BankClient, Credentials, Step, TanKind};
use fints_client::{bank_by_blz, jiff::Timestamp, Pin, ProductId, SessionState, UserId};
let config = bank_by_blz("12030000").expect("BLZ in the bank directory"); // DKB
let client = BankClient::new(config, ProductId::new("YOUR-PRODUCT-ID"));
let user = UserId::new("user");
let creds = Credentials::new(user.clone(), Pin::new("pin"));
let state = SessionState::new(&client.config().blz, &user); // or SessionState::from_json(stored)
// Open the dialog. A bank that wants a TAN answers `NeedTan`.
let (mut dialog, mut step) = jobs::open(&client, &creds, &state).await?;
let opened = loop {
match step {
Step::Done(done) => break done.value,
Step::NeedTan(challenge, resume) => {
println!("{}", challenge.challenge);
step = match challenge.kind {
// App approval: wait as long as the bank asks, then ask once.
TanKind::Decoupled { .. } => {
if let Some(at) = challenge.not_before {
let wait = at.duration_since(Timestamp::now());
tokio::time::sleep(wait.try_into().unwrap_or_default()).await;
}
dialog.poll(resume).await?
}
// chipTAN, smsTAN, photoTAN: the user types the TAN.
TanKind::Typed { .. } => dialog.submit_tan(resume, &read_tan()).await?,
};
}
_ => unreachable!("only a transfer pauses on its payee check"),
}
};
let account = opened.accounts[0].account()?;
if let Step::Done(balance) = jobs::balance(&mut dialog, &account).await? {
println!("{:?}", balance.value);
}
let state = dialog.end().await?;
std::fs::write("state.json", state.to_json()?)?; // encrypt this in a real app§Steps instead of callbacks
Every job in jobs returns a jobs::Step: Done with the value,
or a pause with a resume handle. NeedTan carries a
jobs::TanChallenge; its jobs::TanKind says how to answer:
- Typed (chipTAN, smsTAN, photoTAN): the user types the TAN, you call
jobs::Dialog::submit_tan. A flicker code or photoTAN image comes inmediafor you to render. - Decoupled (app approval): sleep until
not_before, then calljobs::Dialog::poll; repeat while the bank says it is still waiting. Whenauto_polling_allowedisSome(false), poll only when the user asks (a button), not on a timer.
A jobs::transfer may also pause on its payee check
(NeedVopConfirmation). The library never sleeps and never calls back.
A paused dialog can be frozen into a serialisable value and thawed in a
new process (jobs::Dialog::freeze). jobs::synchronise learns the
allowed TAN methods without a login, so the user can choose one before
open.
§Banks
bank_by_blz looks a bank up in the bank directory by its BLZ
(Bankleitzahl: the German bank code, characters 5 to 12 of the IBAN) and
returns a BankConfig with its server and profile. A bank’s own
behaviour lives in its BankProfile, not in code paths.
§Cargo features
http(default):HttpTransport(reqwest with rustls), the default transport of ajobs::Dialog. Without it you supply the transport.trace:RecorderandTrace, masked recordings of dialogs.testbank: registers the synthetic test bank (BLZ 12345678 on localhost) as a known bank.tooling: the protocol internals (codec,protocol,types) for the test bank and wire-level tests. Applications usejobs.
§Dates
Dates and timestamps in the API are jiff types. The crate re-exports
jiff so a caller can name the version this crate uses.
Re-exports§
pub use banks::BankConfig;pub use banks::BankProfile;pub use banks::BookingIdSource;pub use banks::InitMode;pub use banks::ProfileId;pub use banks::all_banks;pub use banks::bank_by_blz;pub use error::AddressingReason;pub use error::BankError;pub use error::FinTSError;pub use error::Result;pub use error::TransportKind;pub use jobs::CheckedTransfer;pub use jobs::Instant;pub use jobs::InvalidReason;pub use jobs::InvalidTransfer;pub use jobs::PayeeOutcome;pub use jobs::PayeeResult;pub use jobs::Transfer;pub use jobs::TransferField;pub use jobs::VopResult;pub use return_code::Category;pub use return_code::ClientWarning;pub use return_code::Notice;pub use return_code::NoticeDialog;pub use return_code::ReturnCode;pub use session::SessionState;pub use jiff;
Modules§
- banks
- Bank directory: known German banks with their FinTS endpoint URLs and bank profiles.
- camt
- CAMT.052 (ISO 20022 “Bank to Customer Account Report”) parser.
- error
- formats
- Bank data formats.
- jobs
- Jobs as steps (docs/jobs-step-design.md).
- mask
- Masking of FinTS messages for logs and tooling.
- quirks
- Repairs for bank messages that break the message layout.
- return_
code - Return codes (“Rückmeldungen”) of HIRMG and HIRMS, Formals 2017 B.7.
- session
- The state a client keeps between runs.
- trace
trace - Recording dialogs as masked, anonymised traces (feature
trace). - transport
- Transport layer: how a FinTS message reaches the bank.
Structs§
- Account
Non- tooling - The account an order is for, as KTI (international: IBAN and BIC) and, where known, KTV (national: number, subaccount, bank code).
- Account
Balance Non- tooling - Account balance.
- Account
KeyError Non- tooling - Why a string is not an
AccountKey. - Account
Limit Non- tooling - Kontolimit, or the limit of one allowed order.
- Bank
Name Non- tooling - Human-readable bank name.
- Bank
Time Non- tooling - A time the bank stamped on its data: the bank’s wall clock, and its UTC
offset when the bank sent one. FinTS carries no time zones (Formals
timis the sender’s local time); SWIFT:13D:adds a fixed offset, the older:13:(HBCI 2.2 IX.2.9) has none. Not serde (jiff’sOffsetis not); likejobs::Statement. - Bic
Non- tooling - BIC (Bank Identifier Code).
- Blz
Non- tooling - Bank code (Bankleitzahl), e.g. “12030000”.
- Challenge
Text Non- tooling - TAN challenge text to display to the user.
- Currency
Non- tooling - Currency code (ISO 4217), e.g. “EUR”.
- Depot
Transaction Non- tooling - One depot transaction (securities movement) from an MT536 statement.
- FinTS
Url Non- tooling - FinTS server URL.
- Format
Lists Non- tooling - The data formats of a
VersionMismatchon a format. - Iban
Non- tooling - IBAN (International Bank Account Number).
- Isin
Non- tooling - ISIN (International Securities Identification Number), e.g. “DE0005140008”.
- Pin
Non- tooling - The user’s PIN.
DebugandDisplaynever show it. - Product
Id Non- tooling - FinTS product registration ID.
- Security
Function Non- tooling - Security function code, e.g. “940” for pushTAN, “999” for PIN-only.
- Security
Holding Non- tooling - A single securities position in a depot.
- Segment
Type Non- tooling - Segment type identifier, e.g. “HKSAL”, “HKKAZ”.
- System
Id Non- tooling - System ID assigned by the bank via HKSYN.
- TanMedium
Name Non- tooling - TAN medium name (e.g. device name for pushTAN).
- TanMethod
Non- tooling - One TAN method the bank offers (an entry of HITANS).
- TanOverrides
Non- tooling - Per-order overrides, keyed by the order’s segment code (e.g.
HKSAL). - Touchdown
Point Non- tooling - Touchdown/pagination point returned by the bank (code 3040).
- Transaction
Non- tooling - A parsed transaction.
- UserId
Non- tooling - FinTS user ID / login name.
- Version
Mismatch Non- tooling - No version of a job is both offered by the bank and implemented by us.
- Wkn
Non- tooling - WKN (Wertpapierkennnummer), e.g. “514000”.
Enums§
- Account
Class Non- tooling - What kind of account a UPD entry is, from its “Kontoart” (Formals, data dictionary). The spec assigns each tens range one kind; the values inside a range are the bank’s own.
- Account
Key Non- tooling - The identity of an account of the UPD, stable across logins: its KTV (Kontoverbindung, HIUPD DE 1), or its IBAN when the UPD entry has no account number.
- Allowance
Non- tooling - What the UPD says about an order for an account.
- Class
Source Non- tooling - Where an
AccountClasscame from. - Depot
Transaction Direction Non- tooling - Whether securities came into or left the depot (MT536
:22H::REDE). - Limit
Kind Non- tooling - Limitart.
- TanMedia
Non- tooling - HHD-UC challenge data sorted into something a user interface can show.
- TanOverride
Non- tooling - A bank profile’s fixed answer for one order, beating HIPINS.
- TanProcess
Non- tooling - “TAN-Prozess” of a two-step method (PIN/TAN document, HITANS).
- Transaction
Status Non- tooling - Whether a transaction is booked or pending (vorgemerkt).