-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.go
185 lines (159 loc) · 6.15 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"log"
"os"
"path/filepath"
"time"
"github.com/moov-io/imagecashletter"
)
const (
citadelRoutingNumber = "231380104"
wellsFargoRoutingNumber = "121042882"
)
func main() {
now := time.Now().UTC()
imageBytes, err := os.ReadFile(filepath.Join("examples", "imagecashletter-write", "check_image.tiff"))
if err != nil {
log.Fatalf("could not open check image: %v\n", err)
}
imageDataLength := fmt.Sprintf("%d", len(imageBytes))
header := imagecashletter.NewFileHeader()
header.StandardLevel = "03"
header.TestFileIndicator = "T"
header.ImmediateDestination = citadelRoutingNumber
header.ImmediateDestinationName = "Citadel"
header.ImmediateOrigin = wellsFargoRoutingNumber
header.ImmediateOriginName = "Wells Fargo"
header.FileCreationDate = now
header.FileCreationTime = now
header.ResendIndicator = "N"
header.FileIDModifier = "1"
header.CompanionDocumentIndicator = "1"
letterHeader := imagecashletter.NewCashLetterHeader()
letterHeader.CollectionTypeIndicator = "01"
letterHeader.DestinationRoutingNumber = citadelRoutingNumber
letterHeader.ECEInstitutionRoutingNumber = wellsFargoRoutingNumber
letterHeader.CashLetterBusinessDate = now
letterHeader.CashLetterCreationDate = now
letterHeader.CashLetterCreationTime = now
letterHeader.RecordTypeIndicator = "I"
letterHeader.DocumentationTypeIndicator = "G"
letterHeader.CashLetterID = "74753"
letterHeader.FedWorkType = "C"
bundleHeader := imagecashletter.NewBundleHeader()
bundleHeader.CollectionTypeIndicator = "01"
bundleHeader.DestinationRoutingNumber = citadelRoutingNumber
bundleHeader.ECEInstitutionRoutingNumber = wellsFargoRoutingNumber
bundleHeader.BundleBusinessDate = now
bundleHeader.BundleCreationDate = now
bundleHeader.BundleID = "747531"
bundleHeader.BundleSequenceNumber = "1"
checkDetail := imagecashletter.NewCheckDetail()
checkDetail.PayorBankRoutingNumber = "122000661"
checkDetail.OnUs = "1211-1234-56789"
checkDetail.ItemAmount = 1000
checkDetail.EceInstitutionItemSequenceNumber = "29001104"
checkDetail.DocumentationTypeIndicator = "G"
checkDetail.ReturnAcceptanceIndicator = "0"
checkDetail.MICRValidIndicator = 1
checkDetail.BOFDIndicator = "Y"
checkDetail.AddendumCount = 1
checkDetail.CorrectionIndicator = 4
checkDetail.ArchiveTypeIndicator = "F"
addendumA := imagecashletter.NewCheckDetailAddendumA()
addendumA.RecordNumber = 1
addendumA.ReturnLocationRoutingNumber = wellsFargoRoutingNumber
addendumA.BOFDEndorsementDate = now
addendumA.BOFDItemSequenceNumber = "29001104"
addendumA.BOFDBranchCode = "00029"
addendumA.TruncationIndicator = "Y"
addendumA.BOFDConversionIndicator = "2"
addendumA.BOFDCorrectionIndicator = 0
ivDetailFront := imagecashletter.NewImageViewDetail()
ivDetailFront.ImageIndicator = 1
ivDetailFront.ImageCreatorRoutingNumber = wellsFargoRoutingNumber
ivDetailFront.ImageCreatorDate = now
ivDetailFront.ImageViewFormatIndicator = "00"
ivDetailFront.ImageViewCompressionAlgorithm = "00"
ivDetailFront.ImageViewDataSize = imageDataLength
ivDetailFront.ViewSideIndicator = 0
ivDetailFront.ViewDescriptor = "00"
ivDetailFront.DigitalSignatureIndicator = 0
ivDataFront := imagecashletter.NewImageViewData()
ivDataFront.EceInstitutionRoutingNumber = wellsFargoRoutingNumber
ivDataFront.BundleBusinessDate = now
ivDataFront.CycleNumber = "1"
ivDataFront.EceInstitutionItemSequenceNumber = "29001104"
ivDataFront.LengthImageData = imageDataLength
ivDataFront.ImageData = imageBytes
ivDetailBack := imagecashletter.NewImageViewDetail()
ivDetailBack.ImageCreatorRoutingNumber = wellsFargoRoutingNumber
ivDetailBack.ImageCreatorDate = now
ivDetailBack.ImageViewFormatIndicator = "00"
ivDetailBack.ImageViewCompressionAlgorithm = "00"
ivDetailBack.ImageViewDataSize = imageDataLength
ivDetailBack.ViewSideIndicator = 1
ivDetailBack.ViewDescriptor = "00"
ivDetailBack.DigitalSignatureIndicator = 0
ivDataBack := imagecashletter.NewImageViewData()
ivDataBack.EceInstitutionRoutingNumber = wellsFargoRoutingNumber
ivDataBack.BundleBusinessDate = now
ivDataBack.CycleNumber = "1"
ivDataBack.EceInstitutionItemSequenceNumber = "29001104"
ivDataBack.LengthImageData = imageDataLength
ivDataBack.ImageData = imageBytes
bundleControl := imagecashletter.NewBundleControl()
bundleControl.BundleItemsCount = 1
bundleControl.BundleTotalAmount = 1000
bundleControl.MICRValidTotalAmount = 1000
bundleControl.BundleImagesCount = 2
letterControl := imagecashletter.NewCashLetterControl()
letterControl.CashLetterBundleCount = 1
letterControl.CashLetterItemsCount = 1
letterControl.CashLetterTotalAmount = 1000
letterControl.ECEInstitutionName = "Wells Fargo"
letterControl.SettlementDate = now
fileControl := imagecashletter.NewFileControl()
fileControl.CashLetterCount = 1
fileControl.TotalRecordCount = 12
fileControl.TotalItemCount = 1
fileControl.FileTotalAmount = 1000
checkDetail.AddCheckDetailAddendumA(addendumA)
checkDetail.AddImageViewDetail(ivDetailFront)
checkDetail.AddImageViewData(ivDataFront)
checkDetail.AddImageViewDetail(ivDetailBack)
checkDetail.AddImageViewData(ivDataBack)
bundle := imagecashletter.NewBundle(bundleHeader)
bundle.AddCheckDetail(checkDetail)
cashLetter := imagecashletter.NewCashLetter(letterHeader)
cashLetter.AddBundle(bundle)
if err = cashLetter.Create(); err != nil {
log.Fatalf("could not create cash letter: %v\n", err)
}
file := imagecashletter.NewFile()
file.SetHeader(header)
file.AddCashLetter(cashLetter)
if err = file.Create(); err != nil {
log.Fatalf("Could not create File: %s\n", err)
}
if err = file.Validate(); err != nil {
log.Fatalf("Could not validate File: %s\n", err)
}
opts := []imagecashletter.WriterOption{
imagecashletter.WriteVariableLineLengthOption(),
imagecashletter.WriteEbcdicEncodingOption(),
}
fd, err := os.Create(filepath.Join("examples", "imagecashletter-write", "iclFile.x937"))
if err != nil {
log.Fatalf("could not create output file: %v\n", err)
}
w := imagecashletter.NewWriter(fd, opts...)
if err = w.Write(file); err != nil {
log.Fatalf("Unexpected error: %s\n", err)
}
w.Flush()
}