---
title: ZeroPaySubpoenaProcess
summary: API reference for ZeroPaySubpoenaProcess.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-24
library: SAIF.Services
reference_type: package
---

# ZeroPaySubpoenaProcess

Batch-generates the mail-room print package for provider-type subpoena recipients that require no check payment ("zero pay"), pre-generating certified mailing labels for each mailable recipient via `ISubpoenaLabelService`, assembling per-recipient document XML via `ISubpoenaDocumentService`, persisting the resulting `XPrintControl`/`XDocument` batch records (with OnBase imaging index metadata) via `IUnitOfWork`, and emailing the development team through `IDocumentService.EmailService` when any recipient's label generation fails.

## Purpose
- Generates the XPressions print-batch XML and imaging index entries for zero-paid-amount recipients of ready-to-pay, provider-type subpoenas, writing an empty placeholder file when there is nothing to print.
- Pre-generates certified mailing labels for each mailable recipient before building the document batch, logging and continuing past any individual label failure rather than aborting the run.
- Notifies the development team by email when one or more recipient labels failed to generate during the batch.

## Context
- Namespace: `SAIF.Services.Legal.Subpoenas`
- Assembly/package: `SAIF.Services` (packaged inside the `SAIF.SAIFCode.Core` NuGet package).

## Public members
| Member | Signature | Purpose |
| --- | --- | --- |
| ZeroPaySubpoenaProcess (constructor) | `public ZeroPaySubpoenaProcess(IUnitOfWork unitOfWork, ISubpoenaDocumentService subpoenaDocumentService, ISubpoenaLabelService subpoenaLabelService, IEnvironmentService environmentService, UtilDocument.IDocumentService documentService, string developerEmails)` | Wires the unit of work, subpoena document service, subpoena label service, environment configuration, document/email service, and a developer-email distribution list; null-checks all six parameters. |
| GenerateZeroPayDocuments | `public long GenerateZeroPayDocuments(XPrintBatchArguments batchArguments, ILogWriter errorLogWriter)` | Selects ready-to-pay, provider-type subpoenas, pre-generates certified labels for each mailable recipient (logging and continuing past `InvalidOperationException` failures), builds a `SubpoenaDocumentsConfiguration` per zero-paid-amount recipient (with OnBase IDX metadata) inside a transaction, writes the resulting XPressions XML (or an empty placeholder if none), emails the development team if any label failed, and returns the number of documents generated. |

## Behavioral notes
- Restricts document generation to recipients whose `PaidAmount == 0` within otherwise-approved subpoenas, and further restricts label pre-generation to recipients whose subpoena special handling is not `DoNotMail`.
- Catches only `InvalidOperationException` around each recipient's label generation, logging the message to `errorLogWriter` and setting an `anyErrors` flag rather than aborting the batch; any other exception type still propagates.
- Sends the development-team failure-notification email only after the transaction commits, and only if at least one label failed during the run.
- Do-not-mail-flagged recipients are still included in the document batch but are excluded from label generation and have no certified-label file path assigned, with the window-envelope flag left unset for them.*
- Sanitizes generated XML by renaming internal DTO element names to the external XPressions schema (`SubpoenaDocumentsConfiguration`→`clsPaymentTransaction`, `ArrayOfclsPaymentTransaction`→`clsPaymentTransactionCollection`, `SubpoenaDocument`→`Subpoena`) and un-escaping doubly-encoded `<br>` tags before writing the file, matching the convention used by `OpposingCounselService` and `WitnessSubpoenaProcess`.
- Uses a different mail-room instruction string ("Deliver to Transformers Team") when `IEnvironmentService.IsProduction` is `false`, redirecting non-production batches away from the live mail room.*
- Carries a `CA1506:AvoidExcessiveClassCoupling` suppression on `GenerateZeroPayDocuments`, reflecting its dependency on document, label, environment, and email collaborators.

## Constraints and usage notes
- `GenerateZeroPayDocuments` throws via `Enforce.ArgumentNotNull` if `batchArguments` or `errorLogWriter` is `null`.
- `CreateIdxString` hardcodes several OnBase imaging fields (`BatchJobName = "AUTOIMPORT"`, `ImageFileCode = "LEGAL"`, `CreateUser = "BATCH"`, `Spec = "OnBase16"`), so document imaging metadata is not configurable per batch run.*

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- `Services/SAIF.Services/Legal/Subpoenas/ZeroPaySubpoenaProcess.cs`
