Skip to content

Commit 336d7ab

Browse files
committed
save transaction parameters in BPD, consider supported CAMT formats when sending HKCAZ with allowed formats, some refactoring
1 parent 7042ed3 commit 336d7ab

7 files changed

Lines changed: 76 additions & 46 deletions

File tree

src/bankTransaction.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
import type { HICAZSParameter } from './segments/HICAZS.js';
2+
import type { HIKAZSParameter } from './segments/HIKAZS.js';
3+
import type { HISPASParameter } from './segments/HISPAS.js';
4+
15
export type BankTransaction = {
26
transId: string;
37
tanRequired: boolean;
48
versions: number[];
9+
params?: unknown;
10+
};
11+
12+
export type SepaBankTransaction = BankTransaction & {
13+
transId: 'HKSPA';
14+
params: HISPASParameter;
15+
};
16+
17+
export type StatementTransactionMT940 = BankTransaction & {
18+
transId: 'HKKAZ';
19+
params: HIKAZSParameter;
20+
};
21+
22+
export type StatementTransactionCAMT = BankTransaction & {
23+
transId: 'HKCAZ';
24+
params: HICAZSParameter;
525
};

src/config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ export class FinTSConfig {
204204
return this.availableTanMethods.find((t) => t.id === this.tanMethodId);
205205
}
206206

207+
/**
208+
* Gets the transaction parameters for a specific transaction ID
209+
* @param transId The transaction ID
210+
* @returns The transaction parameters or undefined if not available
211+
*/
212+
getTransactionParameters<T>(transId: string): T | undefined {
213+
const transaction = this.bankingInformation.bpd?.allowedTransactions.find(
214+
(t) => t.transId === transId,
215+
);
216+
return transaction?.params as T | undefined;
217+
}
218+
207219
/**
208220
* Checks if a transaction is supported by the bank
209221
* @param transId The transaction ID

src/dataGroups/SepaAccountParameters.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/interactions/initDialogInteraction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Language, SyncMode, TanMediaRequirement } from '../codes.js';
66
import type { FinTSConfig } from '../config.js';
77
import type { Message } from '../message.js';
88
import type { Segment } from '../segment.js';
9+
import type { BusinessTransactionParameterSegment } from '../segments/businessTransactionParameter.js';
910
import { HIBPA, type HIBPASegment } from '../segments/HIBPA.js';
1011
import { HIKIM, type HIKIMSegment } from '../segments/HIKIM.js';
1112
import { HIKOM, type HIKOMSegment } from '../segments/HIKOM.js';
@@ -140,11 +141,19 @@ export class InitDialogInteraction extends CustomerInteraction {
140141
if (transaction.transId.startsWith('HK') || transaction.transId.startsWith('DK')) {
141142
const paramSegId = `HI${transaction.transId.slice(2)}S`;
142143
const paramSegments = [
143-
...response.findAllSegments(paramSegId),
144-
...response.findAllUnknownSegments(paramSegId),
144+
...response.findAllSegments<BusinessTransactionParameterSegment<unknown>>(paramSegId),
145145
];
146146

147+
const unknownParamSegments = [...response.findAllUnknownSegments(paramSegId)];
148+
147149
paramSegments.forEach((paramSegment) => {
150+
if (paramSegment) {
151+
transaction.versions.push(paramSegment.header.version);
152+
transaction.params = paramSegment.params;
153+
}
154+
});
155+
156+
unknownParamSegments.forEach((paramSegment) => {
148157
if (paramSegment) {
149158
transaction.versions.push(paramSegment.header.version);
150159
}

src/interactions/sepaAccountInteraction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export class SepaAccountInteraction extends CustomerOrderInteraction {
5353

5454
clientResponse.sepaAccounts.forEach((sepaAccount) => {
5555
const bankAccount = this.dialog?.config.getBankAccount(sepaAccount.accountNumber);
56-
if (bankAccount) {
56+
if (bankAccount && !bankAccount.isSepaAccount) {
5757
bankAccount.isSepaAccount = sepaAccount.isSepaAccount;
5858
bankAccount.iban = sepaAccount.iban;
5959
bankAccount.bic = sepaAccount.bic;

src/interactions/statementInteractionCAMT.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ import type { FinTSConfig } from '../config.js';
33
import type { Message } from '../message.js';
44
import type { Segment } from '../segment.js';
55
import { HICAZ, type HICAZSegment } from '../segments/HICAZ.js';
6+
import type { HICAZSParameter } from '../segments/HICAZS.js';
67
import { HKCAZ, type HKCAZSegment } from '../segments/HKCAZ.js';
78
import type { Statement } from '../statement.js';
89
import { CustomerOrderInteraction, type StatementResponse } from './customerInteraction.js';
910

1011
export class StatementInteractionCAMT extends CustomerOrderInteraction {
11-
private acceptedCamtFormats: string[] = ['urn:iso:std:iso:20022:tech:xsd:camt.052.001.08'];
12-
1312
constructor(
1413
public accountNumber: string,
1514
public from?: Date,
@@ -25,10 +24,20 @@ export class StatementInteractionCAMT extends CustomerOrderInteraction {
2524
throw Error(`There is no supported version for business transaction '${HKCAZ.Id}'`);
2625
}
2726

27+
let acceptedCamtFormats = ['urn:iso:std:iso:20022:tech:xsd:camt.052.001.08'];
28+
29+
const params = init.getTransactionParameters<HICAZSParameter>(HKCAZ.Id);
30+
31+
if (params && params.supportedCamtFormats.length > 0) {
32+
acceptedCamtFormats = params.supportedCamtFormats.filter((format) =>
33+
format.startsWith('urn:iso:std:iso:20022:tech:xsd:camt.052.001.'),
34+
);
35+
}
36+
2837
const hkcaz: HKCAZSegment = {
2938
header: { segId: HKCAZ.Id, segNr: 0, version: version },
3039
account: bankAccount,
31-
acceptedCamtFormats: this.acceptedCamtFormats,
40+
acceptedCamtFormats: acceptedCamtFormats,
3241
allAccounts: false,
3342
from: this.from,
3443
to: this.to,

src/segments/HISPAS.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
import {
2-
type SepaAccountParameters,
3-
SepaAccountParametersGroup,
4-
} from '../dataGroups/SepaAccountParameters.js';
1+
import { AlphaNumeric } from '../dataElements/AlphaNumeric.js';
2+
import { Numeric } from '../dataElements/Numeric.js';
3+
import { YesNo } from '../dataElements/YesNo.js';
54
import {
65
BusinessTransactionParameter,
76
type BusinessTransactionParameterSegment,
87
} from './businessTransactionParameter.js';
98

10-
export type HISPASSegment = BusinessTransactionParameterSegment<SepaAccountParameters>;
9+
export type HISPASSegment = BusinessTransactionParameterSegment<HISPASParameter>;
1110

12-
export type HISPASParameter = SepaAccountParameters;
11+
export type HISPASParameter = {
12+
individualAccountRetrievalAllowed: boolean;
13+
nationalAccountAllowed: boolean;
14+
structuredPurposeAllowed: boolean;
15+
maxEntriesAllowed?: boolean; // version 2+
16+
reservedPurposePositions?: number; // version 3+
17+
supportedSepaFormats?: string[]; // optional, up to 99 entries
18+
};
1319

1420
/**
1521
* Parameters for HKSPA business transaction - SEPA account connection request
@@ -22,7 +28,14 @@ export class HISPAS extends BusinessTransactionParameter {
2228
constructor() {
2329
super(
2430
HISPAS.Id,
25-
[new SepaAccountParametersGroup('sepaAccountParams', 1, 1)],
31+
[
32+
new YesNo('individualAccountRetrievalAllowed', 1, 1),
33+
new YesNo('nationalAccountAllowed', 1, 1),
34+
new YesNo('structuredPurposeAllowed', 1, 1),
35+
new YesNo('maxEntriesAllowed', 1, 1, 2), // version 2+
36+
new Numeric('reservedPurposePositions', 1, 1, 2, 3), // version 3+
37+
new AlphaNumeric('supportedSepaFormats', 0, 99, 256), // optional, up to 99 entries
38+
],
2639
1, // secClassMinVersion
2740
);
2841
}

0 commit comments

Comments
 (0)