Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

Commit

Permalink
handles currency exchanges
Browse files Browse the repository at this point in the history
  • Loading branch information
Seklfreak committed Nov 22, 2021
1 parent 4e1ee58 commit 2ed12e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ func createLunchmoneyTrx(
payee = account.OwnerName
}

// for exchanges use the transaction code as payee
if (trx.ProprietaryBankTransactionCode == "EXCHANGE") &&
payee == "" {
payee = strings.Title(strings.ToLower(trx.ProprietaryBankTransactionCode))
}

note := trx.RemittanceInformationUnstructured
if note == "" {
note = strings.Join(trx.RemittanceInformationUnstructuredArray, "; ")
Expand Down
7 changes: 6 additions & 1 deletion nordigen/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,20 @@ type CurrencyExchanges []*CurrencyExchange

// UnmarshalJSON provides custom JSON unmarshalling for CurrencyExchanges.
func (ce *CurrencyExchanges) UnmarshalJSON(b []byte) error {
// Nordigen returns this sometimes as an array of objects, sometimes as an object.
// this logic is to handle both cases.

// try array
var r []*CurrencyExchange
err := json.Unmarshal(b, &r)
if err != nil {

// try object
var ceItem *CurrencyExchange
err = json.Unmarshal(b, &ceItem)
if err != nil {
return errors.Wrap(err, "failed to unmarshal CurrencyExchanges")
}

r = []*CurrencyExchange{ceItem}
}

Expand Down

0 comments on commit 2ed12e8

Please sign in to comment.