Skip to content

Commit

Permalink
Merge pull request #15 from pkern/master
Browse files Browse the repository at this point in the history
Parse purpose fields as string lists.
  • Loading branch information
mitch000001 authored Dec 9, 2018
2 parents 2315736 + eca1b8a commit d1fd34b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions swift/element.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ type CustomFieldTag struct {
TransactionID int
BookingText string
PrimanotenNumber string
Purpose string
Purpose []string
BankID string
AccountID string
Name string
MessageKeyAddition int
Purpose2 string
Purpose2 []string
}

var customFieldTagFieldKeys = [][]byte{
Expand Down Expand Up @@ -187,7 +187,7 @@ func (c *CustomFieldTag) Unmarshal(value []byte) error {
case bytes.HasPrefix(fieldKey, []byte{'?', '1', '0'}):
c.PrimanotenNumber = fieldValue
case bytes.HasPrefix(fieldKey, []byte{'?', '2'}):
c.Purpose += fieldValue
c.Purpose = append(c.Purpose, fieldValue)
case bytes.HasPrefix(fieldKey, []byte{'?', '3', '0'}):
c.BankID = fieldValue
case bytes.HasPrefix(fieldKey, []byte{'?', '3', '1'}):
Expand All @@ -203,7 +203,7 @@ func (c *CustomFieldTag) Unmarshal(value []byte) error {
}
c.MessageKeyAddition = messageKeyAddition
case bytes.HasPrefix(fieldKey, []byte{'?', '6'}):
c.Purpose2 += fieldValue
c.Purpose2 = append(c.Purpose2, fieldValue)
default:
internal.Debug.Printf("Unmarshal CustomFieldTag: unknown fieldKey: %s\n", fieldKey)
}
Expand Down
4 changes: 2 additions & 2 deletions swift/element_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ func TestCustomFieldTagUnmarshal(t *testing.T) {
TransactionID: 123,
BookingText: "ABC",
PrimanotenNumber: "xyz",
Purpose: "ahhhjj",
Purpose: []string{"ahh", "hjj"},
BankID: "1000",
AccountID: "56",
Name: "Max Muster",
MessageKeyAddition: 99,
Purpose2: "uuz4",
Purpose2: []string{"uu", "z4"},
}

tag := &CustomFieldTag{}
Expand Down
4 changes: 2 additions & 2 deletions swift/mt940.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (m *MT940) AccountTransactions() []domain.AccountTransaction {
transaction.BankID = descr.BankID
transaction.AccountID = descr.AccountID
transaction.Name = descr.Name
transaction.Purpose = descr.Purpose
transaction.Purpose2 = descr.Purpose2
transaction.Purpose = strings.Join(descr.Purpose, " ")
transaction.Purpose2 = strings.Join(descr.Purpose2, " ")
transaction.TransactionID = descr.TransactionID
}
transactions = append(transactions, transaction)
Expand Down

0 comments on commit d1fd34b

Please sign in to comment.