|
1 | | -import { Connection } from "./types"; |
| 1 | +import { Connection, BankCapabilities } from "./types"; |
2 | 2 | import { |
3 | 3 | HKIDN, |
4 | 4 | HKVVB, |
@@ -103,6 +103,41 @@ export class Dialog extends DialogConfig { |
103 | 103 | * Stores the maximum supported version parsed during synchronization. |
104 | 104 | */ |
105 | 105 | public hiwpdsVersion = 0; |
| 106 | + /** |
| 107 | + * Whether the bank supports querying account balances (HKSAL). |
| 108 | + * Set to `true` during synchronization if the bank returns a HISALS parameter segment. |
| 109 | + */ |
| 110 | + public supportsBalance = false; |
| 111 | + /** |
| 112 | + * Whether the bank supports fetching bank statements / transaction history (HKKAZ). |
| 113 | + * Set to `true` during synchronization if the bank returns a HIKAZS parameter segment. |
| 114 | + */ |
| 115 | + public supportsTransactions = false; |
| 116 | + /** |
| 117 | + * Whether the bank supports fetching standing orders (HKCDB). |
| 118 | + * Set to `true` during synchronization if the bank returns a HICDBS parameter segment. |
| 119 | + */ |
| 120 | + public supportsStandingOrders = false; |
| 121 | + /** |
| 122 | + * Whether the bank supports SEPA credit transfers (HKCCS). |
| 123 | + * Set to `true` during synchronization if the bank returns a HICCSS parameter segment. |
| 124 | + */ |
| 125 | + public supportsCreditTransfer = false; |
| 126 | + /** |
| 127 | + * Whether the bank supports SEPA direct debits (HKDSE). |
| 128 | + * Set to `true` during synchronization if the bank returns a HIDSES parameter segment. |
| 129 | + */ |
| 130 | + public supportsDirectDebit = false; |
| 131 | + /** |
| 132 | + * Minimum number of signatures required to fetch bank statements (from HIKAZS). |
| 133 | + * A value greater than `0` means a TAN is required. |
| 134 | + */ |
| 135 | + public hikazsMinSignatures = 0; |
| 136 | + /** |
| 137 | + * Minimum number of signatures required to query account balances (from HISALS). |
| 138 | + * A value greater than `0` means a TAN is required. |
| 139 | + */ |
| 140 | + public hisalsMinSignatures = 0; |
106 | 141 | /** |
107 | 142 | * A list of supported SEPA pain-formats as configured by the server. |
108 | 143 | */ |
@@ -148,17 +183,29 @@ export class Dialog extends DialogConfig { |
148 | 183 | const response = await this.send(new Request({ blz, name, pin, systemId, dialogId, msgNo, segments })); |
149 | 184 | this.systemId = escapeFinTS(response.systemId); |
150 | 185 | this.dialogId = response.dialogId; |
151 | | - this.hisalsVersion = response.segmentMaxVersion(HISALS); |
152 | | - this.hikazsVersion = response.segmentMaxVersion(HIKAZS); |
153 | | - this.hicdbVersion = response.segmentMaxVersion(HICDBS); |
| 186 | + const hisalsVer = response.segmentMaxVersion(HISALS); |
| 187 | + this.supportsBalance = hisalsVer > 0; |
| 188 | + if (hisalsVer > 0) this.hisalsVersion = hisalsVer; |
| 189 | + const hikazsVer = response.segmentMaxVersion(HIKAZS); |
| 190 | + this.supportsTransactions = hikazsVer > 0; |
| 191 | + if (hikazsVer > 0) this.hikazsVersion = hikazsVer; |
| 192 | + const hicdbVer = response.segmentMaxVersion(HICDBS); |
| 193 | + this.supportsStandingOrders = hicdbVer > 0; |
| 194 | + if (hicdbVer > 0) this.hicdbVersion = hicdbVer; |
154 | 195 | const hkdseVersion = response.segmentMaxVersion(HIDSES); |
155 | 196 | this.hkdseVersion = hkdseVersion > 0 ? hkdseVersion : 1; |
| 197 | + this.supportsDirectDebit = hkdseVersion > 0; |
156 | 198 | const hkccsVersion = response.segmentMaxVersion(HICCSS); |
157 | 199 | this.hkccsVersion = hkccsVersion > 0 ? hkccsVersion : 1; |
| 200 | + this.supportsCreditTransfer = hkccsVersion > 0; |
158 | 201 | this.hiwpdsVersion = response.segmentMaxVersion(HIWPDS); |
159 | 202 | this.hktanVersion = response.segmentMaxVersion(HITANS); |
160 | 203 | this.tanMethods = response.supportedTanMethods; |
161 | 204 | this.painFormats = response.painFormats; |
| 205 | + const hikazs = response.findSegment(HIKAZS); |
| 206 | + this.hikazsMinSignatures = hikazs?.minSignatures ?? 0; |
| 207 | + const hisals = response.findSegment(HISALS); |
| 208 | + this.hisalsMinSignatures = hisals?.minSignatures ?? 0; |
162 | 209 | const hiupd = response.findSegments(HIUPD); |
163 | 210 | this.hiupd = hiupd; |
164 | 211 | await this.end(); |
@@ -326,4 +373,25 @@ export class Dialog extends DialogConfig { |
326 | 373 | this.decoupledTanManager = undefined; |
327 | 374 | } |
328 | 375 | } |
| 376 | + |
| 377 | + /** |
| 378 | + * Returns the capabilities of the bank based on the parameter segments |
| 379 | + * received during the last synchronisation. |
| 380 | + * |
| 381 | + * Call this only after `sync()` has been invoked so that all version |
| 382 | + * fields have been populated from the server response. |
| 383 | + */ |
| 384 | + public get capabilities(): BankCapabilities { |
| 385 | + return { |
| 386 | + supportsAccounts: true, |
| 387 | + supportsBalance: this.supportsBalance, |
| 388 | + supportsTransactions: this.supportsTransactions, |
| 389 | + supportsHoldings: this.hiwpdsVersion > 0, |
| 390 | + supportsStandingOrders: this.supportsStandingOrders, |
| 391 | + supportsCreditTransfer: this.supportsCreditTransfer, |
| 392 | + supportsDirectDebit: this.supportsDirectDebit, |
| 393 | + requiresTanForTransactions: this.hikazsMinSignatures > 0, |
| 394 | + requiresTanForBalance: this.hisalsMinSignatures > 0, |
| 395 | + }; |
| 396 | + } |
329 | 397 | } |
0 commit comments