Skip to content

Commit

Permalink
Parse purpose fields as string lists.
Browse files Browse the repository at this point in the history
Messages usually contain multiple purpose fields that are currently simply
concatenated. This loses the spacing information between different fields
in the message. This change preserves the string list during parsing and
passes a space-separated list back to the account transaction code.
  • Loading branch information
pkern committed Sep 23, 2018
1 parent 2ad14b3 commit eca1b8a
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 eca1b8a

Please sign in to comment.