Skip to content

Commit

Permalink
fix(nordigen): bring back transaction ID option
Browse files Browse the repository at this point in the history
Bring back support for the user to change transaction ID. Lets give the
users the power to change stuff while we still attempt to support all
banks with specific mappers out of the box.

Fixes #64
  • Loading branch information
martinohansen committed Jan 17, 2024
1 parent c4a2fca commit b8323ce
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 b8323ce

Please sign in to comment.