rs_ach/
records.rs

1//! ACH record type definitions following NACHA specifications.
2//!
3//! Each record type represents a specific line in an ACH file.
4//! All ACH records are exactly 94 characters long.
5
6/// File Header Record (Record Type 1)
7///
8/// The file header record designates physical file characteristics and
9/// identifies the immediate destination and origin of the entries within the file.
10#[derive(Debug, Clone)]
11pub struct FileHeader<'a> {
12    /// Record Type Code (always "1")
13    pub record_type: &'a str,
14
15    /// Priority Code (01-99)
16    pub priority_code: &'a str,
17
18    /// Immediate Destination (10 characters) - Routing number with leading space
19    pub immediate_destination: &'a str,
20
21    /// Immediate Origin (10 characters) - Company ID with leading space
22    pub immediate_origin: &'a str,
23
24    /// File Creation Date (YYMMDD)
25    pub file_creation_date: &'a str,
26
27    /// File Creation Time (HHMM)
28    pub file_creation_time: &'a str,
29
30    /// File ID Modifier (A-Z, 0-9)
31    pub file_id_modifier: &'a str,
32
33    /// Record Size (always "094")
34    pub record_size: &'a str,
35
36    /// Blocking Factor (always "10")
37    pub blocking_factor: &'a str,
38
39    /// Format Code (always "1")
40    pub format_code: &'a str,
41
42    /// Immediate Destination Name (23 characters)
43    pub immediate_destination_name: &'a str,
44
45    /// Immediate Origin Name (23 characters)
46    pub immediate_origin_name: &'a str,
47
48    /// Reference Code (8 characters)
49    pub reference_code: &'a str,
50}
51
52/// Batch Header Record (Record Type 5)
53///
54/// The batch header record identifies the batch and provides summary
55/// information about the entries in the batch.
56#[derive(Debug, Clone)]
57pub struct BatchHeader<'a> {
58    /// Record Type Code (always "5")
59    pub record_type: &'a str,
60
61    /// Service Class Code (200, 220, 225)
62    /// - 200: Mixed debits and credits
63    /// - 220: Credits only
64    /// - 225: Debits only
65    pub service_class_code: &'a str,
66
67    /// Company Name (16 characters)
68    pub company_name: &'a str,
69
70    /// Company Discretionary Data (20 characters)
71    pub company_discretionary_data: &'a str,
72
73    /// Company Identification (10 characters) - Tax ID
74    pub company_identification: &'a str,
75
76    /// Standard Entry Class Code (3 characters) - PPD, CCD, WEB, etc.
77    pub standard_entry_class_code: &'a str,
78
79    /// Company Entry Description (10 characters)
80    pub company_entry_description: &'a str,
81
82    /// Company Descriptive Date (6 characters)
83    pub company_descriptive_date: &'a str,
84
85    /// Effective Entry Date (YYMMDD)
86    pub effective_entry_date: &'a str,
87
88    /// Settlement Date (Julian, 3 characters)
89    pub settlement_date: &'a str,
90
91    /// Originator Status Code (1 character)
92    pub originator_status_code: &'a str,
93
94    /// Originating DFI Identification (8 characters) - First 8 digits of routing number
95    pub originating_dfi_identification: &'a str,
96
97    /// Batch Number (7 characters)
98    pub batch_number: &'a str,
99}
100
101/// Entry Detail Record (Record Type 6)
102///
103/// Contains the details of individual transactions within a batch.
104#[derive(Debug, Clone)]
105pub struct EntryDetail<'a> {
106    /// Record Type Code (always "6")
107    pub record_type: &'a str,
108
109    /// Transaction Code (22, 23, 27, 28, 32, 33, 37, 38)
110    pub transaction_code: &'a str,
111
112    /// Receiving DFI Identification (8 characters) - First 8 digits of routing number
113    pub receiving_dfi_identification: &'a str,
114
115    /// Check Digit (1 character) - 9th digit of routing number
116    pub check_digit: &'a str,
117
118    /// DFI Account Number (17 characters)
119    pub dfi_account_number: &'a str,
120
121    /// Amount (10 characters) - In cents, no decimal
122    pub amount: u64,
123
124    /// Individual Identification Number (15 characters)
125    pub individual_identification_number: &'a str,
126
127    /// Individual Name (22 characters)
128    pub individual_name: &'a str,
129
130    /// Discretionary Data (2 characters)
131    pub discretionary_data: &'a str,
132
133    /// Addenda Record Indicator (0 or 1)
134    pub addenda_record_indicator: &'a str,
135
136    /// Trace Number (15 characters)
137    pub trace_number: &'a str,
138
139    /// Optional addenda records
140    pub addenda: Vec<Addenda<'a>>,
141}
142
143/// Addenda Record (Record Type 7)
144///
145/// Provides additional information for an entry detail record.
146#[derive(Debug, Clone)]
147pub struct Addenda<'a> {
148    /// Record Type Code (always "7")
149    pub record_type: &'a str,
150
151    /// Addenda Type Code (05 for most types)
152    pub addenda_type_code: &'a str,
153
154    /// Payment Related Information (80 characters)
155    pub payment_related_information: &'a str,
156
157    /// Addenda Sequence Number (4 characters)
158    pub addenda_sequence_number: &'a str,
159
160    /// Entry Detail Sequence Number (7 characters)
161    pub entry_detail_sequence_number: &'a str,
162}
163
164/// Batch Control Record (Record Type 8)
165///
166/// Contains totals and counts for the entries in the batch.
167#[derive(Debug, Clone)]
168pub struct BatchControl {
169    /// Record Type Code (always "8")
170    pub record_type: String,
171
172    /// Service Class Code (must match batch header)
173    pub service_class_code: String,
174
175    /// Entry/Addenda Count
176    pub entry_addenda_count: u64,
177
178    /// Entry Hash - Sum of receiving DFI identification numbers
179    pub entry_hash: u64,
180
181    /// Total Debit Entry Dollar Amount (in cents)
182    pub total_debit_amount: u64,
183
184    /// Total Credit Entry Dollar Amount (in cents)
185    pub total_credit_amount: u64,
186
187    /// Company Identification (must match batch header)
188    pub company_identification: String,
189
190    /// Message Authentication Code (19 characters)
191    pub message_authentication_code: String,
192
193    /// Reserved (6 characters)
194    pub reserved: String,
195
196    /// Originating DFI Identification (8 characters)
197    pub originating_dfi_identification: String,
198
199    /// Batch Number (must match batch header)
200    pub batch_number: String,
201}
202
203/// File Control Record (Record Type 9)
204///
205/// Contains totals and counts for the entire file.
206#[derive(Debug, Clone)]
207pub struct FileControl {
208    /// Record Type Code (always "9")
209    pub record_type: String,
210
211    /// Batch Count
212    pub batch_count: u64,
213
214    /// Block Count
215    pub block_count: u64,
216
217    /// Entry/Addenda Count
218    pub entry_addenda_count: u64,
219
220    /// Entry Hash - Sum of all entry hashes
221    pub entry_hash: u64,
222
223    /// Total Debit Entry Dollar Amount in File (in cents)
224    pub total_debit_amount: u64,
225
226    /// Total Credit Entry Dollar Amount in File (in cents)
227    pub total_credit_amount: u64,
228
229    /// Reserved (39 characters)
230    pub reserved: String,
231}