@lucianpacurar/iso20022.js 0.2.7 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +250 -6
- package/dist/index.js +343 -0
- package/dist/index.mjs +343 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/iso20022.d.ts +80 -0
- package/dist/src/pain/001/sepa-multi-credit-payment-initiation.d.ts +167 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -622,7 +622,7 @@ declare abstract class PaymentInitiation {
|
|
|
622
622
|
static getBuilder(): XMLBuilder;
|
|
623
623
|
}
|
|
624
624
|
|
|
625
|
-
type AtLeastOne$
|
|
625
|
+
type AtLeastOne$5<T> = [T, ...T[]];
|
|
626
626
|
/**
|
|
627
627
|
* Configuration for SWIFT Credit Payment Initiation.
|
|
628
628
|
*
|
|
@@ -635,7 +635,7 @@ interface SWIFTCreditPaymentInitiationConfig$1 {
|
|
|
635
635
|
/** The party initiating the payment. */
|
|
636
636
|
initiatingParty: Party;
|
|
637
637
|
/** An array of payment instructions. */
|
|
638
|
-
paymentInstructions: AtLeastOne$
|
|
638
|
+
paymentInstructions: AtLeastOne$5<SWIFTCreditPaymentInstruction>;
|
|
639
639
|
/** Optional unique identifier for the message. If not provided, a UUID will be generated. */
|
|
640
640
|
messageId?: string;
|
|
641
641
|
/** Optional creation date for the message. If not provided, current date will be used. */
|
|
@@ -692,7 +692,7 @@ declare class SWIFTCreditPaymentInitiation extends PaymentInitiation {
|
|
|
692
692
|
serialize(): string;
|
|
693
693
|
}
|
|
694
694
|
|
|
695
|
-
type AtLeastOne$
|
|
695
|
+
type AtLeastOne$4<T> = [T, ...T[]];
|
|
696
696
|
/**
|
|
697
697
|
* Configuration for SEPA Credit Payment Initiation.
|
|
698
698
|
*
|
|
@@ -706,7 +706,7 @@ interface SEPACreditPaymentInitiationConfig$1 {
|
|
|
706
706
|
/** The party initiating the SEPA credit transfer. */
|
|
707
707
|
initiatingParty: Party;
|
|
708
708
|
/** An array containing at least one payment instruction for SEPA credit transfer. */
|
|
709
|
-
paymentInstructions: AtLeastOne$
|
|
709
|
+
paymentInstructions: AtLeastOne$4<SEPACreditPaymentInstruction>;
|
|
710
710
|
/** Optional unique identifier for the message. If not provided, a UUID will be generated. */
|
|
711
711
|
messageId?: string;
|
|
712
712
|
/** Optional creation date for the message. If not provided, current date will be used. */
|
|
@@ -739,7 +739,7 @@ declare class SEPACreditPaymentInitiation extends PaymentInitiation {
|
|
|
739
739
|
initiatingParty: Party;
|
|
740
740
|
messageId: string;
|
|
741
741
|
creationDate: Date;
|
|
742
|
-
paymentInstructions: AtLeastOne$
|
|
742
|
+
paymentInstructions: AtLeastOne$4<SEPACreditPaymentInstruction>;
|
|
743
743
|
paymentInformationId: string;
|
|
744
744
|
categoryPurpose?: ExternalCategoryPurpose;
|
|
745
745
|
private formattedPaymentSum;
|
|
@@ -816,6 +816,171 @@ declare class SEPACreditPaymentInitiation extends PaymentInitiation {
|
|
|
816
816
|
static fromXML(rawXml: string): SEPACreditPaymentInitiation;
|
|
817
817
|
}
|
|
818
818
|
|
|
819
|
+
type AtLeastOne$3<T> = [T, ...T[]];
|
|
820
|
+
/**
|
|
821
|
+
* Represents a group of payment instructions for a single debtor (PmtInf block).
|
|
822
|
+
*
|
|
823
|
+
* @property {Party} initiatingParty - The party (debtor) for this specific payment information block.
|
|
824
|
+
* @property {AtLeastOne<SEPACreditPaymentInstruction>} payments - An array containing at least one payment instruction for this debtor.
|
|
825
|
+
* @property {ExternalCategoryPurpose} [categoryPurpose] - Optional category purpose code for this payment information block.
|
|
826
|
+
*/
|
|
827
|
+
interface SEPAMultiCreditPaymentInstructionGroup {
|
|
828
|
+
/** The party (debtor) for this specific payment information block. */
|
|
829
|
+
initiatingParty: Party;
|
|
830
|
+
/** An array containing at least one payment instruction for this debtor. */
|
|
831
|
+
payments: AtLeastOne$3<SEPACreditPaymentInstruction>;
|
|
832
|
+
/** Optional category purpose code for this payment information block. */
|
|
833
|
+
categoryPurpose?: ExternalCategoryPurpose;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Configuration for SEPA Multi Credit Payment Initiation.
|
|
837
|
+
*
|
|
838
|
+
* @property {Party} initiatingParty - The top-level party initiating the message (used in GrpHdr).
|
|
839
|
+
* @property {AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>} paymentInstructions - An array containing at least one payment instruction group.
|
|
840
|
+
* @property {string} [messageId] - Optional unique identifier for the message. If not provided, a UUID will be generated.
|
|
841
|
+
* @property {Date} [creationDate] - Optional creation date for the message. If not provided, current date will be used.
|
|
842
|
+
*/
|
|
843
|
+
interface SEPAMultiCreditPaymentInitiationConfig$1 {
|
|
844
|
+
/** The top-level party initiating the message (used in GrpHdr). */
|
|
845
|
+
initiatingParty: Party;
|
|
846
|
+
/** An array containing at least one payment instruction group. */
|
|
847
|
+
paymentInstructions: AtLeastOne$3<SEPAMultiCreditPaymentInstructionGroup>;
|
|
848
|
+
/** Optional unique identifier for the message. If not provided, a UUID will be generated. */
|
|
849
|
+
messageId?: string;
|
|
850
|
+
/** Optional creation date for the message. If not provided, current date will be used. */
|
|
851
|
+
creationDate?: Date;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Represents a SEPA Multi Credit Payment Initiation.
|
|
855
|
+
* This class handles the creation and serialization of SEPA credit transfer messages
|
|
856
|
+
* with multiple payment information blocks (multiple debtors) according to the ISO20022 standard.
|
|
857
|
+
* @class
|
|
858
|
+
* @extends PaymentInitiation
|
|
859
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration for the SEPA Multi Credit Payment Initiation message.
|
|
860
|
+
* @example
|
|
861
|
+
* ```typescript
|
|
862
|
+
* // Creating a SEPA multi-payment message
|
|
863
|
+
* const payment = new SEPAMultiCreditPaymentInitiation({
|
|
864
|
+
* initiatingParty: { name: 'Company Ltd', id: '12345' },
|
|
865
|
+
* paymentInstructions: [
|
|
866
|
+
* {
|
|
867
|
+
* initiatingParty: debtor1,
|
|
868
|
+
* payments: [payment1, payment2]
|
|
869
|
+
* },
|
|
870
|
+
* {
|
|
871
|
+
* initiatingParty: debtor2,
|
|
872
|
+
* payments: [payment3]
|
|
873
|
+
* }
|
|
874
|
+
* ]
|
|
875
|
+
* });
|
|
876
|
+
* ```
|
|
877
|
+
*/
|
|
878
|
+
declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
|
|
879
|
+
initiatingParty: Party;
|
|
880
|
+
messageId: string;
|
|
881
|
+
creationDate: Date;
|
|
882
|
+
paymentInstructions: AtLeastOne$3<SEPAMultiCreditPaymentInstructionGroup>;
|
|
883
|
+
paymentInformationIdBase: string;
|
|
884
|
+
private formattedPaymentSum;
|
|
885
|
+
private totalTransactionCount;
|
|
886
|
+
/**
|
|
887
|
+
* Creates an instance of SEPAMultiCreditPaymentInitiation.
|
|
888
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration object for the SEPA multi credit transfer.
|
|
889
|
+
*/
|
|
890
|
+
constructor(config: SEPAMultiCreditPaymentInitiationConfig$1);
|
|
891
|
+
/**
|
|
892
|
+
* Counts the total number of transactions across all payment instruction groups.
|
|
893
|
+
* @private
|
|
894
|
+
* @returns {number} The total count of all transactions.
|
|
895
|
+
*/
|
|
896
|
+
private countAllTransactions;
|
|
897
|
+
/**
|
|
898
|
+
* Calculates the sum of all payment instructions across all groups.
|
|
899
|
+
* @private
|
|
900
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
901
|
+
*/
|
|
902
|
+
private sumAllPayments;
|
|
903
|
+
/**
|
|
904
|
+
* Calculates the sum of payment instructions for a single group.
|
|
905
|
+
* @private
|
|
906
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
907
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
908
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
909
|
+
*/
|
|
910
|
+
private sumPaymentInstructions;
|
|
911
|
+
/**
|
|
912
|
+
* Validates the payment initiation data according to SEPA requirements.
|
|
913
|
+
* @private
|
|
914
|
+
* @throws {Error} If messageId exceeds 35 characters.
|
|
915
|
+
* @throws {Error} If any group's payment instructions have different currencies.
|
|
916
|
+
*/
|
|
917
|
+
private validate;
|
|
918
|
+
/**
|
|
919
|
+
* Validates that all payment instructions in a group have the same currency.
|
|
920
|
+
* @private
|
|
921
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
922
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
923
|
+
*/
|
|
924
|
+
private validateGroupInstructionsHaveSameCurrency;
|
|
925
|
+
/**
|
|
926
|
+
* Generates payment information for a single SEPA credit transfer instruction.
|
|
927
|
+
* @param {SEPACreditPaymentInstruction} instruction - The payment instruction.
|
|
928
|
+
* @returns {Object} The payment information object formatted according to SEPA specifications.
|
|
929
|
+
*/
|
|
930
|
+
creditTransfer(instruction: SEPACreditPaymentInstruction): {
|
|
931
|
+
Cdtr: any;
|
|
932
|
+
CdtrAcct: {
|
|
933
|
+
Id: {
|
|
934
|
+
IBAN: string;
|
|
935
|
+
};
|
|
936
|
+
Ccy: "EUR";
|
|
937
|
+
};
|
|
938
|
+
RmtInf: {
|
|
939
|
+
Ustrd: string;
|
|
940
|
+
} | undefined;
|
|
941
|
+
CdtrAgt?: {
|
|
942
|
+
FinInstnId: {
|
|
943
|
+
BIC: string;
|
|
944
|
+
ClrSysMmbId?: undefined;
|
|
945
|
+
};
|
|
946
|
+
} | {
|
|
947
|
+
FinInstnId: {
|
|
948
|
+
ClrSysMmbId: {
|
|
949
|
+
ClrSysId: {
|
|
950
|
+
Cd: string;
|
|
951
|
+
};
|
|
952
|
+
MmbId: string;
|
|
953
|
+
};
|
|
954
|
+
BIC?: undefined;
|
|
955
|
+
};
|
|
956
|
+
} | undefined;
|
|
957
|
+
PmtId: {
|
|
958
|
+
InstrId: string;
|
|
959
|
+
EndToEndId: string;
|
|
960
|
+
};
|
|
961
|
+
Amt: {
|
|
962
|
+
InstdAmt: {
|
|
963
|
+
'#': string;
|
|
964
|
+
'@Ccy': "EUR";
|
|
965
|
+
};
|
|
966
|
+
};
|
|
967
|
+
};
|
|
968
|
+
/**
|
|
969
|
+
* Serializes the SEPA multi credit transfer initiation to an XML string.
|
|
970
|
+
* @returns {string} The XML representation of the SEPA multi credit transfer initiation.
|
|
971
|
+
*/
|
|
972
|
+
serialize(): string;
|
|
973
|
+
/**
|
|
974
|
+
* Parses an XML string and creates a SEPAMultiCreditPaymentInitiation instance.
|
|
975
|
+
* Supports multiple PmtInf blocks in the XML document.
|
|
976
|
+
* @param {string} rawXml - The XML string to parse.
|
|
977
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new instance created from the XML data.
|
|
978
|
+
* @throws {InvalidXmlError} If the XML format is invalid.
|
|
979
|
+
* @throws {InvalidXmlNamespaceError} If the namespace is not pain.001.001.03.
|
|
980
|
+
*/
|
|
981
|
+
static fromXML(rawXml: string): SEPAMultiCreditPaymentInitiation;
|
|
982
|
+
}
|
|
983
|
+
|
|
819
984
|
type AtLeastOne$2<T> = [T, ...T[]];
|
|
820
985
|
/**
|
|
821
986
|
* Configuration for RTP Credit Payment Initiation.
|
|
@@ -1394,6 +1559,53 @@ interface SEPACreditPaymentInitiationConfig {
|
|
|
1394
1559
|
*/
|
|
1395
1560
|
creationDate?: Date;
|
|
1396
1561
|
}
|
|
1562
|
+
/**
|
|
1563
|
+
* Configuration interface for SEPA Multi Credit Payment Initiation.
|
|
1564
|
+
* @interface SEPAMultiCreditPaymentInitiationConfig
|
|
1565
|
+
* @example
|
|
1566
|
+
* const config: SEPAMultiCreditPaymentInitiationConfig = {
|
|
1567
|
+
* paymentInstructions: [
|
|
1568
|
+
* {
|
|
1569
|
+
* initiatingParty: debtor1,
|
|
1570
|
+
* payments: [
|
|
1571
|
+
* {
|
|
1572
|
+
* type: 'sepa',
|
|
1573
|
+
* direction: 'credit',
|
|
1574
|
+
* amount: 1000, // €10.00 Euros
|
|
1575
|
+
* currency: 'EUR',
|
|
1576
|
+
* creditor: {
|
|
1577
|
+
* name: 'Hans Schneider',
|
|
1578
|
+
* account: {
|
|
1579
|
+
* iban: 'DE1234567890123456',
|
|
1580
|
+
* },
|
|
1581
|
+
* },
|
|
1582
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
1583
|
+
* },
|
|
1584
|
+
* ],
|
|
1585
|
+
* categoryPurpose: 'SALA', // Optional
|
|
1586
|
+
* },
|
|
1587
|
+
* ],
|
|
1588
|
+
* messageId: 'MSGID123', // Optional
|
|
1589
|
+
* creationDate: new Date(), // Optional
|
|
1590
|
+
* };
|
|
1591
|
+
*/
|
|
1592
|
+
interface SEPAMultiCreditPaymentInitiationConfig {
|
|
1593
|
+
/**
|
|
1594
|
+
* An array of payment instruction groups, each with its own debtor.
|
|
1595
|
+
* @type {AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>}
|
|
1596
|
+
*/
|
|
1597
|
+
paymentInstructions: AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>;
|
|
1598
|
+
/**
|
|
1599
|
+
* Optional unique identifier for the message. If not provided, a UUID will be generated.
|
|
1600
|
+
* @type {string}
|
|
1601
|
+
*/
|
|
1602
|
+
messageId?: string;
|
|
1603
|
+
/**
|
|
1604
|
+
* Optional creation date for the message. If not provided, current date will be used.
|
|
1605
|
+
* @type {Date}
|
|
1606
|
+
*/
|
|
1607
|
+
creationDate?: Date;
|
|
1608
|
+
}
|
|
1397
1609
|
/**
|
|
1398
1610
|
* Configuration interface for RTP Credit Payment Initiation.
|
|
1399
1611
|
* @interface RTPCreditPaymentInitiationConfig
|
|
@@ -1575,6 +1787,38 @@ declare class ISO20022 {
|
|
|
1575
1787
|
* @returns {SEPACreditPaymentInitiation} A new SEPA Credit Payment Initiation object.
|
|
1576
1788
|
*/
|
|
1577
1789
|
createSEPACreditPaymentInitiation(config: SEPACreditPaymentInitiationConfig): SEPACreditPaymentInitiation;
|
|
1790
|
+
/**
|
|
1791
|
+
* Creates a SEPA Multi Credit Payment Initiation message with multiple payment information blocks.
|
|
1792
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - Configuration containing payment instruction groups and optional parameters.
|
|
1793
|
+
* @example
|
|
1794
|
+
* const payment = iso20022.createSEPAMultiCreditPaymentInitiation({
|
|
1795
|
+
* paymentInstructions: [
|
|
1796
|
+
* {
|
|
1797
|
+
* initiatingParty: debtor1,
|
|
1798
|
+
* payments: [
|
|
1799
|
+
* {
|
|
1800
|
+
* type: 'sepa',
|
|
1801
|
+
* direction: 'credit',
|
|
1802
|
+
* amount: 1000, // €10.00 Euros
|
|
1803
|
+
* currency: 'EUR',
|
|
1804
|
+
* creditor: {
|
|
1805
|
+
* name: 'Hans Schneider',
|
|
1806
|
+
* account: {
|
|
1807
|
+
* iban: 'DE1234567890123456',
|
|
1808
|
+
* },
|
|
1809
|
+
* },
|
|
1810
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
1811
|
+
* },
|
|
1812
|
+
* ],
|
|
1813
|
+
* categoryPurpose: 'SALA', // Optional
|
|
1814
|
+
* },
|
|
1815
|
+
* ],
|
|
1816
|
+
* messageId: 'SEPA-MULTI-MSG-001', // Optional
|
|
1817
|
+
* creationDate: new Date('2025-03-01'), // Optional
|
|
1818
|
+
* });
|
|
1819
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new SEPA Multi Credit Payment Initiation object.
|
|
1820
|
+
*/
|
|
1821
|
+
createSEPAMultiCreditPaymentInitiation(config: SEPAMultiCreditPaymentInitiationConfig): SEPAMultiCreditPaymentInitiation;
|
|
1578
1822
|
/**
|
|
1579
1823
|
* Creates a RTP Credit Payment Initiation message.
|
|
1580
1824
|
* @param {RTPCreditPaymentInitiationConfig} config - Configuration containing payment instructions and optional parameters.
|
|
@@ -1893,4 +2137,4 @@ declare class InvalidXmlNamespaceError extends Iso20022JsError {
|
|
|
1893
2137
|
constructor(message: string);
|
|
1894
2138
|
}
|
|
1895
2139
|
|
|
1896
|
-
export { type ABAAgent, ACHCreditPaymentInitiation, type ACHCreditPaymentInitiationConfig$1 as ACHCreditPaymentInitiationConfig, type ACHCreditPaymentInstruction, type ACHLocalInstrument, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, type Account, type Agent, type BICAgent, type Balance, type BalanceType, BalanceTypeCode, BalanceTypeCodeDescriptionMap, type BaseAccount, type BaseStatusInformation as BaseStatus, CashManagementEndOfDayReport, type Entry, type GroupStatusInformation as GroupStatus, type IBANAccount, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, type OriginalGroupInformation, type Party, type PaymentStatusInformation as PaymentStatus, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, type RTPCreditPaymentInitiationConfig$1 as RTPCreditPaymentInitiationConfig, type RTPCreditPaymentInstruction, SEPACreditPaymentInitiation, type SEPACreditPaymentInitiationConfig$1 as SEPACreditPaymentInitiationConfig, type SEPACreditPaymentInstruction, SWIFTCreditPaymentInitiation, type SWIFTCreditPaymentInitiationConfig$1 as SWIFTCreditPaymentInitiationConfig, type SWIFTCreditPaymentInstruction, type Statement, type PaymentStatus as Status, type StatusInformation, type StatusType, type StructuredAddress, type Transaction, type TransactionStatusInformation as TransactionStatus };
|
|
2140
|
+
export { type ABAAgent, ACHCreditPaymentInitiation, type ACHCreditPaymentInitiationConfig$1 as ACHCreditPaymentInitiationConfig, type ACHCreditPaymentInstruction, type ACHLocalInstrument, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, type Account, type Agent, type BICAgent, type Balance, type BalanceType, BalanceTypeCode, BalanceTypeCodeDescriptionMap, type BaseAccount, type BaseStatusInformation as BaseStatus, CashManagementEndOfDayReport, type Entry, type GroupStatusInformation as GroupStatus, type IBANAccount, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, type OriginalGroupInformation, type Party, type PaymentStatusInformation as PaymentStatus, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, type RTPCreditPaymentInitiationConfig$1 as RTPCreditPaymentInitiationConfig, type RTPCreditPaymentInstruction, SEPACreditPaymentInitiation, type SEPACreditPaymentInitiationConfig$1 as SEPACreditPaymentInitiationConfig, type SEPACreditPaymentInstruction, SEPAMultiCreditPaymentInitiation, type SEPAMultiCreditPaymentInitiationConfig$1 as SEPAMultiCreditPaymentInitiationConfig, type SEPAMultiCreditPaymentInstructionGroup, SWIFTCreditPaymentInitiation, type SWIFTCreditPaymentInitiationConfig$1 as SWIFTCreditPaymentInitiationConfig, type SWIFTCreditPaymentInstruction, type Statement, type PaymentStatus as Status, type StatusInformation, type StatusType, type StructuredAddress, type Transaction, type TransactionStatusInformation as TransactionStatus };
|
package/dist/index.js
CHANGED
|
@@ -7840,6 +7840,309 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
|
|
|
7840
7840
|
}
|
|
7841
7841
|
}
|
|
7842
7842
|
|
|
7843
|
+
/**
|
|
7844
|
+
* Represents a SEPA Multi Credit Payment Initiation.
|
|
7845
|
+
* This class handles the creation and serialization of SEPA credit transfer messages
|
|
7846
|
+
* with multiple payment information blocks (multiple debtors) according to the ISO20022 standard.
|
|
7847
|
+
* @class
|
|
7848
|
+
* @extends PaymentInitiation
|
|
7849
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration for the SEPA Multi Credit Payment Initiation message.
|
|
7850
|
+
* @example
|
|
7851
|
+
* ```typescript
|
|
7852
|
+
* // Creating a SEPA multi-payment message
|
|
7853
|
+
* const payment = new SEPAMultiCreditPaymentInitiation({
|
|
7854
|
+
* initiatingParty: { name: 'Company Ltd', id: '12345' },
|
|
7855
|
+
* paymentInstructions: [
|
|
7856
|
+
* {
|
|
7857
|
+
* initiatingParty: debtor1,
|
|
7858
|
+
* payments: [payment1, payment2]
|
|
7859
|
+
* },
|
|
7860
|
+
* {
|
|
7861
|
+
* initiatingParty: debtor2,
|
|
7862
|
+
* payments: [payment3]
|
|
7863
|
+
* }
|
|
7864
|
+
* ]
|
|
7865
|
+
* });
|
|
7866
|
+
* ```
|
|
7867
|
+
*/
|
|
7868
|
+
class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
|
|
7869
|
+
initiatingParty;
|
|
7870
|
+
messageId;
|
|
7871
|
+
creationDate;
|
|
7872
|
+
paymentInstructions;
|
|
7873
|
+
paymentInformationIdBase;
|
|
7874
|
+
formattedPaymentSum;
|
|
7875
|
+
totalTransactionCount;
|
|
7876
|
+
/**
|
|
7877
|
+
* Creates an instance of SEPAMultiCreditPaymentInitiation.
|
|
7878
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration object for the SEPA multi credit transfer.
|
|
7879
|
+
*/
|
|
7880
|
+
constructor(config) {
|
|
7881
|
+
super({ type: "sepa" });
|
|
7882
|
+
this.initiatingParty = config.initiatingParty;
|
|
7883
|
+
this.paymentInstructions = config.paymentInstructions;
|
|
7884
|
+
this.messageId = config.messageId || v4().replace(/-/g, '');
|
|
7885
|
+
this.creationDate = config.creationDate || new Date();
|
|
7886
|
+
this.paymentInformationIdBase = sanitize(v4(), 35);
|
|
7887
|
+
this.totalTransactionCount = this.countAllTransactions();
|
|
7888
|
+
this.formattedPaymentSum = this.sumAllPayments();
|
|
7889
|
+
this.validate();
|
|
7890
|
+
}
|
|
7891
|
+
/**
|
|
7892
|
+
* Counts the total number of transactions across all payment instruction groups.
|
|
7893
|
+
* @private
|
|
7894
|
+
* @returns {number} The total count of all transactions.
|
|
7895
|
+
*/
|
|
7896
|
+
countAllTransactions() {
|
|
7897
|
+
return this.paymentInstructions.reduce((total, group) => {
|
|
7898
|
+
return total + group.payments.length;
|
|
7899
|
+
}, 0);
|
|
7900
|
+
}
|
|
7901
|
+
/**
|
|
7902
|
+
* Calculates the sum of all payment instructions across all groups.
|
|
7903
|
+
* @private
|
|
7904
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
7905
|
+
*/
|
|
7906
|
+
sumAllPayments() {
|
|
7907
|
+
let totalAmount = 0;
|
|
7908
|
+
let currency = null;
|
|
7909
|
+
for (const group of this.paymentInstructions) {
|
|
7910
|
+
for (const payment of group.payments) {
|
|
7911
|
+
if (currency === null) {
|
|
7912
|
+
currency = payment.currency;
|
|
7913
|
+
}
|
|
7914
|
+
totalAmount += payment.amount;
|
|
7915
|
+
}
|
|
7916
|
+
}
|
|
7917
|
+
if (currency === null) {
|
|
7918
|
+
throw new Error('No payments found');
|
|
7919
|
+
}
|
|
7920
|
+
return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
|
|
7921
|
+
}
|
|
7922
|
+
/**
|
|
7923
|
+
* Calculates the sum of payment instructions for a single group.
|
|
7924
|
+
* @private
|
|
7925
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
7926
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
7927
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
7928
|
+
*/
|
|
7929
|
+
sumPaymentInstructions(payments) {
|
|
7930
|
+
this.validateGroupInstructionsHaveSameCurrency(payments);
|
|
7931
|
+
const instructionDineros = payments.map(instruction => Dinero({ amount: instruction.amount, currency: instruction.currency }));
|
|
7932
|
+
return instructionDineros.reduce((acc, next) => {
|
|
7933
|
+
return acc.add(next);
|
|
7934
|
+
}, Dinero({ amount: 0, currency: payments[0].currency })).toFormat('0.00');
|
|
7935
|
+
}
|
|
7936
|
+
/**
|
|
7937
|
+
* Validates the payment initiation data according to SEPA requirements.
|
|
7938
|
+
* @private
|
|
7939
|
+
* @throws {Error} If messageId exceeds 35 characters.
|
|
7940
|
+
* @throws {Error} If any group's payment instructions have different currencies.
|
|
7941
|
+
*/
|
|
7942
|
+
validate() {
|
|
7943
|
+
if (this.messageId.length > 35) {
|
|
7944
|
+
throw new Error('messageId must not exceed 35 characters');
|
|
7945
|
+
}
|
|
7946
|
+
// Validate each group has same currency within its payments
|
|
7947
|
+
for (const group of this.paymentInstructions) {
|
|
7948
|
+
this.validateGroupInstructionsHaveSameCurrency(group.payments);
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7951
|
+
/**
|
|
7952
|
+
* Validates that all payment instructions in a group have the same currency.
|
|
7953
|
+
* @private
|
|
7954
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
7955
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
7956
|
+
*/
|
|
7957
|
+
validateGroupInstructionsHaveSameCurrency(payments) {
|
|
7958
|
+
if (!payments.every((i) => { return i.currency === payments[0].currency; })) {
|
|
7959
|
+
throw new Error("In order to calculate the payment instructions sum, all payment instruction currencies within a group must be the same.");
|
|
7960
|
+
}
|
|
7961
|
+
}
|
|
7962
|
+
/**
|
|
7963
|
+
* Generates payment information for a single SEPA credit transfer instruction.
|
|
7964
|
+
* @param {SEPACreditPaymentInstruction} instruction - The payment instruction.
|
|
7965
|
+
* @returns {Object} The payment information object formatted according to SEPA specifications.
|
|
7966
|
+
*/
|
|
7967
|
+
creditTransfer(instruction) {
|
|
7968
|
+
const paymentInstructionId = sanitize(instruction.id || v4(), 35);
|
|
7969
|
+
const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
|
|
7970
|
+
const dinero = Dinero({ amount: instruction.amount, currency: instruction.currency });
|
|
7971
|
+
return {
|
|
7972
|
+
PmtId: {
|
|
7973
|
+
InstrId: paymentInstructionId,
|
|
7974
|
+
EndToEndId: endToEndId,
|
|
7975
|
+
},
|
|
7976
|
+
Amt: {
|
|
7977
|
+
InstdAmt: {
|
|
7978
|
+
'#': dinero.toFormat('0.00'),
|
|
7979
|
+
'@Ccy': instruction.currency,
|
|
7980
|
+
},
|
|
7981
|
+
},
|
|
7982
|
+
...(instruction.creditor.agent && { CdtrAgt: this.agent(instruction.creditor.agent) }),
|
|
7983
|
+
Cdtr: this.party(instruction.creditor),
|
|
7984
|
+
CdtrAcct: {
|
|
7985
|
+
Id: { IBAN: instruction.creditor.account.iban },
|
|
7986
|
+
Ccy: instruction.currency,
|
|
7987
|
+
},
|
|
7988
|
+
RmtInf: instruction.remittanceInformation ? {
|
|
7989
|
+
Ustrd: instruction.remittanceInformation,
|
|
7990
|
+
} : undefined,
|
|
7991
|
+
};
|
|
7992
|
+
}
|
|
7993
|
+
/**
|
|
7994
|
+
* Serializes the SEPA multi credit transfer initiation to an XML string.
|
|
7995
|
+
* @returns {string} The XML representation of the SEPA multi credit transfer initiation.
|
|
7996
|
+
*/
|
|
7997
|
+
serialize() {
|
|
7998
|
+
const builder = PaymentInitiation.getBuilder();
|
|
7999
|
+
// Generate multiple PmtInf entries, one per payment instruction group
|
|
8000
|
+
const paymentInfoEntries = this.paymentInstructions.map((group, index) => {
|
|
8001
|
+
const groupSum = this.sumPaymentInstructions(group.payments);
|
|
8002
|
+
const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${index + 1}`, 35);
|
|
8003
|
+
return {
|
|
8004
|
+
PmtInfId: pmtInfId,
|
|
8005
|
+
PmtMtd: 'TRF',
|
|
8006
|
+
NbOfTxs: group.payments.length.toString(),
|
|
8007
|
+
CtrlSum: groupSum,
|
|
8008
|
+
PmtTpInf: {
|
|
8009
|
+
SvcLvl: { Cd: 'SEPA' },
|
|
8010
|
+
...(group.categoryPurpose && {
|
|
8011
|
+
CtgyPurp: { Cd: group.categoryPurpose }
|
|
8012
|
+
}),
|
|
8013
|
+
},
|
|
8014
|
+
ReqdExctnDt: this.creationDate.toISOString().split('T')[0],
|
|
8015
|
+
Dbtr: this.party(group.initiatingParty),
|
|
8016
|
+
DbtrAcct: this.account(group.initiatingParty.account),
|
|
8017
|
+
DbtrAgt: this.agent(group.initiatingParty.agent),
|
|
8018
|
+
ChrgBr: 'SLEV',
|
|
8019
|
+
CdtTrfTxInf: group.payments.map(p => this.creditTransfer(p)),
|
|
8020
|
+
};
|
|
8021
|
+
});
|
|
8022
|
+
const xml = {
|
|
8023
|
+
'?xml': {
|
|
8024
|
+
'@version': '1.0',
|
|
8025
|
+
'@encoding': 'UTF-8'
|
|
8026
|
+
},
|
|
8027
|
+
Document: {
|
|
8028
|
+
'@xmlns': 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03',
|
|
8029
|
+
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
8030
|
+
CstmrCdtTrfInitn: {
|
|
8031
|
+
GrpHdr: {
|
|
8032
|
+
MsgId: this.messageId,
|
|
8033
|
+
CreDtTm: this.creationDate.toISOString(),
|
|
8034
|
+
NbOfTxs: this.totalTransactionCount.toString(),
|
|
8035
|
+
CtrlSum: this.formattedPaymentSum,
|
|
8036
|
+
InitgPty: {
|
|
8037
|
+
Nm: this.initiatingParty.name,
|
|
8038
|
+
Id: {
|
|
8039
|
+
OrgId: {
|
|
8040
|
+
Othr: {
|
|
8041
|
+
Id: this.initiatingParty.id,
|
|
8042
|
+
},
|
|
8043
|
+
},
|
|
8044
|
+
},
|
|
8045
|
+
},
|
|
8046
|
+
},
|
|
8047
|
+
PmtInf: paymentInfoEntries,
|
|
8048
|
+
}
|
|
8049
|
+
},
|
|
8050
|
+
};
|
|
8051
|
+
return builder.build(xml);
|
|
8052
|
+
}
|
|
8053
|
+
/**
|
|
8054
|
+
* Parses an XML string and creates a SEPAMultiCreditPaymentInitiation instance.
|
|
8055
|
+
* Supports multiple PmtInf blocks in the XML document.
|
|
8056
|
+
* @param {string} rawXml - The XML string to parse.
|
|
8057
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new instance created from the XML data.
|
|
8058
|
+
* @throws {InvalidXmlError} If the XML format is invalid.
|
|
8059
|
+
* @throws {InvalidXmlNamespaceError} If the namespace is not pain.001.001.03.
|
|
8060
|
+
*/
|
|
8061
|
+
static fromXML(rawXml) {
|
|
8062
|
+
const parser = new fxp.XMLParser({ ignoreAttributes: false });
|
|
8063
|
+
const xml = parser.parse(rawXml);
|
|
8064
|
+
// Validate XML structure
|
|
8065
|
+
if (!xml.Document) {
|
|
8066
|
+
throw new InvalidXmlError("Invalid XML format");
|
|
8067
|
+
}
|
|
8068
|
+
// Validate namespace
|
|
8069
|
+
const namespace = (xml.Document['@_xmlns'] || xml.Document['@_Xmlns']);
|
|
8070
|
+
if (!namespace.startsWith('urn:iso:std:iso:20022:tech:xsd:pain.001.001.03')) {
|
|
8071
|
+
throw new InvalidXmlNamespaceError('Invalid PAIN.001 namespace');
|
|
8072
|
+
}
|
|
8073
|
+
// Extract GrpHdr data
|
|
8074
|
+
const messageId = xml.Document.CstmrCdtTrfInitn.GrpHdr.MsgId;
|
|
8075
|
+
const creationDate = new Date(xml.Document.CstmrCdtTrfInitn.GrpHdr.CreDtTm);
|
|
8076
|
+
// Extract top-level initiating party from GrpHdr
|
|
8077
|
+
const topLevelInitiatingParty = {
|
|
8078
|
+
name: xml.Document.CstmrCdtTrfInitn.GrpHdr.InitgPty.Nm,
|
|
8079
|
+
id: xml.Document.CstmrCdtTrfInitn.GrpHdr.InitgPty.Id?.OrgId?.Othr?.Id,
|
|
8080
|
+
};
|
|
8081
|
+
// Normalize PmtInf to array (handle both single object and array cases)
|
|
8082
|
+
const rawPmtInf = Array.isArray(xml.Document.CstmrCdtTrfInitn.PmtInf)
|
|
8083
|
+
? xml.Document.CstmrCdtTrfInitn.PmtInf
|
|
8084
|
+
: [xml.Document.CstmrCdtTrfInitn.PmtInf];
|
|
8085
|
+
// Map each PmtInf to SEPAMultiCreditPaymentInstructionGroup
|
|
8086
|
+
const paymentInstructions = rawPmtInf.map((pmtInf) => {
|
|
8087
|
+
// Extract debtor info as the group's initiating party
|
|
8088
|
+
const groupInitiatingParty = {
|
|
8089
|
+
name: pmtInf.Dbtr.Nm,
|
|
8090
|
+
id: pmtInf.Dbtr.Id?.OrgId?.Othr?.Id,
|
|
8091
|
+
agent: parseAgent(pmtInf.DbtrAgt),
|
|
8092
|
+
account: parseAccount(pmtInf.DbtrAcct),
|
|
8093
|
+
};
|
|
8094
|
+
// Extract optional category purpose
|
|
8095
|
+
const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
|
|
8096
|
+
// Normalize CdtTrfTxInf to array
|
|
8097
|
+
const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
|
|
8098
|
+
? pmtInf.CdtTrfTxInf
|
|
8099
|
+
: [pmtInf.CdtTrfTxInf];
|
|
8100
|
+
// Parse each CdtTrfTxInf to SEPACreditPaymentInstruction
|
|
8101
|
+
const payments = rawInstructions.map((inst) => {
|
|
8102
|
+
const currency = inst.Amt.InstdAmt['@_Ccy'];
|
|
8103
|
+
const amount = parseAmountToMinorUnits(Number(inst.Amt.InstdAmt['#text']), currency);
|
|
8104
|
+
const rawPostalAddress = inst.Cdtr.PstlAdr;
|
|
8105
|
+
return {
|
|
8106
|
+
...(inst.PmtId.InstrId && { id: inst.PmtId.InstrId.toString() }),
|
|
8107
|
+
...(inst.PmtId.EndToEndId && { endToEndId: inst.PmtId.EndToEndId.toString() }),
|
|
8108
|
+
type: 'sepa',
|
|
8109
|
+
direction: 'credit',
|
|
8110
|
+
amount: amount,
|
|
8111
|
+
currency: currency,
|
|
8112
|
+
creditor: {
|
|
8113
|
+
name: inst.Cdtr?.Nm,
|
|
8114
|
+
agent: parseAgent(inst.CdtrAgt),
|
|
8115
|
+
account: parseAccount(inst.CdtrAcct),
|
|
8116
|
+
...((rawPostalAddress && (rawPostalAddress.StrtNm || rawPostalAddress.BldgNb || rawPostalAddress.PstCd || rawPostalAddress.TwnNm || rawPostalAddress.Ctry)) ? {
|
|
8117
|
+
address: {
|
|
8118
|
+
...(rawPostalAddress.StrtNm && { streetName: rawPostalAddress.StrtNm.toString() }),
|
|
8119
|
+
...(rawPostalAddress.BldgNb && { buildingNumber: rawPostalAddress.BldgNb.toString() }),
|
|
8120
|
+
...(rawPostalAddress.TwnNm && { townName: rawPostalAddress.TwnNm.toString() }),
|
|
8121
|
+
...(rawPostalAddress.CtrySubDvsn && { countrySubDivision: rawPostalAddress.CtrySubDvsn.toString() }),
|
|
8122
|
+
...(rawPostalAddress.PstCd && { postalCode: rawPostalAddress.PstCd.toString() }),
|
|
8123
|
+
...(rawPostalAddress.Ctry && { country: rawPostalAddress.Ctry }),
|
|
8124
|
+
}
|
|
8125
|
+
} : {}),
|
|
8126
|
+
},
|
|
8127
|
+
...(inst.RmtInf?.Ustrd && { remittanceInformation: inst.RmtInf.Ustrd.toString() })
|
|
8128
|
+
};
|
|
8129
|
+
});
|
|
8130
|
+
return {
|
|
8131
|
+
initiatingParty: groupInitiatingParty,
|
|
8132
|
+
payments: payments,
|
|
8133
|
+
...(categoryPurpose && { categoryPurpose }),
|
|
8134
|
+
};
|
|
8135
|
+
});
|
|
8136
|
+
// Return new instance
|
|
8137
|
+
return new SEPAMultiCreditPaymentInitiation({
|
|
8138
|
+
messageId: messageId,
|
|
8139
|
+
creationDate: creationDate,
|
|
8140
|
+
initiatingParty: topLevelInitiatingParty,
|
|
8141
|
+
paymentInstructions: paymentInstructions,
|
|
8142
|
+
});
|
|
8143
|
+
}
|
|
8144
|
+
}
|
|
8145
|
+
|
|
7843
8146
|
/**
|
|
7844
8147
|
* Represents a RTP Credit Payment Initiation.
|
|
7845
8148
|
* This class handles the creation and serialization of RTP credit transfer messages
|
|
@@ -9567,6 +9870,45 @@ class ISO20022 {
|
|
|
9567
9870
|
creationDate: config.creationDate,
|
|
9568
9871
|
});
|
|
9569
9872
|
}
|
|
9873
|
+
/**
|
|
9874
|
+
* Creates a SEPA Multi Credit Payment Initiation message with multiple payment information blocks.
|
|
9875
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - Configuration containing payment instruction groups and optional parameters.
|
|
9876
|
+
* @example
|
|
9877
|
+
* const payment = iso20022.createSEPAMultiCreditPaymentInitiation({
|
|
9878
|
+
* paymentInstructions: [
|
|
9879
|
+
* {
|
|
9880
|
+
* initiatingParty: debtor1,
|
|
9881
|
+
* payments: [
|
|
9882
|
+
* {
|
|
9883
|
+
* type: 'sepa',
|
|
9884
|
+
* direction: 'credit',
|
|
9885
|
+
* amount: 1000, // €10.00 Euros
|
|
9886
|
+
* currency: 'EUR',
|
|
9887
|
+
* creditor: {
|
|
9888
|
+
* name: 'Hans Schneider',
|
|
9889
|
+
* account: {
|
|
9890
|
+
* iban: 'DE1234567890123456',
|
|
9891
|
+
* },
|
|
9892
|
+
* },
|
|
9893
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
9894
|
+
* },
|
|
9895
|
+
* ],
|
|
9896
|
+
* categoryPurpose: 'SALA', // Optional
|
|
9897
|
+
* },
|
|
9898
|
+
* ],
|
|
9899
|
+
* messageId: 'SEPA-MULTI-MSG-001', // Optional
|
|
9900
|
+
* creationDate: new Date('2025-03-01'), // Optional
|
|
9901
|
+
* });
|
|
9902
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new SEPA Multi Credit Payment Initiation object.
|
|
9903
|
+
*/
|
|
9904
|
+
createSEPAMultiCreditPaymentInitiation(config) {
|
|
9905
|
+
return new SEPAMultiCreditPaymentInitiation({
|
|
9906
|
+
initiatingParty: this.initiatingParty,
|
|
9907
|
+
paymentInstructions: config.paymentInstructions,
|
|
9908
|
+
messageId: config.messageId,
|
|
9909
|
+
creationDate: config.creationDate,
|
|
9910
|
+
});
|
|
9911
|
+
}
|
|
9570
9912
|
/**
|
|
9571
9913
|
* Creates a RTP Credit Payment Initiation message.
|
|
9572
9914
|
* @param {RTPCreditPaymentInitiationConfig} config - Configuration containing payment instructions and optional parameters.
|
|
@@ -10036,4 +10378,5 @@ exports.PaymentStatusCode = PaymentStatusCode;
|
|
|
10036
10378
|
exports.PaymentStatusReport = PaymentStatusReport;
|
|
10037
10379
|
exports.RTPCreditPaymentInitiation = RTPCreditPaymentInitiation;
|
|
10038
10380
|
exports.SEPACreditPaymentInitiation = SEPACreditPaymentInitiation;
|
|
10381
|
+
exports.SEPAMultiCreditPaymentInitiation = SEPAMultiCreditPaymentInitiation;
|
|
10039
10382
|
exports.SWIFTCreditPaymentInitiation = SWIFTCreditPaymentInitiation;
|
package/dist/index.mjs
CHANGED
|
@@ -7838,6 +7838,309 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
|
|
|
7838
7838
|
}
|
|
7839
7839
|
}
|
|
7840
7840
|
|
|
7841
|
+
/**
|
|
7842
|
+
* Represents a SEPA Multi Credit Payment Initiation.
|
|
7843
|
+
* This class handles the creation and serialization of SEPA credit transfer messages
|
|
7844
|
+
* with multiple payment information blocks (multiple debtors) according to the ISO20022 standard.
|
|
7845
|
+
* @class
|
|
7846
|
+
* @extends PaymentInitiation
|
|
7847
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration for the SEPA Multi Credit Payment Initiation message.
|
|
7848
|
+
* @example
|
|
7849
|
+
* ```typescript
|
|
7850
|
+
* // Creating a SEPA multi-payment message
|
|
7851
|
+
* const payment = new SEPAMultiCreditPaymentInitiation({
|
|
7852
|
+
* initiatingParty: { name: 'Company Ltd', id: '12345' },
|
|
7853
|
+
* paymentInstructions: [
|
|
7854
|
+
* {
|
|
7855
|
+
* initiatingParty: debtor1,
|
|
7856
|
+
* payments: [payment1, payment2]
|
|
7857
|
+
* },
|
|
7858
|
+
* {
|
|
7859
|
+
* initiatingParty: debtor2,
|
|
7860
|
+
* payments: [payment3]
|
|
7861
|
+
* }
|
|
7862
|
+
* ]
|
|
7863
|
+
* });
|
|
7864
|
+
* ```
|
|
7865
|
+
*/
|
|
7866
|
+
class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
|
|
7867
|
+
initiatingParty;
|
|
7868
|
+
messageId;
|
|
7869
|
+
creationDate;
|
|
7870
|
+
paymentInstructions;
|
|
7871
|
+
paymentInformationIdBase;
|
|
7872
|
+
formattedPaymentSum;
|
|
7873
|
+
totalTransactionCount;
|
|
7874
|
+
/**
|
|
7875
|
+
* Creates an instance of SEPAMultiCreditPaymentInitiation.
|
|
7876
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration object for the SEPA multi credit transfer.
|
|
7877
|
+
*/
|
|
7878
|
+
constructor(config) {
|
|
7879
|
+
super({ type: "sepa" });
|
|
7880
|
+
this.initiatingParty = config.initiatingParty;
|
|
7881
|
+
this.paymentInstructions = config.paymentInstructions;
|
|
7882
|
+
this.messageId = config.messageId || v4().replace(/-/g, '');
|
|
7883
|
+
this.creationDate = config.creationDate || new Date();
|
|
7884
|
+
this.paymentInformationIdBase = sanitize(v4(), 35);
|
|
7885
|
+
this.totalTransactionCount = this.countAllTransactions();
|
|
7886
|
+
this.formattedPaymentSum = this.sumAllPayments();
|
|
7887
|
+
this.validate();
|
|
7888
|
+
}
|
|
7889
|
+
/**
|
|
7890
|
+
* Counts the total number of transactions across all payment instruction groups.
|
|
7891
|
+
* @private
|
|
7892
|
+
* @returns {number} The total count of all transactions.
|
|
7893
|
+
*/
|
|
7894
|
+
countAllTransactions() {
|
|
7895
|
+
return this.paymentInstructions.reduce((total, group) => {
|
|
7896
|
+
return total + group.payments.length;
|
|
7897
|
+
}, 0);
|
|
7898
|
+
}
|
|
7899
|
+
/**
|
|
7900
|
+
* Calculates the sum of all payment instructions across all groups.
|
|
7901
|
+
* @private
|
|
7902
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
7903
|
+
*/
|
|
7904
|
+
sumAllPayments() {
|
|
7905
|
+
let totalAmount = 0;
|
|
7906
|
+
let currency = null;
|
|
7907
|
+
for (const group of this.paymentInstructions) {
|
|
7908
|
+
for (const payment of group.payments) {
|
|
7909
|
+
if (currency === null) {
|
|
7910
|
+
currency = payment.currency;
|
|
7911
|
+
}
|
|
7912
|
+
totalAmount += payment.amount;
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
if (currency === null) {
|
|
7916
|
+
throw new Error('No payments found');
|
|
7917
|
+
}
|
|
7918
|
+
return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
|
|
7919
|
+
}
|
|
7920
|
+
/**
|
|
7921
|
+
* Calculates the sum of payment instructions for a single group.
|
|
7922
|
+
* @private
|
|
7923
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
7924
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
7925
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
7926
|
+
*/
|
|
7927
|
+
sumPaymentInstructions(payments) {
|
|
7928
|
+
this.validateGroupInstructionsHaveSameCurrency(payments);
|
|
7929
|
+
const instructionDineros = payments.map(instruction => Dinero({ amount: instruction.amount, currency: instruction.currency }));
|
|
7930
|
+
return instructionDineros.reduce((acc, next) => {
|
|
7931
|
+
return acc.add(next);
|
|
7932
|
+
}, Dinero({ amount: 0, currency: payments[0].currency })).toFormat('0.00');
|
|
7933
|
+
}
|
|
7934
|
+
/**
|
|
7935
|
+
* Validates the payment initiation data according to SEPA requirements.
|
|
7936
|
+
* @private
|
|
7937
|
+
* @throws {Error} If messageId exceeds 35 characters.
|
|
7938
|
+
* @throws {Error} If any group's payment instructions have different currencies.
|
|
7939
|
+
*/
|
|
7940
|
+
validate() {
|
|
7941
|
+
if (this.messageId.length > 35) {
|
|
7942
|
+
throw new Error('messageId must not exceed 35 characters');
|
|
7943
|
+
}
|
|
7944
|
+
// Validate each group has same currency within its payments
|
|
7945
|
+
for (const group of this.paymentInstructions) {
|
|
7946
|
+
this.validateGroupInstructionsHaveSameCurrency(group.payments);
|
|
7947
|
+
}
|
|
7948
|
+
}
|
|
7949
|
+
/**
|
|
7950
|
+
* Validates that all payment instructions in a group have the same currency.
|
|
7951
|
+
* @private
|
|
7952
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
7953
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
7954
|
+
*/
|
|
7955
|
+
validateGroupInstructionsHaveSameCurrency(payments) {
|
|
7956
|
+
if (!payments.every((i) => { return i.currency === payments[0].currency; })) {
|
|
7957
|
+
throw new Error("In order to calculate the payment instructions sum, all payment instruction currencies within a group must be the same.");
|
|
7958
|
+
}
|
|
7959
|
+
}
|
|
7960
|
+
/**
|
|
7961
|
+
* Generates payment information for a single SEPA credit transfer instruction.
|
|
7962
|
+
* @param {SEPACreditPaymentInstruction} instruction - The payment instruction.
|
|
7963
|
+
* @returns {Object} The payment information object formatted according to SEPA specifications.
|
|
7964
|
+
*/
|
|
7965
|
+
creditTransfer(instruction) {
|
|
7966
|
+
const paymentInstructionId = sanitize(instruction.id || v4(), 35);
|
|
7967
|
+
const endToEndId = sanitize(instruction.endToEndId || instruction.id || v4(), 35);
|
|
7968
|
+
const dinero = Dinero({ amount: instruction.amount, currency: instruction.currency });
|
|
7969
|
+
return {
|
|
7970
|
+
PmtId: {
|
|
7971
|
+
InstrId: paymentInstructionId,
|
|
7972
|
+
EndToEndId: endToEndId,
|
|
7973
|
+
},
|
|
7974
|
+
Amt: {
|
|
7975
|
+
InstdAmt: {
|
|
7976
|
+
'#': dinero.toFormat('0.00'),
|
|
7977
|
+
'@Ccy': instruction.currency,
|
|
7978
|
+
},
|
|
7979
|
+
},
|
|
7980
|
+
...(instruction.creditor.agent && { CdtrAgt: this.agent(instruction.creditor.agent) }),
|
|
7981
|
+
Cdtr: this.party(instruction.creditor),
|
|
7982
|
+
CdtrAcct: {
|
|
7983
|
+
Id: { IBAN: instruction.creditor.account.iban },
|
|
7984
|
+
Ccy: instruction.currency,
|
|
7985
|
+
},
|
|
7986
|
+
RmtInf: instruction.remittanceInformation ? {
|
|
7987
|
+
Ustrd: instruction.remittanceInformation,
|
|
7988
|
+
} : undefined,
|
|
7989
|
+
};
|
|
7990
|
+
}
|
|
7991
|
+
/**
|
|
7992
|
+
* Serializes the SEPA multi credit transfer initiation to an XML string.
|
|
7993
|
+
* @returns {string} The XML representation of the SEPA multi credit transfer initiation.
|
|
7994
|
+
*/
|
|
7995
|
+
serialize() {
|
|
7996
|
+
const builder = PaymentInitiation.getBuilder();
|
|
7997
|
+
// Generate multiple PmtInf entries, one per payment instruction group
|
|
7998
|
+
const paymentInfoEntries = this.paymentInstructions.map((group, index) => {
|
|
7999
|
+
const groupSum = this.sumPaymentInstructions(group.payments);
|
|
8000
|
+
const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${index + 1}`, 35);
|
|
8001
|
+
return {
|
|
8002
|
+
PmtInfId: pmtInfId,
|
|
8003
|
+
PmtMtd: 'TRF',
|
|
8004
|
+
NbOfTxs: group.payments.length.toString(),
|
|
8005
|
+
CtrlSum: groupSum,
|
|
8006
|
+
PmtTpInf: {
|
|
8007
|
+
SvcLvl: { Cd: 'SEPA' },
|
|
8008
|
+
...(group.categoryPurpose && {
|
|
8009
|
+
CtgyPurp: { Cd: group.categoryPurpose }
|
|
8010
|
+
}),
|
|
8011
|
+
},
|
|
8012
|
+
ReqdExctnDt: this.creationDate.toISOString().split('T')[0],
|
|
8013
|
+
Dbtr: this.party(group.initiatingParty),
|
|
8014
|
+
DbtrAcct: this.account(group.initiatingParty.account),
|
|
8015
|
+
DbtrAgt: this.agent(group.initiatingParty.agent),
|
|
8016
|
+
ChrgBr: 'SLEV',
|
|
8017
|
+
CdtTrfTxInf: group.payments.map(p => this.creditTransfer(p)),
|
|
8018
|
+
};
|
|
8019
|
+
});
|
|
8020
|
+
const xml = {
|
|
8021
|
+
'?xml': {
|
|
8022
|
+
'@version': '1.0',
|
|
8023
|
+
'@encoding': 'UTF-8'
|
|
8024
|
+
},
|
|
8025
|
+
Document: {
|
|
8026
|
+
'@xmlns': 'urn:iso:std:iso:20022:tech:xsd:pain.001.001.03',
|
|
8027
|
+
'@xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
|
|
8028
|
+
CstmrCdtTrfInitn: {
|
|
8029
|
+
GrpHdr: {
|
|
8030
|
+
MsgId: this.messageId,
|
|
8031
|
+
CreDtTm: this.creationDate.toISOString(),
|
|
8032
|
+
NbOfTxs: this.totalTransactionCount.toString(),
|
|
8033
|
+
CtrlSum: this.formattedPaymentSum,
|
|
8034
|
+
InitgPty: {
|
|
8035
|
+
Nm: this.initiatingParty.name,
|
|
8036
|
+
Id: {
|
|
8037
|
+
OrgId: {
|
|
8038
|
+
Othr: {
|
|
8039
|
+
Id: this.initiatingParty.id,
|
|
8040
|
+
},
|
|
8041
|
+
},
|
|
8042
|
+
},
|
|
8043
|
+
},
|
|
8044
|
+
},
|
|
8045
|
+
PmtInf: paymentInfoEntries,
|
|
8046
|
+
}
|
|
8047
|
+
},
|
|
8048
|
+
};
|
|
8049
|
+
return builder.build(xml);
|
|
8050
|
+
}
|
|
8051
|
+
/**
|
|
8052
|
+
* Parses an XML string and creates a SEPAMultiCreditPaymentInitiation instance.
|
|
8053
|
+
* Supports multiple PmtInf blocks in the XML document.
|
|
8054
|
+
* @param {string} rawXml - The XML string to parse.
|
|
8055
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new instance created from the XML data.
|
|
8056
|
+
* @throws {InvalidXmlError} If the XML format is invalid.
|
|
8057
|
+
* @throws {InvalidXmlNamespaceError} If the namespace is not pain.001.001.03.
|
|
8058
|
+
*/
|
|
8059
|
+
static fromXML(rawXml) {
|
|
8060
|
+
const parser = new fxp.XMLParser({ ignoreAttributes: false });
|
|
8061
|
+
const xml = parser.parse(rawXml);
|
|
8062
|
+
// Validate XML structure
|
|
8063
|
+
if (!xml.Document) {
|
|
8064
|
+
throw new InvalidXmlError("Invalid XML format");
|
|
8065
|
+
}
|
|
8066
|
+
// Validate namespace
|
|
8067
|
+
const namespace = (xml.Document['@_xmlns'] || xml.Document['@_Xmlns']);
|
|
8068
|
+
if (!namespace.startsWith('urn:iso:std:iso:20022:tech:xsd:pain.001.001.03')) {
|
|
8069
|
+
throw new InvalidXmlNamespaceError('Invalid PAIN.001 namespace');
|
|
8070
|
+
}
|
|
8071
|
+
// Extract GrpHdr data
|
|
8072
|
+
const messageId = xml.Document.CstmrCdtTrfInitn.GrpHdr.MsgId;
|
|
8073
|
+
const creationDate = new Date(xml.Document.CstmrCdtTrfInitn.GrpHdr.CreDtTm);
|
|
8074
|
+
// Extract top-level initiating party from GrpHdr
|
|
8075
|
+
const topLevelInitiatingParty = {
|
|
8076
|
+
name: xml.Document.CstmrCdtTrfInitn.GrpHdr.InitgPty.Nm,
|
|
8077
|
+
id: xml.Document.CstmrCdtTrfInitn.GrpHdr.InitgPty.Id?.OrgId?.Othr?.Id,
|
|
8078
|
+
};
|
|
8079
|
+
// Normalize PmtInf to array (handle both single object and array cases)
|
|
8080
|
+
const rawPmtInf = Array.isArray(xml.Document.CstmrCdtTrfInitn.PmtInf)
|
|
8081
|
+
? xml.Document.CstmrCdtTrfInitn.PmtInf
|
|
8082
|
+
: [xml.Document.CstmrCdtTrfInitn.PmtInf];
|
|
8083
|
+
// Map each PmtInf to SEPAMultiCreditPaymentInstructionGroup
|
|
8084
|
+
const paymentInstructions = rawPmtInf.map((pmtInf) => {
|
|
8085
|
+
// Extract debtor info as the group's initiating party
|
|
8086
|
+
const groupInitiatingParty = {
|
|
8087
|
+
name: pmtInf.Dbtr.Nm,
|
|
8088
|
+
id: pmtInf.Dbtr.Id?.OrgId?.Othr?.Id,
|
|
8089
|
+
agent: parseAgent(pmtInf.DbtrAgt),
|
|
8090
|
+
account: parseAccount(pmtInf.DbtrAcct),
|
|
8091
|
+
};
|
|
8092
|
+
// Extract optional category purpose
|
|
8093
|
+
const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
|
|
8094
|
+
// Normalize CdtTrfTxInf to array
|
|
8095
|
+
const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
|
|
8096
|
+
? pmtInf.CdtTrfTxInf
|
|
8097
|
+
: [pmtInf.CdtTrfTxInf];
|
|
8098
|
+
// Parse each CdtTrfTxInf to SEPACreditPaymentInstruction
|
|
8099
|
+
const payments = rawInstructions.map((inst) => {
|
|
8100
|
+
const currency = inst.Amt.InstdAmt['@_Ccy'];
|
|
8101
|
+
const amount = parseAmountToMinorUnits(Number(inst.Amt.InstdAmt['#text']), currency);
|
|
8102
|
+
const rawPostalAddress = inst.Cdtr.PstlAdr;
|
|
8103
|
+
return {
|
|
8104
|
+
...(inst.PmtId.InstrId && { id: inst.PmtId.InstrId.toString() }),
|
|
8105
|
+
...(inst.PmtId.EndToEndId && { endToEndId: inst.PmtId.EndToEndId.toString() }),
|
|
8106
|
+
type: 'sepa',
|
|
8107
|
+
direction: 'credit',
|
|
8108
|
+
amount: amount,
|
|
8109
|
+
currency: currency,
|
|
8110
|
+
creditor: {
|
|
8111
|
+
name: inst.Cdtr?.Nm,
|
|
8112
|
+
agent: parseAgent(inst.CdtrAgt),
|
|
8113
|
+
account: parseAccount(inst.CdtrAcct),
|
|
8114
|
+
...((rawPostalAddress && (rawPostalAddress.StrtNm || rawPostalAddress.BldgNb || rawPostalAddress.PstCd || rawPostalAddress.TwnNm || rawPostalAddress.Ctry)) ? {
|
|
8115
|
+
address: {
|
|
8116
|
+
...(rawPostalAddress.StrtNm && { streetName: rawPostalAddress.StrtNm.toString() }),
|
|
8117
|
+
...(rawPostalAddress.BldgNb && { buildingNumber: rawPostalAddress.BldgNb.toString() }),
|
|
8118
|
+
...(rawPostalAddress.TwnNm && { townName: rawPostalAddress.TwnNm.toString() }),
|
|
8119
|
+
...(rawPostalAddress.CtrySubDvsn && { countrySubDivision: rawPostalAddress.CtrySubDvsn.toString() }),
|
|
8120
|
+
...(rawPostalAddress.PstCd && { postalCode: rawPostalAddress.PstCd.toString() }),
|
|
8121
|
+
...(rawPostalAddress.Ctry && { country: rawPostalAddress.Ctry }),
|
|
8122
|
+
}
|
|
8123
|
+
} : {}),
|
|
8124
|
+
},
|
|
8125
|
+
...(inst.RmtInf?.Ustrd && { remittanceInformation: inst.RmtInf.Ustrd.toString() })
|
|
8126
|
+
};
|
|
8127
|
+
});
|
|
8128
|
+
return {
|
|
8129
|
+
initiatingParty: groupInitiatingParty,
|
|
8130
|
+
payments: payments,
|
|
8131
|
+
...(categoryPurpose && { categoryPurpose }),
|
|
8132
|
+
};
|
|
8133
|
+
});
|
|
8134
|
+
// Return new instance
|
|
8135
|
+
return new SEPAMultiCreditPaymentInitiation({
|
|
8136
|
+
messageId: messageId,
|
|
8137
|
+
creationDate: creationDate,
|
|
8138
|
+
initiatingParty: topLevelInitiatingParty,
|
|
8139
|
+
paymentInstructions: paymentInstructions,
|
|
8140
|
+
});
|
|
8141
|
+
}
|
|
8142
|
+
}
|
|
8143
|
+
|
|
7841
8144
|
/**
|
|
7842
8145
|
* Represents a RTP Credit Payment Initiation.
|
|
7843
8146
|
* This class handles the creation and serialization of RTP credit transfer messages
|
|
@@ -9565,6 +9868,45 @@ class ISO20022 {
|
|
|
9565
9868
|
creationDate: config.creationDate,
|
|
9566
9869
|
});
|
|
9567
9870
|
}
|
|
9871
|
+
/**
|
|
9872
|
+
* Creates a SEPA Multi Credit Payment Initiation message with multiple payment information blocks.
|
|
9873
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - Configuration containing payment instruction groups and optional parameters.
|
|
9874
|
+
* @example
|
|
9875
|
+
* const payment = iso20022.createSEPAMultiCreditPaymentInitiation({
|
|
9876
|
+
* paymentInstructions: [
|
|
9877
|
+
* {
|
|
9878
|
+
* initiatingParty: debtor1,
|
|
9879
|
+
* payments: [
|
|
9880
|
+
* {
|
|
9881
|
+
* type: 'sepa',
|
|
9882
|
+
* direction: 'credit',
|
|
9883
|
+
* amount: 1000, // €10.00 Euros
|
|
9884
|
+
* currency: 'EUR',
|
|
9885
|
+
* creditor: {
|
|
9886
|
+
* name: 'Hans Schneider',
|
|
9887
|
+
* account: {
|
|
9888
|
+
* iban: 'DE1234567890123456',
|
|
9889
|
+
* },
|
|
9890
|
+
* },
|
|
9891
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
9892
|
+
* },
|
|
9893
|
+
* ],
|
|
9894
|
+
* categoryPurpose: 'SALA', // Optional
|
|
9895
|
+
* },
|
|
9896
|
+
* ],
|
|
9897
|
+
* messageId: 'SEPA-MULTI-MSG-001', // Optional
|
|
9898
|
+
* creationDate: new Date('2025-03-01'), // Optional
|
|
9899
|
+
* });
|
|
9900
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new SEPA Multi Credit Payment Initiation object.
|
|
9901
|
+
*/
|
|
9902
|
+
createSEPAMultiCreditPaymentInitiation(config) {
|
|
9903
|
+
return new SEPAMultiCreditPaymentInitiation({
|
|
9904
|
+
initiatingParty: this.initiatingParty,
|
|
9905
|
+
paymentInstructions: config.paymentInstructions,
|
|
9906
|
+
messageId: config.messageId,
|
|
9907
|
+
creationDate: config.creationDate,
|
|
9908
|
+
});
|
|
9909
|
+
}
|
|
9568
9910
|
/**
|
|
9569
9911
|
* Creates a RTP Credit Payment Initiation message.
|
|
9570
9912
|
* @param {RTPCreditPaymentInitiationConfig} config - Configuration containing payment instructions and optional parameters.
|
|
@@ -10020,4 +10362,4 @@ class CashManagementEndOfDayReport {
|
|
|
10020
10362
|
}
|
|
10021
10363
|
registerISO20022Implementation(CashManagementEndOfDayReport);
|
|
10022
10364
|
|
|
10023
|
-
export { ACHCreditPaymentInitiation, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, BalanceTypeCode, BalanceTypeCodeDescriptionMap, CashManagementEndOfDayReport, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, SEPACreditPaymentInitiation, SWIFTCreditPaymentInitiation };
|
|
10365
|
+
export { ACHCreditPaymentInitiation, ACHLocalInstrumentCode, ACHLocalInstrumentCodeDescriptionMap, BalanceTypeCode, BalanceTypeCodeDescriptionMap, CashManagementEndOfDayReport, ISO20022, InvalidXmlError, InvalidXmlNamespaceError, Iso20022JsError, PaymentStatusCode, PaymentStatusReport, RTPCreditPaymentInitiation, SEPACreditPaymentInitiation, SEPAMultiCreditPaymentInitiation, SWIFTCreditPaymentInitiation };
|
package/dist/src/index.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export type { SWIFTCreditPaymentInitiationConfig } from './pain/001/swift-credit
|
|
|
48
48
|
export { SWIFTCreditPaymentInitiation } from './pain/001/swift-credit-payment-initiation';
|
|
49
49
|
export type { SEPACreditPaymentInitiationConfig } from './pain/001/sepa-credit-payment-initiation';
|
|
50
50
|
export { SEPACreditPaymentInitiation } from './pain/001/sepa-credit-payment-initiation';
|
|
51
|
+
export type { SEPAMultiCreditPaymentInitiationConfig, SEPAMultiCreditPaymentInstructionGroup } from './pain/001/sepa-multi-credit-payment-initiation';
|
|
52
|
+
export { SEPAMultiCreditPaymentInitiation } from './pain/001/sepa-multi-credit-payment-initiation';
|
|
51
53
|
export type { RTPCreditPaymentInitiationConfig } from './pain/001/rtp-credit-payment-initiation';
|
|
52
54
|
export { RTPCreditPaymentInitiation } from './pain/001/rtp-credit-payment-initiation';
|
|
53
55
|
export type { ACHCreditPaymentInitiationConfig } from './pain/001/ach-credit-payment-initiation';
|
package/dist/src/iso20022.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Party, SWIFTCreditPaymentInstruction, SEPACreditPaymentInstruction, RTPCreditPaymentInstruction, ACHCreditPaymentInstruction } from './lib/types.js';
|
|
2
2
|
import { SWIFTCreditPaymentInitiation } from './pain/001/swift-credit-payment-initiation';
|
|
3
3
|
import { SEPACreditPaymentInitiation } from './pain/001/sepa-credit-payment-initiation';
|
|
4
|
+
import { SEPAMultiCreditPaymentInitiation, SEPAMultiCreditPaymentInstructionGroup } from './pain/001/sepa-multi-credit-payment-initiation';
|
|
4
5
|
import { RTPCreditPaymentInitiation } from './pain/001/rtp-credit-payment-initiation';
|
|
5
6
|
import { ACHCreditPaymentInitiation } from './pain/001/ach-credit-payment-initiation';
|
|
6
7
|
import { GenericISO20022Message, ISO20022MessageTypeName } from './lib/interfaces';
|
|
@@ -130,6 +131,53 @@ export interface SEPACreditPaymentInitiationConfig {
|
|
|
130
131
|
*/
|
|
131
132
|
creationDate?: Date;
|
|
132
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Configuration interface for SEPA Multi Credit Payment Initiation.
|
|
136
|
+
* @interface SEPAMultiCreditPaymentInitiationConfig
|
|
137
|
+
* @example
|
|
138
|
+
* const config: SEPAMultiCreditPaymentInitiationConfig = {
|
|
139
|
+
* paymentInstructions: [
|
|
140
|
+
* {
|
|
141
|
+
* initiatingParty: debtor1,
|
|
142
|
+
* payments: [
|
|
143
|
+
* {
|
|
144
|
+
* type: 'sepa',
|
|
145
|
+
* direction: 'credit',
|
|
146
|
+
* amount: 1000, // €10.00 Euros
|
|
147
|
+
* currency: 'EUR',
|
|
148
|
+
* creditor: {
|
|
149
|
+
* name: 'Hans Schneider',
|
|
150
|
+
* account: {
|
|
151
|
+
* iban: 'DE1234567890123456',
|
|
152
|
+
* },
|
|
153
|
+
* },
|
|
154
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
155
|
+
* },
|
|
156
|
+
* ],
|
|
157
|
+
* categoryPurpose: 'SALA', // Optional
|
|
158
|
+
* },
|
|
159
|
+
* ],
|
|
160
|
+
* messageId: 'MSGID123', // Optional
|
|
161
|
+
* creationDate: new Date(), // Optional
|
|
162
|
+
* };
|
|
163
|
+
*/
|
|
164
|
+
export interface SEPAMultiCreditPaymentInitiationConfig {
|
|
165
|
+
/**
|
|
166
|
+
* An array of payment instruction groups, each with its own debtor.
|
|
167
|
+
* @type {AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>}
|
|
168
|
+
*/
|
|
169
|
+
paymentInstructions: AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>;
|
|
170
|
+
/**
|
|
171
|
+
* Optional unique identifier for the message. If not provided, a UUID will be generated.
|
|
172
|
+
* @type {string}
|
|
173
|
+
*/
|
|
174
|
+
messageId?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Optional creation date for the message. If not provided, current date will be used.
|
|
177
|
+
* @type {Date}
|
|
178
|
+
*/
|
|
179
|
+
creationDate?: Date;
|
|
180
|
+
}
|
|
133
181
|
/**
|
|
134
182
|
* Configuration interface for RTP Credit Payment Initiation.
|
|
135
183
|
* @interface RTPCreditPaymentInitiationConfig
|
|
@@ -311,6 +359,38 @@ declare class ISO20022 {
|
|
|
311
359
|
* @returns {SEPACreditPaymentInitiation} A new SEPA Credit Payment Initiation object.
|
|
312
360
|
*/
|
|
313
361
|
createSEPACreditPaymentInitiation(config: SEPACreditPaymentInitiationConfig): SEPACreditPaymentInitiation;
|
|
362
|
+
/**
|
|
363
|
+
* Creates a SEPA Multi Credit Payment Initiation message with multiple payment information blocks.
|
|
364
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - Configuration containing payment instruction groups and optional parameters.
|
|
365
|
+
* @example
|
|
366
|
+
* const payment = iso20022.createSEPAMultiCreditPaymentInitiation({
|
|
367
|
+
* paymentInstructions: [
|
|
368
|
+
* {
|
|
369
|
+
* initiatingParty: debtor1,
|
|
370
|
+
* payments: [
|
|
371
|
+
* {
|
|
372
|
+
* type: 'sepa',
|
|
373
|
+
* direction: 'credit',
|
|
374
|
+
* amount: 1000, // €10.00 Euros
|
|
375
|
+
* currency: 'EUR',
|
|
376
|
+
* creditor: {
|
|
377
|
+
* name: 'Hans Schneider',
|
|
378
|
+
* account: {
|
|
379
|
+
* iban: 'DE1234567890123456',
|
|
380
|
+
* },
|
|
381
|
+
* },
|
|
382
|
+
* remittanceInformation: 'Invoice payment #123',
|
|
383
|
+
* },
|
|
384
|
+
* ],
|
|
385
|
+
* categoryPurpose: 'SALA', // Optional
|
|
386
|
+
* },
|
|
387
|
+
* ],
|
|
388
|
+
* messageId: 'SEPA-MULTI-MSG-001', // Optional
|
|
389
|
+
* creationDate: new Date('2025-03-01'), // Optional
|
|
390
|
+
* });
|
|
391
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new SEPA Multi Credit Payment Initiation object.
|
|
392
|
+
*/
|
|
393
|
+
createSEPAMultiCreditPaymentInitiation(config: SEPAMultiCreditPaymentInitiationConfig): SEPAMultiCreditPaymentInitiation;
|
|
314
394
|
/**
|
|
315
395
|
* Creates a RTP Credit Payment Initiation message.
|
|
316
396
|
* @param {RTPCreditPaymentInitiationConfig} config - Configuration containing payment instructions and optional parameters.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { ExternalCategoryPurpose, Party, SEPACreditPaymentInstruction } from "../../lib/types";
|
|
2
|
+
import { PaymentInitiation } from './payment-initiation';
|
|
3
|
+
type AtLeastOne<T> = [T, ...T[]];
|
|
4
|
+
/**
|
|
5
|
+
* Represents a group of payment instructions for a single debtor (PmtInf block).
|
|
6
|
+
*
|
|
7
|
+
* @property {Party} initiatingParty - The party (debtor) for this specific payment information block.
|
|
8
|
+
* @property {AtLeastOne<SEPACreditPaymentInstruction>} payments - An array containing at least one payment instruction for this debtor.
|
|
9
|
+
* @property {ExternalCategoryPurpose} [categoryPurpose] - Optional category purpose code for this payment information block.
|
|
10
|
+
*/
|
|
11
|
+
export interface SEPAMultiCreditPaymentInstructionGroup {
|
|
12
|
+
/** The party (debtor) for this specific payment information block. */
|
|
13
|
+
initiatingParty: Party;
|
|
14
|
+
/** An array containing at least one payment instruction for this debtor. */
|
|
15
|
+
payments: AtLeastOne<SEPACreditPaymentInstruction>;
|
|
16
|
+
/** Optional category purpose code for this payment information block. */
|
|
17
|
+
categoryPurpose?: ExternalCategoryPurpose;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Configuration for SEPA Multi Credit Payment Initiation.
|
|
21
|
+
*
|
|
22
|
+
* @property {Party} initiatingParty - The top-level party initiating the message (used in GrpHdr).
|
|
23
|
+
* @property {AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>} paymentInstructions - An array containing at least one payment instruction group.
|
|
24
|
+
* @property {string} [messageId] - Optional unique identifier for the message. If not provided, a UUID will be generated.
|
|
25
|
+
* @property {Date} [creationDate] - Optional creation date for the message. If not provided, current date will be used.
|
|
26
|
+
*/
|
|
27
|
+
export interface SEPAMultiCreditPaymentInitiationConfig {
|
|
28
|
+
/** The top-level party initiating the message (used in GrpHdr). */
|
|
29
|
+
initiatingParty: Party;
|
|
30
|
+
/** An array containing at least one payment instruction group. */
|
|
31
|
+
paymentInstructions: AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>;
|
|
32
|
+
/** Optional unique identifier for the message. If not provided, a UUID will be generated. */
|
|
33
|
+
messageId?: string;
|
|
34
|
+
/** Optional creation date for the message. If not provided, current date will be used. */
|
|
35
|
+
creationDate?: Date;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Represents a SEPA Multi Credit Payment Initiation.
|
|
39
|
+
* This class handles the creation and serialization of SEPA credit transfer messages
|
|
40
|
+
* with multiple payment information blocks (multiple debtors) according to the ISO20022 standard.
|
|
41
|
+
* @class
|
|
42
|
+
* @extends PaymentInitiation
|
|
43
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration for the SEPA Multi Credit Payment Initiation message.
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Creating a SEPA multi-payment message
|
|
47
|
+
* const payment = new SEPAMultiCreditPaymentInitiation({
|
|
48
|
+
* initiatingParty: { name: 'Company Ltd', id: '12345' },
|
|
49
|
+
* paymentInstructions: [
|
|
50
|
+
* {
|
|
51
|
+
* initiatingParty: debtor1,
|
|
52
|
+
* payments: [payment1, payment2]
|
|
53
|
+
* },
|
|
54
|
+
* {
|
|
55
|
+
* initiatingParty: debtor2,
|
|
56
|
+
* payments: [payment3]
|
|
57
|
+
* }
|
|
58
|
+
* ]
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
|
|
63
|
+
initiatingParty: Party;
|
|
64
|
+
messageId: string;
|
|
65
|
+
creationDate: Date;
|
|
66
|
+
paymentInstructions: AtLeastOne<SEPAMultiCreditPaymentInstructionGroup>;
|
|
67
|
+
paymentInformationIdBase: string;
|
|
68
|
+
private formattedPaymentSum;
|
|
69
|
+
private totalTransactionCount;
|
|
70
|
+
/**
|
|
71
|
+
* Creates an instance of SEPAMultiCreditPaymentInitiation.
|
|
72
|
+
* @param {SEPAMultiCreditPaymentInitiationConfig} config - The configuration object for the SEPA multi credit transfer.
|
|
73
|
+
*/
|
|
74
|
+
constructor(config: SEPAMultiCreditPaymentInitiationConfig);
|
|
75
|
+
/**
|
|
76
|
+
* Counts the total number of transactions across all payment instruction groups.
|
|
77
|
+
* @private
|
|
78
|
+
* @returns {number} The total count of all transactions.
|
|
79
|
+
*/
|
|
80
|
+
private countAllTransactions;
|
|
81
|
+
/**
|
|
82
|
+
* Calculates the sum of all payment instructions across all groups.
|
|
83
|
+
* @private
|
|
84
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
85
|
+
*/
|
|
86
|
+
private sumAllPayments;
|
|
87
|
+
/**
|
|
88
|
+
* Calculates the sum of payment instructions for a single group.
|
|
89
|
+
* @private
|
|
90
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
91
|
+
* @returns {string} The total sum formatted as a string with 2 decimal places.
|
|
92
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
93
|
+
*/
|
|
94
|
+
private sumPaymentInstructions;
|
|
95
|
+
/**
|
|
96
|
+
* Validates the payment initiation data according to SEPA requirements.
|
|
97
|
+
* @private
|
|
98
|
+
* @throws {Error} If messageId exceeds 35 characters.
|
|
99
|
+
* @throws {Error} If any group's payment instructions have different currencies.
|
|
100
|
+
*/
|
|
101
|
+
private validate;
|
|
102
|
+
/**
|
|
103
|
+
* Validates that all payment instructions in a group have the same currency.
|
|
104
|
+
* @private
|
|
105
|
+
* @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
|
|
106
|
+
* @throws {Error} If payment instructions have different currencies.
|
|
107
|
+
*/
|
|
108
|
+
private validateGroupInstructionsHaveSameCurrency;
|
|
109
|
+
/**
|
|
110
|
+
* Generates payment information for a single SEPA credit transfer instruction.
|
|
111
|
+
* @param {SEPACreditPaymentInstruction} instruction - The payment instruction.
|
|
112
|
+
* @returns {Object} The payment information object formatted according to SEPA specifications.
|
|
113
|
+
*/
|
|
114
|
+
creditTransfer(instruction: SEPACreditPaymentInstruction): {
|
|
115
|
+
Cdtr: any;
|
|
116
|
+
CdtrAcct: {
|
|
117
|
+
Id: {
|
|
118
|
+
IBAN: string;
|
|
119
|
+
};
|
|
120
|
+
Ccy: "EUR";
|
|
121
|
+
};
|
|
122
|
+
RmtInf: {
|
|
123
|
+
Ustrd: string;
|
|
124
|
+
} | undefined;
|
|
125
|
+
CdtrAgt?: {
|
|
126
|
+
FinInstnId: {
|
|
127
|
+
BIC: string;
|
|
128
|
+
ClrSysMmbId?: undefined;
|
|
129
|
+
};
|
|
130
|
+
} | {
|
|
131
|
+
FinInstnId: {
|
|
132
|
+
ClrSysMmbId: {
|
|
133
|
+
ClrSysId: {
|
|
134
|
+
Cd: string;
|
|
135
|
+
};
|
|
136
|
+
MmbId: string;
|
|
137
|
+
};
|
|
138
|
+
BIC?: undefined;
|
|
139
|
+
};
|
|
140
|
+
} | undefined;
|
|
141
|
+
PmtId: {
|
|
142
|
+
InstrId: string;
|
|
143
|
+
EndToEndId: string;
|
|
144
|
+
};
|
|
145
|
+
Amt: {
|
|
146
|
+
InstdAmt: {
|
|
147
|
+
'#': string;
|
|
148
|
+
'@Ccy': "EUR";
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Serializes the SEPA multi credit transfer initiation to an XML string.
|
|
154
|
+
* @returns {string} The XML representation of the SEPA multi credit transfer initiation.
|
|
155
|
+
*/
|
|
156
|
+
serialize(): string;
|
|
157
|
+
/**
|
|
158
|
+
* Parses an XML string and creates a SEPAMultiCreditPaymentInitiation instance.
|
|
159
|
+
* Supports multiple PmtInf blocks in the XML document.
|
|
160
|
+
* @param {string} rawXml - The XML string to parse.
|
|
161
|
+
* @returns {SEPAMultiCreditPaymentInitiation} A new instance created from the XML data.
|
|
162
|
+
* @throws {InvalidXmlError} If the XML format is invalid.
|
|
163
|
+
* @throws {InvalidXmlNamespaceError} If the namespace is not pain.001.001.03.
|
|
164
|
+
*/
|
|
165
|
+
static fromXML(rawXml: string): SEPAMultiCreditPaymentInitiation;
|
|
166
|
+
}
|
|
167
|
+
export {};
|