Skip to main content

fints_client/
lib.rs

1//! # fints-client: a FinTS 3.0 PIN/TAN client
2//!
3//! FinTS (formerly HBCI) is the online-banking protocol of German banks.
4//! This crate reads balances, transactions and securities holdings, and
5//! sends SEPA and instant transfers with the payee name check
6//! (Verification of Payee).
7//!
8//! Banks answer only clients registered with the Deutsche Kreditwirtschaft:
9//! register your app at <https://www.fints.org/de/hersteller/produktregistrierung>
10//! and pass its product ID to [`jobs::BankClient::new`]. The crate ships
11//! with no product ID.
12//!
13//! ## Quick start
14//!
15//! Every operation is `async`. The default `http` transport is reqwest and
16//! needs a tokio runtime.
17//!
18//! ```rust,no_run
19//! use fints_client::jobs::{self, BankClient, Credentials, Step, TanKind};
20//! use fints_client::{bank_by_blz, jiff::Timestamp, Pin, ProductId, SessionState, UserId};
21//!
22//! # fn read_tan() -> String { String::new() }
23//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
24//! let config = bank_by_blz("12030000").expect("BLZ in the bank directory"); // DKB
25//! let client = BankClient::new(config, ProductId::new("YOUR-PRODUCT-ID"));
26//! let user = UserId::new("user");
27//! let creds = Credentials::new(user.clone(), Pin::new("pin"));
28//! let state = SessionState::new(&client.config().blz, &user); // or SessionState::from_json(stored)
29//!
30//! // Open the dialog. A bank that wants a TAN answers `NeedTan`.
31//! let (mut dialog, mut step) = jobs::open(&client, &creds, &state).await?;
32//! let opened = loop {
33//!     match step {
34//!         Step::Done(done) => break done.value,
35//!         Step::NeedTan(challenge, resume) => {
36//!             println!("{}", challenge.challenge);
37//!             step = match challenge.kind {
38//!                 // App approval: wait as long as the bank asks, then ask once.
39//!                 TanKind::Decoupled { .. } => {
40//!                     if let Some(at) = challenge.not_before {
41//!                         let wait = at.duration_since(Timestamp::now());
42//!                         tokio::time::sleep(wait.try_into().unwrap_or_default()).await;
43//!                     }
44//!                     dialog.poll(resume).await?
45//!                 }
46//!                 // chipTAN, smsTAN, photoTAN: the user types the TAN.
47//!                 TanKind::Typed { .. } => dialog.submit_tan(resume, &read_tan()).await?,
48//!             };
49//!         }
50//!         _ => unreachable!("only a transfer pauses on its payee check"),
51//!     }
52//! };
53//!
54//! let account = opened.accounts[0].account()?;
55//! if let Step::Done(balance) = jobs::balance(&mut dialog, &account).await? {
56//!     println!("{:?}", balance.value);
57//! }
58//! let state = dialog.end().await?;
59//! std::fs::write("state.json", state.to_json()?)?; // encrypt this in a real app
60//! # Ok(())
61//! # }
62//! ```
63//!
64//! ## Steps instead of callbacks
65//!
66//! Every job in [`jobs`] returns a [`jobs::Step`]: `Done` with the value,
67//! or a pause with a resume handle. `NeedTan` carries a
68//! [`jobs::TanChallenge`]; its [`jobs::TanKind`] says how to answer:
69//!
70//! - **Typed** (chipTAN, smsTAN, photoTAN): the user types the TAN, you call
71//!   [`jobs::Dialog::submit_tan`]. A flicker code or photoTAN image comes in
72//!   `media` for you to render.
73//! - **Decoupled** (app approval): sleep until `not_before`, then call
74//!   [`jobs::Dialog::poll`]; repeat while the bank says it is still waiting.
75//!   When `auto_polling_allowed` is `Some(false)`, poll only when the user
76//!   asks (a button), not on a timer.
77//!
78//! A [`jobs::transfer`] may also pause on its payee check
79//! (`NeedVopConfirmation`). The library never sleeps and never calls back.
80//! A paused dialog can be frozen into a serialisable value and thawed in a
81//! new process ([`jobs::Dialog::freeze`]). [`jobs::synchronise`] learns the
82//! allowed TAN methods without a login, so the user can choose one before
83//! `open`.
84//!
85//! ## Banks
86//!
87//! [`bank_by_blz`] looks a bank up in the bank directory by its BLZ
88//! (Bankleitzahl: the German bank code, characters 5 to 12 of the IBAN) and
89//! returns a [`BankConfig`] with its server and profile. A bank's own
90//! behaviour lives in its [`BankProfile`], not in code paths.
91//!
92//! ## Cargo features
93//!
94//! - `http` (default): `HttpTransport` (reqwest with rustls), the default
95//!   transport of a [`jobs::Dialog`]. Without it you supply the transport.
96//! - `trace`: `Recorder` and `Trace`, masked recordings of dialogs.
97//! - `testbank`: registers the synthetic test bank (BLZ 12345678 on
98//!   localhost) as a known bank.
99//! - `tooling`: the protocol internals (`codec`, `protocol`, `types`) for
100//!   the test bank and wire-level tests. Applications use `jobs`.
101//!
102//! ## Dates
103//!
104//! Dates and timestamps in the API are [`jiff`] types. The crate re-exports
105//! `jiff` so a caller can name the version this crate uses.
106
107#![cfg_attr(docsrs, feature(doc_cfg))]
108
109// Lets code generated by `fints-client-derive` name `::fints_client` inside
110// this crate as well.
111extern crate self as fints_client;
112
113// ── Infrastructure ──
114pub mod banks;
115pub mod camt;
116#[cfg(feature = "tooling")]
117pub mod codec;
118#[cfg(not(feature = "tooling"))]
119#[allow(unused, dead_code)]
120pub(crate) mod codec;
121pub mod error;
122pub mod formats;
123pub mod mask;
124pub(crate) mod message;
125#[cfg_attr(not(feature = "tooling"), allow(dead_code))]
126pub(crate) mod parser;
127pub mod return_code;
128pub(crate) mod segments;
129#[cfg(feature = "tooling")]
130pub mod types;
131#[cfg(not(feature = "tooling"))]
132#[allow(unused, dead_code)]
133pub(crate) mod types;
134
135// ── Architecture ──
136pub mod jobs;
137#[cfg(feature = "tooling")]
138pub mod protocol;
139#[cfg(not(feature = "tooling"))]
140#[allow(unused, dead_code)]
141pub(crate) mod protocol;
142pub mod quirks;
143pub mod session;
144#[cfg(feature = "trace")]
145pub mod trace;
146pub mod transport;
147
148// ═══════════════════════════════════════════════════════════════════════════════
149// Re-exports
150// ═══════════════════════════════════════════════════════════════════════════════
151
152pub use jiff;
153
154// Protocol types that public signatures name
155pub use protocol::{
156    Account, AccountLimit, Allowance, FormatLists, LimitKind, TanOverride, TanOverrides,
157    VersionMismatch,
158};
159
160// Domain types
161pub use banks::{
162    BankConfig, BankProfile, BookingIdSource, InitMode, ProfileId, all_banks, bank_by_blz,
163};
164pub use error::{AddressingReason, BankError, FinTSError, Result, TransportKind};
165pub use jobs::{
166    CheckedTransfer, Instant, InvalidReason, InvalidTransfer, PayeeOutcome, PayeeResult, Transfer,
167    TransferField, VopResult,
168};
169pub use return_code::{Category, ClientWarning, Notice, NoticeDialog, ReturnCode};
170pub use session::SessionState;
171pub use types::{
172    AccountBalance, AccountClass, AccountKey, AccountKeyError, BankName, BankTime, Bic, Blz,
173    ChallengeText, ClassSource, Currency, DepotTransaction, DepotTransactionDirection, FinTSUrl,
174    Iban, Isin, Pin, ProductId, SecurityFunction, SecurityHolding, SegmentType, SystemId, TanMedia,
175    TanMediumName, TanMethod, TanProcess, TouchdownPoint, Transaction, TransactionStatus, UserId,
176    Wkn,
177};