@lucianpacurar/iso20022.js 0.2.9 → 0.2.10

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 CHANGED
@@ -293,6 +293,8 @@ interface SWIFTCreditPaymentInstruction extends CreditPaymentInstruction {
293
293
  interface SEPACreditPaymentInstruction extends CreditPaymentInstruction {
294
294
  type?: 'sepa';
295
295
  currency: 'EUR';
296
+ /** Optional requested payment execution date. If not provided, defaults to current date. */
297
+ requestedPaymentExecutionDate?: Date;
296
298
  }
297
299
  interface RTPCreditPaymentInstruction extends CreditPaymentInstruction {
298
300
  type?: 'rtp';
@@ -900,14 +902,6 @@ declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
900
902
  * @returns {string} The total sum formatted as a string with 2 decimal places.
901
903
  */
902
904
  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
905
  /**
912
906
  * Validates the payment initiation data according to SEPA requirements.
913
907
  * @private
package/dist/index.js CHANGED
@@ -7921,20 +7921,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7921
7921
  }
7922
7922
  return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
7923
7923
  }
7924
- /**
7925
- * Calculates the sum of payment instructions for a single group.
7926
- * @private
7927
- * @param {AtLeastOne<SEPACreditPaymentInstruction>} payments - Array of payment instructions.
7928
- * @returns {string} The total sum formatted as a string with 2 decimal places.
7929
- * @throws {Error} If payment instructions have different currencies.
7930
- */
7931
- sumPaymentInstructions(payments) {
7932
- this.validateGroupInstructionsHaveSameCurrency(payments);
7933
- const instructionDineros = payments.map(instruction => Dinero({ amount: instruction.amount, currency: instruction.currency }));
7934
- return instructionDineros.reduce((acc, next) => {
7935
- return acc.add(next);
7936
- }, Dinero({ amount: 0, currency: payments[0].currency })).toFormat('0.00');
7937
- }
7938
7924
  /**
7939
7925
  * Validates the payment initiation data according to SEPA requirements.
7940
7926
  * @private
@@ -7998,28 +7984,31 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7998
7984
  */
7999
7985
  serialize() {
8000
7986
  const builder = PaymentInitiation.getBuilder();
8001
- // Generate multiple PmtInf entries, one per payment instruction group
8002
- const paymentInfoEntries = this.paymentInstructions.map((group, index) => {
8003
- const groupSum = this.sumPaymentInstructions(group.payments);
8004
- const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${index + 1}`, 35);
8005
- return {
8006
- PmtInfId: pmtInfId,
8007
- PmtMtd: 'TRF',
8008
- NbOfTxs: group.payments.length.toString(),
8009
- CtrlSum: groupSum,
8010
- PmtTpInf: {
8011
- SvcLvl: { Cd: 'SEPA' },
8012
- ...(group.categoryPurpose && {
8013
- CtgyPurp: { Cd: group.categoryPurpose }
8014
- }),
8015
- },
8016
- ReqdExctnDt: this.creationDate.toISOString().split('T')[0],
8017
- Dbtr: this.party(group.initiatingParty),
8018
- DbtrAcct: this.account(group.initiatingParty.account),
8019
- DbtrAgt: this.agent(group.initiatingParty.agent),
8020
- ChrgBr: 'SLEV',
8021
- CdtTrfTxInf: group.payments.map(p => this.creditTransfer(p)),
8022
- };
7987
+ // Generate one PmtInf entry per individual payment
7988
+ const paymentInfoEntries = this.paymentInstructions.flatMap((group, groupIndex) => {
7989
+ return group.payments.map((payment, paymentIndex) => {
7990
+ const dinero = Dinero({ amount: payment.amount, currency: payment.currency });
7991
+ const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}-${paymentIndex + 1}`, 35);
7992
+ const requestedExecutionDate = payment.requestedPaymentExecutionDate || new Date();
7993
+ return {
7994
+ PmtInfId: pmtInfId,
7995
+ PmtMtd: 'TRF',
7996
+ NbOfTxs: '1',
7997
+ CtrlSum: dinero.toFormat('0.00'),
7998
+ PmtTpInf: {
7999
+ SvcLvl: { Cd: 'SEPA' },
8000
+ ...(group.categoryPurpose && {
8001
+ CtgyPurp: { Cd: group.categoryPurpose }
8002
+ }),
8003
+ },
8004
+ ReqdExctnDt: requestedExecutionDate.toISOString().split('T')[0],
8005
+ Dbtr: this.party(group.initiatingParty),
8006
+ DbtrAcct: this.account(group.initiatingParty.account),
8007
+ DbtrAgt: this.agent(group.initiatingParty.agent),
8008
+ ChrgBr: 'SLEV',
8009
+ CdtTrfTxInf: this.creditTransfer(payment),
8010
+ };
8011
+ });
8023
8012
  });
8024
8013
  const xml = {
8025
8014
  '?xml': {
@@ -8097,6 +8086,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8097
8086
  };
8098
8087
  // Extract optional category purpose
8099
8088
  const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
8089
+ // Extract requested execution date
8090
+ const requestedExecutionDate = pmtInf.ReqdExctnDt ? new Date(pmtInf.ReqdExctnDt) : undefined;
8100
8091
  // Normalize CdtTrfTxInf to array
8101
8092
  const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
8102
8093
  ? pmtInf.CdtTrfTxInf
@@ -8113,6 +8104,7 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8113
8104
  direction: 'credit',
8114
8105
  amount: amount,
8115
8106
  currency: currency,
8107
+ ...(requestedExecutionDate && { requestedPaymentExecutionDate: requestedExecutionDate }),
8116
8108
  creditor: {
8117
8109
  name: inst.Cdtr?.Nm,
8118
8110
  agent: parseAgent(inst.CdtrAgt),
package/dist/index.mjs CHANGED
@@ -7919,20 +7919,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7919
7919
  }
7920
7920
  return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
7921
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
7922
  /**
7937
7923
  * Validates the payment initiation data according to SEPA requirements.
7938
7924
  * @private
@@ -7996,28 +7982,31 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7996
7982
  */
7997
7983
  serialize() {
7998
7984
  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
- };
7985
+ // Generate one PmtInf entry per individual payment
7986
+ const paymentInfoEntries = this.paymentInstructions.flatMap((group, groupIndex) => {
7987
+ return group.payments.map((payment, paymentIndex) => {
7988
+ const dinero = Dinero({ amount: payment.amount, currency: payment.currency });
7989
+ const pmtInfId = sanitize(`${this.paymentInformationIdBase}-${groupIndex + 1}-${paymentIndex + 1}`, 35);
7990
+ const requestedExecutionDate = payment.requestedPaymentExecutionDate || new Date();
7991
+ return {
7992
+ PmtInfId: pmtInfId,
7993
+ PmtMtd: 'TRF',
7994
+ NbOfTxs: '1',
7995
+ CtrlSum: dinero.toFormat('0.00'),
7996
+ PmtTpInf: {
7997
+ SvcLvl: { Cd: 'SEPA' },
7998
+ ...(group.categoryPurpose && {
7999
+ CtgyPurp: { Cd: group.categoryPurpose }
8000
+ }),
8001
+ },
8002
+ ReqdExctnDt: requestedExecutionDate.toISOString().split('T')[0],
8003
+ Dbtr: this.party(group.initiatingParty),
8004
+ DbtrAcct: this.account(group.initiatingParty.account),
8005
+ DbtrAgt: this.agent(group.initiatingParty.agent),
8006
+ ChrgBr: 'SLEV',
8007
+ CdtTrfTxInf: this.creditTransfer(payment),
8008
+ };
8009
+ });
8021
8010
  });
8022
8011
  const xml = {
8023
8012
  '?xml': {
@@ -8095,6 +8084,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8095
8084
  };
8096
8085
  // Extract optional category purpose
8097
8086
  const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
8087
+ // Extract requested execution date
8088
+ const requestedExecutionDate = pmtInf.ReqdExctnDt ? new Date(pmtInf.ReqdExctnDt) : undefined;
8098
8089
  // Normalize CdtTrfTxInf to array
8099
8090
  const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
8100
8091
  ? pmtInf.CdtTrfTxInf
@@ -8111,6 +8102,7 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8111
8102
  direction: 'credit',
8112
8103
  amount: amount,
8113
8104
  currency: currency,
8105
+ ...(requestedExecutionDate && { requestedPaymentExecutionDate: requestedExecutionDate }),
8114
8106
  creditor: {
8115
8107
  name: inst.Cdtr?.Nm,
8116
8108
  agent: parseAgent(inst.CdtrAgt),
@@ -38,6 +38,8 @@ export interface SWIFTCreditPaymentInstruction extends CreditPaymentInstruction
38
38
  export interface SEPACreditPaymentInstruction extends CreditPaymentInstruction {
39
39
  type?: 'sepa';
40
40
  currency: 'EUR';
41
+ /** Optional requested payment execution date. If not provided, defaults to current date. */
42
+ requestedPaymentExecutionDate?: Date;
41
43
  }
42
44
  export interface RTPCreditPaymentInstruction extends CreditPaymentInstruction {
43
45
  type?: 'rtp';
@@ -84,14 +84,6 @@ export declare class SEPAMultiCreditPaymentInitiation extends PaymentInitiation
84
84
  * @returns {string} The total sum formatted as a string with 2 decimal places.
85
85
  */
86
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
87
  /**
96
88
  * Validates the payment initiation data according to SEPA requirements.
97
89
  * @private
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucianpacurar/iso20022.js",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "readme": "README.md",
5
5
  "description": "Library to create payment messages.",
6
6
  "main": "dist/index.js",