-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
52 lines (52 loc) · 1.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { formatToCPA005, validateCPA005 } from './formats/cpa005.js';
export class EFTGenerator {
#config;
#transactions;
constructor(config) {
this.#config = config;
this.#transactions = [];
}
getConfiguration() {
return this.#config;
}
addTransaction(transaction) {
this.#transactions.push(transaction);
}
addCreditTransaction(transactionSegment) {
this.addTransaction({
recordType: 'C',
segments: [transactionSegment]
});
}
addDebitTransaction(transactionSegment) {
this.addTransaction({
recordType: 'D',
segments: [transactionSegment]
});
}
getTransactions() {
return this.#transactions;
}
/**
* Generates a CPA-005 formatted string.
* @throws Fatal error if the configuration or transactions don't pass validation.
* @returns Data formatted to the CPA-005 standard.
*/
toCPA005() {
return formatToCPA005(this);
}
/**
* Checks if the current configuration and transactions can be processed into the CPA-005 format.
* @returns `true` if there will be no fatal errors.
*/
validateCPA005() {
try {
validateCPA005(this);
return true;
}
catch {
return false;
}
}
}
export { cpaTransactionCodes, isCPATransactionCode } from '@cityssm/cpa-codes';