webschik/mt940-js

Issue in transaction ID generation

Opened this issue · 0 comments

Hello,

I must first thank you for your work as this has helped us a lot.

I found an issue during transaction ID generation that you might want to fix.

I have a statement that ended up with the same transaction id for two distinct transactions.
The current implementation seems to do a hash of the transaction but the issue stem from the fact that this generation is done before adding the description on the transaction object.

This is where the hash is computed but at that time, the description hasn't been updated/parsed yet
https://github.com/webschik/mt940-js/blob/master/src/tags/transaction-info.ts#L128

I ended up with the following transactions.

As you can see the only thing that differ is the description but as it is not used during id computation, I ended up with the same ID

{
          id: "62b7488d42b4d11470952584b06bbfa8",
          code: "NTRF",
          amount: 500,
          currency: "EUR",
          isCredit: true,
          entryDate: "2021-09-23",
          fundsCode: "",
          isExpense: true,
          valueDate: "2021-09-24",
          description:
            "/TYPE/0568/VIR SEPA RECU/CODE/FR/18//RBR /ZZ1AJ3Z84ZGZNLM/SDT /20210924/NBTR/1/MID /ZZ1AJ3Z84ZGZNLMO0/ULTD//ID/0000000",
          bankReference: "",
          customerReference: "",
        },
        {
          id: "62b7488d42b4d11470952584b06bbfa8",
          code: "NTRF",
          amount: 500,
          currency: "EUR",
          isCredit: true,
          entryDate: "2021-09-23",
          fundsCode: "",
          isExpense: true,
          valueDate: "2021-09-24",
          description:
            "/TYPE/0568/VIR SEPA RECU/CODE/FR/18//RBR /ZZ1AJ4W6JW0BQFB/SDT /20210924/NBTR/1/MID /ZZ1AJ4W6JW0BQFBWB/ULTD//ID/0000000",
          bankReference: "",
          customerReference: "",
        }