batchPOS
Removed isAddenda02
Add Addenda02 logic to Validate to not range through entries twice
@@ -45,10 +45,6 @@ func (batch *BatchPOS) Validate() error {
}
// Add configuration based validation for this type.
- // POS Addenda must be Addenda02
- if err := batch.isAddenda02(); err != nil {
- return err
- }
// Add type specific validation.
if batch.Header.StandardEntryClassCode != "POS" {
msg := fmt.Sprintf(msgBatchSECType, batch.Header.StandardEntryClassCode, "POS")
@@ -73,31 +69,13 @@ func (batch *BatchPOS) Validate() error {
msg := fmt.Sprintf(msgBatchCardTransactionType, entry.DiscretionaryData)
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "CardTransactionType", Msg: msg}
}
-
- //ToDo; Additional validations - move isAddenda02 logic so we only range through a batch of entries once
- }
- return nil
-}
-
-// Create takes Batch Header and Entries and builds a valid batch
-func (batch *BatchPOS) Create() error {
- // generates sequence numbers and batch control
- if err := batch.build(); err != nil {
- return err
- }
- // Additional steps specific to batch type
- // ...
-
- return batch.Validate()
-}
-
-// isAddenda02 verifies that a Addenda02 exists for each EntryDetail and is Validated
-func (batch *BatchPOS) isAddenda02() error {
- for _, entry := range batch.Entries {
- // Addenda type must be equal to 1
+ // Addendum must be equal to 1
if len(entry.Addendum) != 1 {
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: "Addendum", Msg: msgBatchPOSAddenda}
}
+
+ // POS Addenda must be Addenda02
+
// Addenda type assertion must be Addenda02
addenda02, ok := entry.Addendum[0].(*Addenda02)
if !ok {
@@ -111,6 +89,19 @@ func (batch *BatchPOS) isAddenda02() error {
return &BatchError{BatchNumber: batch.Header.BatchNumber, FieldName: e.FieldName, Msg: e.Msg}
}
}
+ //ToDo; Additional validations
}
return nil
}
+
+// Create takes Batch Header and Entries and builds a valid batch
+func (batch *BatchPOS) Create() error {
+ // generates sequence numbers and batch control
+ if err := batch.build(); err != nil {
+ return err
+ }
+ // Additional steps specific to batch type
+ // ...
+
+ return batch.Validate()
+}
