Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deposit tickets #321

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type Bundle struct {
ID string `json:"id"`
// BundleHeader is a Bundle Header Record
BundleHeader *BundleHeader `json:"bundleHeader,omitempty"`
// Credits may be included as part of a bundle, and are often used to represent deposit tickets
Credits []*Credit `json:"credits,omitempty"`
// Checks are Check Items: Check Detail Records, Check Detail Addendum Records, and Image Views
Checks []*CheckDetail `json:"checks,omitempty"`
// Returns are Return Items: Return Detail Records, Return Detail Addendum Records, and Image Views
Expand All @@ -65,6 +67,9 @@ func (b *Bundle) setRecordType() {
return
}
b.BundleHeader.setRecordType()
for i := range b.Credits {
b.Credits[i].setRecordType()
}
for i := range b.Checks {
b.Checks[i].setRecordType()
}
Expand Down Expand Up @@ -96,8 +101,8 @@ func (b *Bundle) Validate() error {
return nil
}

// build creates a valid Bundle by building BundleControl. An error is returned if
// the bundle being built has invalid records.
// build creates a valid Bundle by building BundleControl. An error is returned if the bundle being
// built has invalid records.
func (b *Bundle) build() error {
// Requires a valid BundleHeader
if err := b.BundleHeader.Validate(); err != nil {
Expand All @@ -115,9 +120,21 @@ func (b *Bundle) build() error {
bundleTotalAmount := 0
micrValidTotalAmount := 0
bundleImagesCount := 0
// The current Implementation doe snot support CreditItems as part of a bundle so BundleControl.CreditIndicator = 0
// The current Implementation does not support CreditItems as part of a bundle so BundleControl.CreditIndicator = 0
creditIndicator := 0

// Credit items
for _, cr := range b.Credits {
if err := b.ValidateCredit(cr); err != nil {
return err
}

// A credit record within a Bundle is typically used to present a
// deposit ticket, and its amount is not included in the bundle total
itemCount++
bundleImagesCount += len(cr.ImageViewDetail)
}

// Forward Items
for _, cd := range b.Checks {

Expand All @@ -126,13 +143,13 @@ func (b *Bundle) build() error {
return err
}

itemCount = itemCount + 1
bundleTotalAmount = bundleTotalAmount + cd.ItemAmount
itemCount++
bundleTotalAmount += cd.ItemAmount
if cd.MICRValidIndicator == 1 {
micrValidTotalAmount = micrValidTotalAmount + cd.ItemAmount
micrValidTotalAmount += cd.ItemAmount
}

bundleImagesCount = bundleImagesCount + len(cd.ImageViewDetail)
bundleImagesCount += len(cd.ImageViewDetail)
}

// Return Items
Expand All @@ -142,9 +159,9 @@ func (b *Bundle) build() error {
if err := b.ValidateReturnItems(rd); err != nil {
return err
}
itemCount = itemCount + 1
bundleTotalAmount = bundleTotalAmount + rd.ItemAmount
bundleImagesCount = bundleImagesCount + len(rd.ImageViewDetail)
itemCount++
bundleTotalAmount += rd.ItemAmount
bundleImagesCount += len(rd.ImageViewDetail)
}

// build a BundleControl record
Expand Down Expand Up @@ -204,6 +221,20 @@ func (b *Bundle) GetReturns() []*ReturnDetail {
return b.Returns
}

func (b *Bundle) ValidateCredit(cr *Credit) error {
for _, ivDetail := range cr.ImageViewDetail {
if err := ivDetail.Validate(); err != nil {
return err
}
}
for _, ivData := range cr.ImageViewData {
if err := ivData.Validate(); err != nil {
return err
}
}
return nil
}

// ValidateForwardItems calls Validate function for check items
func (b *Bundle) ValidateForwardItems(cd *CheckDetail) error {
// Validate items
Expand Down
12 changes: 12 additions & 0 deletions credit.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type Credit struct {
DebitCreditIndicator string `json:"debitCreditIndicator,omitempty"`
// reserved is a field reserved for future use. Reserved should be blank.
reserved string

ImageViewDetail []ImageViewDetail `json:"imageViewDetail"`
ImageViewData []ImageViewData `json:"imageViewData"`

// validator is composed for image cash letter data validation
validator
// converters is composed for image cash letter to golang Converters
Expand Down Expand Up @@ -268,3 +272,11 @@ func (cr *Credit) DebitCreditIndicatorField() string {
func (cr *Credit) reservedField() string {
return cr.alphaField(cr.reserved, 3)
}

func (cr *Credit) AddImageViewData(ivData ImageViewData) {
cr.ImageViewData = append(cr.ImageViewData, ivData)
}

func (cr *Credit) AddImageViewDetail(ivDetail ImageViewDetail) {
cr.ImageViewDetail = append(cr.ImageViewDetail, ivDetail)
}
2 changes: 1 addition & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var (
msgFileCashLetterID = "%s is not unique"
msgRecordType = "received expecting %d"
msgFileCreditItem = "Credit item outside of cash letter"
msgFileCredit = "Credit outside of cash letter"
msgFileCredit = "Credit outside of cash letter or bundle"
)

// FileError is an error describing issues validating a file
Expand Down
7 changes: 7 additions & 0 deletions fileControl.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func NewFileControl() FileControl {
return fc
}

func (fc *FileControl) IsZero() bool {
if fc == nil {
return true
}
return *fc == (FileControl{}) || *fc == NewFileControl()
}

func (fc *FileControl) setRecordType() {
if fc == nil {
return
Expand Down
7 changes: 7 additions & 0 deletions fileHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ func NewFileHeader() FileHeader {
return fh
}

func (fh *FileHeader) IsZero() bool {
if fh == nil {
return true
}
return *fh == (FileHeader{}) || *fh == NewFileHeader()
}

func (fh *FileHeader) setRecordType() {
if fh == nil {
return
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand All @@ -30,7 +29,6 @@ require (
github.com/rickar/cal/v2 v2.1.13 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 0 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/encoding v1.0.1 h1:YzKZckdBL6jVt2Gc+5p82qhrGiqMdG/eNs6Wy0u3Uhw=
github.com/gdamore/encoding v1.0.1/go.mod h1:0Z0cMFinngz9kS1QfMjCP8TY7em3bZYeeklsSDPivEo=
github.com/go-kit/kit v0.13.0 h1:OoneCcHKHQ03LfBpoQCUfCluwd2Vt3ohz+kvbJneZAU=
Expand All @@ -18,11 +16,6 @@ github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU=
github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down Expand Up @@ -59,8 +52,6 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI=
golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -80,7 +71,6 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
Expand All @@ -89,11 +79,6 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 0 additions & 1 deletion imageViewDetail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func TestMockImageViewDetail(t *testing.T) {
require.Equal(t, "", ivDetail.reserved)
require.Equal(t, "0", ivDetail.OverrideIndicator)
require.Equal(t, "", ivDetail.reservedTwo)

}

// TestParseIVDetail validates parsing an ImageViewDetail
Expand Down
Loading
Loading