Receive the BAI2 file from the bank (SFTP pickup or API delivery); parse the fixed-position, comma-delimited structure by record type: 01 (File Header), 02 (Group Header), 03 (Account Identifier), 16 (Transaction Detail), 49 (Account Trailer), 98 (Group Trailer), 99 (File Trailer).
Extract from each type-16 detail record: transaction type code, amount, value date, customer reference, and bank reference; map the three-digit type code to a transaction category (credit, debit, lockbox payment, wire, ACH) using the BAI2 type code table.
Match each payment record to an open accounts receivable invoice using the customer reference (check number, invoice number, or remittance advice text); implement fuzzy matching for remittance fields that contain partial invoice numbers or customer PO references.
For matched payments, post a cash application entry in the ERP: debit the bank account, credit the specific open invoice in accounts receivable, and clear the invoice; for unmatched payments, post to a clearing or unidentified cash account for manual review.
Generate a daily cash application summary report: total payments received, percentage auto-matched, total posted to clearing, and unapplied cash aging, and route unmatched items to the AR team with the raw BAI2 detail for research.
Validate file integrity after parsing: recompute the control totals from the detail records and compare against the trailer records (49, 98, 99) to detect file truncation or transmission errors before applying any transactions.
Known gotchas
BAI2 type codes are not universally standardized across all banks; some banks use proprietary extensions or re-use standard codes for non-standard purposes — obtain your bank's specific BAI2 guide and build a bank-specific type code mapping rather than relying on the generic BAI2 specification alone.
Remittance information in BAI2 type-16 records is often truncated to a limited character count (typically 80 characters per continuation record); multi-invoice payments with long remittance details may require parsing continuation records (type 88) appended after the type-16 record.
Duplicate file delivery can result in double-posting if the file header's file-creation-date and sequence number are not checked against previously processed files; maintain a file processing log keyed on the sender-id, receiver-id, and file-creation-date fields from the type-01 record.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp