From b696532082c39d94a482eea660fcaf8c5ff3d78c Mon Sep 17 00:00:00 2001 From: Martin Hansen Date: Fri, 6 Sep 2024 09:49:17 +0200 Subject: [PATCH] feat(nordigen): support unstructured array 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 --- go.mod | 2 +- reader/nordigen/mapper.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index aa1ab38..0b79de4 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/reader/nordigen/mapper.go b/reader/nordigen/mapper.go index 8dea46f..6013f80 100644 --- a/reader/nordigen/mapper.go +++ b/reader/nordigen/mapper.go @@ -3,6 +3,7 @@ package nordigen import ( "fmt" "strconv" + "strings" "time" "github.com/frieser/nordigen-go-lib/v2" @@ -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) } }