Skip to content

Commit

Permalink
feat(nordigen): support unstructured array
Browse files Browse the repository at this point in the history
If string is not defined combine the array into a single string and use
that. Should fix BoursoBank which only returns the array.

Fixes #77
  • Loading branch information
martinohansen committed Sep 6, 2024
1 parent dd452f4 commit 07cc371
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 07cc371

Please sign in to comment.