diff --git a/config.go b/config.go index 87b134f..bca2ae7 100644 --- a/config.go +++ b/config.go @@ -77,6 +77,12 @@ type Nordigen struct { // "foo,bar" PayeeStrip []string `envconfig:"NORDIGEN_PAYEE_STRIP"` + // TransactionID is the field to use as transaction ID. Not all banks use + // the same field and some even change the ID over time. + // + // Valid options are: TransactionId, InternalTransactionId + TransactionID string `envconfig:"NORDIGEN_TRANSACTION_ID" default:"TransactionId"` + // RequisitionHook is a exec hook thats executed at various stages of the // requisition process. The hook is executed with the following arguments: // diff --git a/reader/nordigen/mapper.go b/reader/nordigen/mapper.go index dcd04ab..8dea46f 100644 --- a/reader/nordigen/mapper.go +++ b/reader/nordigen/mapper.go @@ -21,7 +21,8 @@ func (r Reader) Mapper() Mapper { default: return Default{ - PayeeSource: r.Config.Nordigen.PayeeSource, + PayeeSource: r.Config.Nordigen.PayeeSource, + TransactionID: r.Config.Nordigen.TransactionID, } } } @@ -44,7 +45,8 @@ func parseDate(t nordigen.Transaction) (time.Time, error) { // Default mapping for all banks unless a more specific mapping exists type Default struct { - PayeeSource []string + PayeeSource []string + TransactionID string } // Map t using the default mapper @@ -91,9 +93,20 @@ func (mapper Default) Map(a ynabber.Account, t nordigen.Transaction) (ynabber.Tr } } + // Set the transaction ID according to config + var id string + switch mapper.TransactionID { + case "InternalTransactionId": + id = t.InternalTransactionId + case "TransactionId": + id = t.TransactionId + default: + return ynabber.Transaction{}, fmt.Errorf("unrecognized TransactionID: %s", mapper.TransactionID) + } + return ynabber.Transaction{ Account: a, - ID: ynabber.ID(t.TransactionId), + ID: ynabber.ID(id), Date: date, Payee: ynabber.Payee(payee), Memo: t.RemittanceInformationUnstructured,