Skip to content

Commit

Permalink
mandatory fedWireMessage fields
Browse files Browse the repository at this point in the history
mandatory fedWireMessage fields
  • Loading branch information
bkmoovio committed Apr 16, 2019
1 parent 91bf76b commit 0933546
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 88 deletions.
4 changes: 2 additions & 2 deletions beneficiaryIntermediaryFI_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wire

// mockBeneficiaryIntermediaryFI creates a BeneficiaryIntermediaryFI
// mockBeneficiaryIntermediaryFI creates a BeneficiaryIntermediaryFI
func mockBeneficiaryIntermediaryFI() *BeneficiaryIntermediaryFI {
bifi := NewBeneficiaryIntermediaryFI()
bifi.FinancialInstitution.IdentificationCode = DemandDepositAccountNumber
Expand All @@ -10,4 +10,4 @@ func mockBeneficiaryIntermediaryFI() *BeneficiaryIntermediaryFI {
bifi.FinancialInstitution.Address.AddressLineTwo = "Address Two"
bifi.FinancialInstitution.Address.AddressLineThree = "Address Three"
return bifi
}
}
36 changes: 20 additions & 16 deletions fedWireMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

package wire

//ToDo: omitEmpty

// FedWireMessage is a FedWire Message
type FedWireMessage struct {
// ID
Expand Down Expand Up @@ -142,34 +140,40 @@ func NewFedWireMessage() FedWireMessage {

// verify checks basic valid NACHA batch rules. Assumes properly parsed records. This does not mean it is a valid batch as validity is tied to each batch type
func (fwm *FedWireMessage) verify() error {
// ToDo: Add errors

if fwm.SenderSupplied == nil {
return nil
if err := fwm.isMandatory(); err != nil {
return err
}

/* if err := batch.isBatchAmount(); err != nil {
return err
}*/

return nil
}

func (fwm *FedWireMessage) isMandatory() error {

if fwm.SenderSupplied == nil {
return fieldError("SenderSupplied", ErrFieldRequired)
}
if fwm.TypeSubType == nil {
return nil
return fieldError("TypeSubType", ErrFieldRequired)
}

if fwm.InputMessageAccountabilityData == nil {
return nil
return fieldError("InputMessageAccountabilityData", ErrFieldRequired)
}

if fwm.Amount == nil {
return nil
return fieldError("Amount", ErrFieldRequired)
}

if fwm.SenderDepositoryInstitution == nil {
return nil
return fieldError("SenderDepositoryInstitution", ErrFieldRequired)
}

if fwm.ReceiverDepositoryInstitution == nil {
return nil
return fieldError("ReceiverDepositoryInstitution", ErrFieldRequired)
}

if fwm.BusinessFunctionCode == nil {
return nil
return fieldError("BusinessFunctionCode", ErrFieldRequired)
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@ func (f *File) Create() error {

// Validate will never modify the file.
func (f *File) Validate() error {
if err := f.FedWireMessage.verify(); err != nil {
return err
}
return nil
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6
github.com/moov-io/ach v1.0.0
github.com/moov-io/base v0.9.0
github.com/pkg/errors v0.8.0
github.com/rickar/cal v1.0.1 // indirect
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421
golang.org/x/text v0.3.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ github.com/moov-io/base v0.8.0/go.mod h1:pPu/TAc9PkaaegbREVEeDHsGqyAlvji9vqTuARu
github.com/moov-io/base v0.9.0 h1:7bp5Jpola4EunGmOVVaw3WkWOqcSnyVZJEoOmYLKdhw=
github.com/moov-io/base v0.9.0/go.mod h1:pPu/TAc9PkaaegbREVEeDHsGqyAlvji9vqTuARuAnd0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down
14 changes: 12 additions & 2 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Reader struct {
File File
// line is the current line being parsed from the input r
line string
// ToDo: Do we need a current FEDWireMessage, just use FedWireMessage
// currentFedWireMessage is the current FedWireMessage being parsed
currentFedWireMessage FedWireMessage
// lineNum is the line number of the file being parsed
Expand Down Expand Up @@ -74,6 +75,8 @@ func (r *Reader) Read() (File, error) {
return r.File, err
}
}
r.File.AddFedWireMessage(r.currentFedWireMessage)
r.currentFedWireMessage = NewFedWireMessage()
return r.File, nil
}

Expand Down Expand Up @@ -321,6 +324,7 @@ func (r *Reader) parseSenderSupplied() error {
if err := ss.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetSenderSupplied(ss)
return nil
}

Expand All @@ -335,6 +339,7 @@ func (r *Reader) parseTypeSubType() error {
if err := tst.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetTypeSubType(tst)
return nil
}

Expand All @@ -349,6 +354,7 @@ func (r *Reader) parseInputMessageAccountabilityData() error {
if err := imad.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetInputMessageAccountabilityData(imad)
return nil
}

Expand All @@ -363,12 +369,13 @@ func (r *Reader) parseAmount() error {
if err := amt.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetAmount(amt)
return nil
}

func (r *Reader) parseSenderDepositoryInstitution() error {
r.tagName = "SenderDepositoryInstitution"
/* if len(r.line) < 15 {
/* if len(r.line) < 15 {
r.errors.Add(r.parseError(NewTagWrongLengthErr(15, len(r.line))))
return r.errors
}*/
Expand All @@ -377,12 +384,13 @@ func (r *Reader) parseSenderDepositoryInstitution() error {
if err := sdi.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetSenderDepositoryInstitution(sdi)
return nil
}

func (r *Reader) parseReceiverDepositoryInstitution() error {
r.tagName = "ReceiverDepositoryInstitution"
/* if len(r.line) < 15 {
/* if len(r.line) < 15 {
r.errors.Add(r.parseError(NewTagWrongLengthErr(15, len(r.line))))
return r.errors
}*/
Expand All @@ -391,6 +399,7 @@ func (r *Reader) parseReceiverDepositoryInstitution() error {
if err := rdi.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetReceiverDepositoryInstitution(rdi)
return nil
}

Expand All @@ -405,6 +414,7 @@ func (r *Reader) parseBusinessFunctionCode() error {
if err := bfc.Validate(); err != nil {
return r.parseError(err)
}
r.currentFedWireMessage.SetBusinessFunctionCode(bfc)
return nil
}

Expand Down
8 changes: 5 additions & 3 deletions reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ func TestFedWireMessageFileRead(t *testing.T) {
}
defer f.Close()
r := NewReader(f)
_, err = r.Read()

if _, err := r.Read(); err != nil {
fwmFile, err := r.Read()
if err != nil {
t.Errorf("%T: %s", err, err)
}
if err = r.File.Validate(); err != nil {
// ensure we have a validated file structure
if err = fwmFile.Validate(); err != nil {
t.Errorf("%T: %s", err, err)
}

}
69 changes: 34 additions & 35 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"io"
)

// A Writer writes an x9.file to an encoded file.
// A Writer writes an fedWireMessage to an encoded file.
//
// As returned by NewWriter, a Writer writes x9file structs into
// x9 formatted files.
// As returned by NewWriter, a Writer writes FedWireMessage file structs into
// FedWireMessage formatted files.

// Writer struct
type Writer struct {
Expand All @@ -27,7 +27,7 @@ func NewWriter(w io.Writer) *Writer {
}
}

// Writer writes a single x9.file record to w
// Writer writes a single FedWireMessage record to w
func (w *Writer) Write(file *File) error {
if err := file.Validate(); err != nil {
return err
Expand All @@ -49,44 +49,43 @@ func (w *Writer) Flush() {
}

func (w *Writer) writeFedWireMessage(file *File) error {
fwm := file.FedWireMessage
if err := w.writeMandatory(fwm); err != nil {
return err
}
if err := w.writeOtherTransferInfo(fwm); err != nil {
return err
}
if err := w.writeBeneficiary(fwm); err != nil {
return err
}
if err := w.writeOriginator(fwm); err != nil {
return err
}
if err := w.writeFinancialInstitution(fwm); err != nil {
return err
}
fwm := file.FedWireMessage
if err := w.writeMandatory(fwm); err != nil {
return err
}
if err := w.writeOtherTransferInfo(fwm); err != nil {
return err
}
if err := w.writeBeneficiary(fwm); err != nil {
return err
}
if err := w.writeOriginator(fwm); err != nil {
return err
}
if err := w.writeFinancialInstitution(fwm); err != nil {
return err
}

if err := w.writeCoverPayment(fwm); err != nil {
return err
}
if err := w.writeCoverPayment(fwm); err != nil {
return err
}

if fwm.UnstructuredAddenda != nil {
if _, err := w.w.WriteString(fwm.GetUnstructuredAddenda().String() + "\n"); err != nil {
return err
}
if fwm.UnstructuredAddenda != nil {
if _, err := w.w.WriteString(fwm.GetUnstructuredAddenda().String() + "\n"); err != nil {
return err
}
if err := w.writeRemittance(fwm); err != nil {
return err
}
if fwm.ServiceMessage != nil {
if _, err := w.w.WriteString(fwm.GetServiceMessage().String() + "\n"); err != nil {
return err
}
}
if err := w.writeRemittance(fwm); err != nil {
return err
}
if fwm.ServiceMessage != nil {
if _, err := w.w.WriteString(fwm.GetServiceMessage().String() + "\n"); err != nil {
return err
}
}
return nil
}


func (w *Writer) writeMandatory(fwm FedWireMessage) error {
if fwm.SenderSupplied != nil {
if _, err := w.w.WriteString(fwm.GetSenderSupplied().String() + "\n"); err != nil {
Expand Down
Loading

0 comments on commit 0933546

Please sign in to comment.