diff --git a/cmd/createbatch/import_csv.go b/cmd/createbatch/import_csv.go index eebae69..a05c32e 100644 --- a/cmd/createbatch/import_csv.go +++ b/cmd/createbatch/import_csv.go @@ -10,14 +10,15 @@ import ( ) // FieldsPerBatchLine are the expected number of fields in each CSV line. -const FieldsPerBatchLine = 9 +const FieldsPerBatchLine = 11 // ImportIndex keeps track of what column corresponds to what data. type ImportIndex int // These are our numbered input fields const ( - ImportName ImportIndex = iota + ImportCustomerId ImportIndex = iota + ImportName ImportAddr1 ImportAddr2 ImportCountry @@ -26,6 +27,7 @@ const ( ImportSignatureDate ImportAmount ImportInfo + ImportInfoLength ) func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) { @@ -45,7 +47,7 @@ func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) { ret := make([]pain.DrctDbtTxInf, len(all)) for i, line := range all { - if line[0] == "name" { + if line[ImportCustomerId] == "customer_id" { // Header line continue } @@ -57,10 +59,16 @@ func ImportCSV(fn string) ([]pain.DrctDbtTxInf, error) { if err != nil { return nil, fmt.Errorf("error importing line %d, cannot parse amount: %v", i, err) } + if amount == 0.0 { + continue + } info := line[ImportInfo] if info == "" { info = EMPTY_INFO } + if len(info) > MAXLEN_INFO { + return nil, fmt.Errorf("error: info field larger (%d) than allowed (%d)", len(info), MAXLEN_INFO) + } ret[i] = pain.NewDirectDebitTransaction(dbtr, dbtrAcct, mandateInfo, amount, info, i) }