Skip to content

Commit

Permalink
Merge pull request #78 from martinohansen/martin/add-unstructured-array
Browse files Browse the repository at this point in the history
feat(nordigen): support unstructured array
  • Loading branch information
martinohansen authored Sep 16, 2024
2 parents dd452f4 + b696532 commit b57073c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/martinohansen/ynabber

go 1.21
go 1.23

require github.com/frieser/nordigen-go-lib/v2 v2.1.7

Expand Down
18 changes: 12 additions & 6 deletions reader/nordigen/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nordigen
import (
"fmt"
"strconv"
"strings"
"time"

"github.com/frieser/nordigen-go-lib/v2"
Expand Down Expand Up @@ -66,28 +67,33 @@ func (mapper Default) Map(a ynabber.Account, t nordigen.Transaction) (ynabber.Tr
for _, source := range mapper.PayeeSource {
if payee == "" {
switch source {
// Unstructured should properly have been called "remittance" but
// its not. Some banks use this field as Payee.
case "unstructured":
payee = t.RemittanceInformationUnstructured
// Use first unstructured string or array that is defied
if t.RemittanceInformationUnstructured != "" {
payee = t.RemittanceInformationUnstructured
} else if t.RemittanceInformationUnstructuredArray != nil {
payee = strings.Join(t.RemittanceInformationUnstructuredArray, " ")
}

// Unstructured data may need some formatting, some banks
// inserts the amount and date which will cause every
// transaction to create a new Payee
payee = payeeStripNonAlphanumeric(payee)

// Name is using either creditor or debtor as the payee
case "name":
// Use either one
// Use either creditor or debtor as the payee
if t.CreditorName != "" {
payee = t.CreditorName
} else if t.DebtorName != "" {
payee = t.DebtorName
}

// Additional uses AdditionalInformation as payee
case "additional":
// Use AdditionalInformation as payee
payee = t.AdditionalInformation

default:
// Return an error if source is not recognized
return ynabber.Transaction{}, fmt.Errorf("unrecognized PayeeSource: %s", source)
}
}
Expand Down

0 comments on commit b57073c

Please sign in to comment.