@lucianpacurar/iso20022.js 0.2.8 → 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
@@ -7746,13 +7746,15 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7746
7746
  CtrlSum: this.formattedPaymentSum,
7747
7747
  InitgPty: {
7748
7748
  Nm: this.initiatingParty.name,
7749
- Id: {
7750
- OrgId: {
7751
- Othr: {
7752
- Id: this.initiatingParty.id,
7749
+ ...(this.initiatingParty.id && {
7750
+ Id: {
7751
+ OrgId: {
7752
+ Othr: {
7753
+ Id: this.initiatingParty.id,
7754
+ },
7753
7755
  },
7754
7756
  },
7755
- },
7757
+ }),
7756
7758
  },
7757
7759
  },
7758
7760
  PmtInf: {
@@ -7919,20 +7921,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7919
7921
  }
7920
7922
  return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
7921
7923
  }
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
7924
  /**
7937
7925
  * Validates the payment initiation data according to SEPA requirements.
7938
7926
  * @private
@@ -7996,28 +7984,31 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7996
7984
  */
7997
7985
  serialize() {
7998
7986
  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
- };
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
+ });
8021
8012
  });
8022
8013
  const xml = {
8023
8014
  '?xml': {
@@ -8035,13 +8026,15 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8035
8026
  CtrlSum: this.formattedPaymentSum,
8036
8027
  InitgPty: {
8037
8028
  Nm: this.initiatingParty.name,
8038
- Id: {
8039
- OrgId: {
8040
- Othr: {
8041
- Id: this.initiatingParty.id,
8029
+ ...(this.initiatingParty.id && {
8030
+ Id: {
8031
+ OrgId: {
8032
+ Othr: {
8033
+ Id: this.initiatingParty.id,
8034
+ },
8042
8035
  },
8043
8036
  },
8044
- },
8037
+ }),
8045
8038
  },
8046
8039
  },
8047
8040
  PmtInf: paymentInfoEntries,
@@ -8093,6 +8086,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8093
8086
  };
8094
8087
  // Extract optional category purpose
8095
8088
  const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
8089
+ // Extract requested execution date
8090
+ const requestedExecutionDate = pmtInf.ReqdExctnDt ? new Date(pmtInf.ReqdExctnDt) : undefined;
8096
8091
  // Normalize CdtTrfTxInf to array
8097
8092
  const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
8098
8093
  ? pmtInf.CdtTrfTxInf
@@ -8109,6 +8104,7 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8109
8104
  direction: 'credit',
8110
8105
  amount: amount,
8111
8106
  currency: currency,
8107
+ ...(requestedExecutionDate && { requestedPaymentExecutionDate: requestedExecutionDate }),
8112
8108
  creditor: {
8113
8109
  name: inst.Cdtr?.Nm,
8114
8110
  agent: parseAgent(inst.CdtrAgt),
package/dist/index.mjs CHANGED
@@ -7744,13 +7744,15 @@ class SEPACreditPaymentInitiation extends PaymentInitiation {
7744
7744
  CtrlSum: this.formattedPaymentSum,
7745
7745
  InitgPty: {
7746
7746
  Nm: this.initiatingParty.name,
7747
- Id: {
7748
- OrgId: {
7749
- Othr: {
7750
- Id: this.initiatingParty.id,
7747
+ ...(this.initiatingParty.id && {
7748
+ Id: {
7749
+ OrgId: {
7750
+ Othr: {
7751
+ Id: this.initiatingParty.id,
7752
+ },
7751
7753
  },
7752
7754
  },
7753
- },
7755
+ }),
7754
7756
  },
7755
7757
  },
7756
7758
  PmtInf: {
@@ -7917,20 +7919,6 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7917
7919
  }
7918
7920
  return Dinero({ amount: totalAmount, currency }).toFormat('0.00');
7919
7921
  }
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
7922
  /**
7935
7923
  * Validates the payment initiation data according to SEPA requirements.
7936
7924
  * @private
@@ -7994,28 +7982,31 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
7994
7982
  */
7995
7983
  serialize() {
7996
7984
  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
- };
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
+ });
8019
8010
  });
8020
8011
  const xml = {
8021
8012
  '?xml': {
@@ -8033,13 +8024,15 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8033
8024
  CtrlSum: this.formattedPaymentSum,
8034
8025
  InitgPty: {
8035
8026
  Nm: this.initiatingParty.name,
8036
- Id: {
8037
- OrgId: {
8038
- Othr: {
8039
- Id: this.initiatingParty.id,
8027
+ ...(this.initiatingParty.id && {
8028
+ Id: {
8029
+ OrgId: {
8030
+ Othr: {
8031
+ Id: this.initiatingParty.id,
8032
+ },
8040
8033
  },
8041
8034
  },
8042
- },
8035
+ }),
8043
8036
  },
8044
8037
  },
8045
8038
  PmtInf: paymentInfoEntries,
@@ -8091,6 +8084,8 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8091
8084
  };
8092
8085
  // Extract optional category purpose
8093
8086
  const categoryPurpose = pmtInf.PmtTpInf?.CtgyPurp?.Cd;
8087
+ // Extract requested execution date
8088
+ const requestedExecutionDate = pmtInf.ReqdExctnDt ? new Date(pmtInf.ReqdExctnDt) : undefined;
8094
8089
  // Normalize CdtTrfTxInf to array
8095
8090
  const rawInstructions = Array.isArray(pmtInf.CdtTrfTxInf)
8096
8091
  ? pmtInf.CdtTrfTxInf
@@ -8107,6 +8102,7 @@ class SEPAMultiCreditPaymentInitiation extends PaymentInitiation {
8107
8102
  direction: 'credit',
8108
8103
  amount: amount,
8109
8104
  currency: currency,
8105
+ ...(requestedExecutionDate && { requestedPaymentExecutionDate: requestedExecutionDate }),
8110
8106
  creditor: {
8111
8107
  name: inst.Cdtr?.Nm,
8112
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.8",
3
+ "version": "0.2.10",
4
4
  "readme": "README.md",
5
5
  "description": "Library to create payment messages.",
6
6
  "main": "dist/index.js",