Skip to content

Commit

Permalink
Merge pull request #65 from martinohansen/martin/revert-tid
Browse files Browse the repository at this point in the history
fix(nordigen): bring back transaction ID option
  • Loading branch information
martinohansen authored Jan 18, 2024
2 parents c881693 + b8323ce commit 2c0983f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// <status> <link>
Expand Down
19 changes: 16 additions & 3 deletions reader/nordigen/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2c0983f

Please sign in to comment.