Skip to content

Commit 2c4cf95

Browse files
authored
Merge pull request #30 from larsdecker/copilot/update-documentation-with-use-cases
docs: Add comprehensive use cases and practical examples
2 parents cfe90ac + 1fa4c2f commit 2c4cf95

3 files changed

Lines changed: 594 additions & 22 deletions

File tree

README.md

Lines changed: 327 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,35 +55,268 @@ yarn lint
5555

5656
## 🚀 Quick Start
5757

58+
### Minimal Configuration
59+
5860
```typescript
5961
import { PinTanClient } from "fints-lib";
6062

63+
// Create a client with minimal required configuration
6164
const client = new PinTanClient({
62-
url: "https://example.com/fints",
63-
name: "username",
64-
pin: "12345",
65-
blz: "12345678",
65+
url: "https://banking.example.com/fints", // Your bank's FinTS URL
66+
name: "username", // Your banking username
67+
pin: "12345", // Your banking PIN
68+
blz: "12345678", // Bank code (BLZ/Bankleitzahl)
6669
});
6770

68-
// List accounts
71+
// List all accounts
6972
const accounts = await client.accounts();
7073
console.log(accounts);
74+
```
75+
76+
### CLI Quick Start
77+
78+
```bash
79+
# Install globally
80+
npm install -g fints-lib-cli
81+
82+
# List your accounts
83+
fints-lib list-accounts \
84+
--url https://banking.example.com/fints \
85+
-n username \
86+
-p 12345 \
87+
-b 12345678
88+
```
89+
90+
## 📖 Common Use Cases
91+
92+
### 1. Check Account Balance
93+
94+
```typescript
95+
import { PinTanClient } from "fints-lib";
96+
97+
const client = new PinTanClient({
98+
url: process.env.FINTS_URL,
99+
name: process.env.FINTS_USERNAME,
100+
pin: process.env.FINTS_PIN,
101+
blz: process.env.FINTS_BLZ,
102+
});
103+
104+
// Get all accounts
105+
const accounts = await client.accounts();
106+
107+
// Check balance for first account
108+
const balance = await client.balance(accounts[0]);
109+
console.log(`Account: ${accounts[0].iban}`);
110+
console.log(`Balance: ${balance.value.value} ${balance.value.currency}`);
111+
```
112+
113+
**CLI Example**
114+
```bash
115+
fints-lib get-balance \
116+
--url https://banking.example.com/fints \
117+
-n username -p 12345 -b 12345678 \
118+
-i DE89370400440532013000
119+
```
120+
121+
### 2. Fetch Recent Transactions
122+
123+
```typescript
124+
import { PinTanClient } from "fints-lib";
125+
126+
const client = new PinTanClient({
127+
url: process.env.FINTS_URL,
128+
name: process.env.FINTS_USERNAME,
129+
pin: process.env.FINTS_PIN,
130+
blz: process.env.FINTS_BLZ,
131+
});
132+
133+
const accounts = await client.accounts();
134+
135+
// Fetch last 30 days of transactions
136+
const endDate = new Date();
137+
const startDate = new Date(endDate.getTime() - 30 * 24 * 60 * 60 * 1000);
71138

72-
// Fetch statements
73-
const startDate = new Date("2024-01-01");
74-
const endDate = new Date("2024-12-31");
75139
const statements = await client.statements(accounts[0], startDate, endDate);
76-
console.log(statements);
140+
141+
// Process transactions
142+
statements.forEach(statement => {
143+
console.log(`Date: ${statement.date}`);
144+
statement.transactions.forEach(transaction => {
145+
console.log(` ${transaction.descriptionStructured?.bookingText || 'Transaction'}`);
146+
console.log(` Amount: ${transaction.amount} ${transaction.currency}`);
147+
console.log(` Purpose: ${transaction.purpose || 'N/A'}`);
148+
});
149+
});
77150
```
78151

79-
For CLI usage:
152+
**CLI Example**
153+
```bash
154+
# Fetch transactions for a date range
155+
fints-lib fetch-transactions \
156+
--url https://banking.example.com/fints \
157+
-n username -p 12345 -b 12345678 \
158+
-i DE89370400440532013000 \
159+
-s 2024-01-01 -e 2024-12-31 \
160+
--json > transactions.json
161+
```
162+
163+
### 3. SEPA Credit Transfer (Send Money)
164+
165+
```typescript
166+
import { PinTanClient, TanRequiredError } from "fints-lib";
167+
168+
const client = new PinTanClient({
169+
url: process.env.FINTS_URL,
170+
name: process.env.FINTS_USERNAME,
171+
pin: process.env.FINTS_PIN,
172+
blz: process.env.FINTS_BLZ,
173+
});
174+
175+
const accounts = await client.accounts();
176+
const myAccount = accounts[0];
177+
178+
// Prepare transfer
179+
const transfer = {
180+
debtorName: "John Doe",
181+
creditor: {
182+
name: "Recipient Name",
183+
iban: "DE44500105175407324931",
184+
bic: "INGDDEFFXXX", // Optional for transfers within SEPA
185+
},
186+
amount: 50.00,
187+
remittanceInformation: "Payment for invoice #12345",
188+
};
189+
190+
try {
191+
// Initiate transfer
192+
const result = await client.creditTransfer(myAccount, transfer);
193+
console.log("Transfer successful:", result.taskId);
194+
} catch (error) {
195+
if (error instanceof TanRequiredError) {
196+
// TAN is required - get TAN from user
197+
const tan = "123456"; // Get from user input or TAN app
198+
199+
const result = await client.completeCreditTransfer(
200+
error.dialog,
201+
error.transactionReference,
202+
tan,
203+
error.creditTransferSubmission
204+
);
205+
console.log("Transfer completed:", result.taskId);
206+
} else {
207+
throw error;
208+
}
209+
}
210+
```
211+
212+
**CLI Example**
213+
```bash
214+
# Transfer money (will prompt for TAN if required)
215+
fints-lib submit-credit-transfer \
216+
--url https://banking.example.com/fints \
217+
-n username -p 12345 -b 12345678 \
218+
--account-iban DE89370400440532013000 \
219+
--debtor-name "John Doe" \
220+
--creditor-name "Recipient Name" \
221+
--creditor-iban DE44500105175407324931 \
222+
--amount 50.00 \
223+
--remittance "Payment for invoice #12345"
224+
```
225+
226+
### 4. SEPA Direct Debit (Collect Money)
227+
228+
```typescript
229+
import { PinTanClient, TanRequiredError } from "fints-lib";
230+
231+
const client = new PinTanClient({
232+
url: process.env.FINTS_URL,
233+
name: process.env.FINTS_USERNAME,
234+
pin: process.env.FINTS_PIN,
235+
blz: process.env.FINTS_BLZ,
236+
});
237+
238+
const accounts = await client.accounts();
239+
const myAccount = accounts[0];
240+
241+
// Prepare direct debit
242+
const debit = {
243+
creditorName: "My Company GmbH",
244+
creditorId: "DE98ZZZ09999999999", // Your SEPA creditor ID
245+
debtor: {
246+
name: "Customer Name",
247+
iban: "DE02120300000000202051",
248+
},
249+
amount: 99.99,
250+
mandateId: "MANDATE-2024-001",
251+
mandateSignatureDate: new Date("2024-01-15"),
252+
requestedCollectionDate: new Date("2024-12-15"),
253+
remittanceInformation: "Monthly subscription fee",
254+
};
255+
256+
try {
257+
const result = await client.directDebit(myAccount, debit);
258+
console.log("Direct debit submitted:", result.taskId);
259+
} catch (error) {
260+
if (error instanceof TanRequiredError) {
261+
const tan = "123456"; // Get from user
262+
263+
const result = await client.completeDirectDebit(
264+
error.dialog,
265+
error.transactionReference,
266+
tan,
267+
error.directDebitSubmission
268+
);
269+
console.log("Direct debit completed:", result.taskId);
270+
} else {
271+
throw error;
272+
}
273+
}
274+
```
80275

276+
**CLI Example**
81277
```bash
82-
# List accounts
83-
fints-lib list-accounts --url https://example.com/fints -n username -p 12345 -b 12345678
278+
fints-lib submit-direct-debit \
279+
--url https://banking.example.com/fints \
280+
-n username -p 12345 -b 12345678 \
281+
--account-iban DE89370400440532013000 \
282+
--creditor-name "My Company GmbH" \
283+
--creditor-id DE98ZZZ09999999999 \
284+
--debtor-name "Customer Name" \
285+
--debtor-iban DE02120300000000202051 \
286+
--amount 99.99 \
287+
--mandate-id MANDATE-2024-001 \
288+
--mandate-date 2024-01-15 \
289+
--collection-date 2024-12-15 \
290+
--remittance "Monthly subscription fee"
291+
```
84292

85-
# Fetch transactions
86-
fints-lib fetch-transactions --url https://example.com/fints -n username -p 12345 -b 12345678 -i DE111234567800000001 -s 2024-01-01 -e 2024-12-31
293+
### 5. List Multiple Accounts and Their Balances
294+
295+
```typescript
296+
import { PinTanClient } from "fints-lib";
297+
298+
const client = new PinTanClient({
299+
url: process.env.FINTS_URL,
300+
name: process.env.FINTS_USERNAME,
301+
pin: process.env.FINTS_PIN,
302+
blz: process.env.FINTS_BLZ,
303+
});
304+
305+
// Get all accounts with balances
306+
const accounts = await client.accounts();
307+
308+
for (const account of accounts) {
309+
console.log(`\n${account.accountName || 'Account'} (${account.iban})`);
310+
console.log(` Type: ${account.accountType || 'N/A'}`);
311+
312+
try {
313+
const balance = await client.balance(account);
314+
console.log(` Balance: ${balance.value.value} ${balance.value.currency}`);
315+
console.log(` Available: ${balance.availableBalance?.value || 'N/A'}`);
316+
} catch (error) {
317+
console.log(` Balance: Unable to fetch`);
318+
}
319+
}
87320
```
88321

89322
> Before using any FinTS library you have to register your application with Die Deutsche Kreditwirtschaft in order to get your registration number. Note that this process can take several weeks. First you receive your registration number after a couple days, but then you have to wait anywhere between 0 and 8+ weeks for the registration to reach your bank's server. If you have multiple banks, it probably reaches them at different times.
@@ -135,6 +368,86 @@ const badClient = new PinTanClient({
135368

136369
If you discover a security vulnerability, please report it privately via GitHub's "Security" tab instead of opening a public issue.
137370

371+
## 💡 Tips and Troubleshooting
372+
373+
### Finding Your Bank's FinTS URL
374+
375+
You can find your bank's FinTS endpoint URL in this community database:
376+
- [FinTS Institute Database](https://github.com/jhermsmeier/fints-institute-db)
377+
378+
### Common Issues
379+
380+
**Authentication Errors:**
381+
- Verify your username, PIN, and BLZ are correct
382+
- Some banks require you to enable FinTS/HBCI access in your online banking settings
383+
- Check if your bank requires registration (see registration note below)
384+
385+
**TAN Requirements:**
386+
- Many operations (transfers, direct debits) require TAN authentication
387+
- Use try-catch with `TanRequiredError` to handle TAN challenges properly
388+
- Some banks require TAN even for login - handle with `completeLogin()`
389+
390+
**Timeout Issues:**
391+
- Increase the timeout value in client configuration:
392+
```typescript
393+
const client = new PinTanClient({
394+
// ... other config
395+
timeout: 60000, // 60 seconds
396+
maxRetries: 5,
397+
});
398+
```
399+
400+
**Date Range Queries:**
401+
- Not all banks support all date ranges - some limit how far back you can query
402+
- Use shorter date ranges if you experience timeouts or errors
403+
404+
### Best Practices
405+
406+
1. **Always use environment variables for credentials:**
407+
```typescript
408+
const client = new PinTanClient({
409+
url: process.env.FINTS_URL,
410+
name: process.env.FINTS_USERNAME,
411+
pin: process.env.FINTS_PIN,
412+
blz: process.env.FINTS_BLZ,
413+
});
414+
```
415+
416+
2. **Enable debug mode during development:**
417+
```typescript
418+
const client = new PinTanClient({
419+
// ... credentials
420+
debug: process.env.NODE_ENV === 'development',
421+
});
422+
```
423+
424+
3. **Handle errors gracefully:**
425+
```typescript
426+
import { FinTSError, TanRequiredError, PinError } from "fints-lib";
427+
428+
try {
429+
const accounts = await client.accounts();
430+
} catch (error) {
431+
if (error instanceof TanRequiredError) {
432+
// Handle TAN requirement
433+
} else if (error instanceof PinError) {
434+
// Handle PIN error
435+
} else if (error instanceof FinTSError) {
436+
console.error(`FinTS Error [${error.code}]: ${error.message}`);
437+
}
438+
}
439+
```
440+
441+
4. **Close dialogs when done:**
442+
```typescript
443+
const dialog = await client.startDialog();
444+
try {
445+
// ... perform operations
446+
} finally {
447+
await dialog.end();
448+
}
449+
```
450+
138451
## Mentions
139452

140453
FinTS is a complex and old format and this library wouldn't have been possible without the great work of:

0 commit comments

Comments
 (0)