# `Worldpay.Reporting.CNPBatch`
[🔗](https://github.com/iamkanishka/worldpay/blob/v1.0.0/lib/worldpay/reporting/reporting.ex#L373)

Helpers for **cnpAPI batch file** processing.

cnpAPI batch files are submitted via SFTP and contain XML transaction
records. Results are returned as completion files (~5 business days
for Account Updater; same-day for Dynamic Payout).

## File types

- **Transaction batch** — auth, sale, credit, void, etc. in bulk
- **Account Updater completion file** — results of card update requests
- **Dynamic Payout funding report** — sub-merchant disbursement results

## Usage

    # Build a batch session file
    session_xml = Worldpay.Reporting.CNPBatch.build_session([
      Worldpay.CNP.Builder.sale(id: "txn-001", order_id: "order-001", amount: 1999, card: card),
      Worldpay.CNP.Builder.sale(id: "txn-002", order_id: "order-002", amount: 2999, card: card)
    ],
      merchant_id: "MERCH-001",
      user: "user",
      password: "pass",
      batch_id: "batch-001",
      num_batch_requests: 2
    )

    # Write to SFTP for transmission to Worldpay
    File.write!("/path/to/batch_2026-07-09.xml", session_xml)

# `batch_filename`

```elixir
@spec batch_filename(String.t(), String.t()) :: String.t()
```

Generate a SFTP-ready filename for a cnpAPI batch file.

# `build_session`

```elixir
@spec build_session(
  [String.t()],
  keyword()
) :: String.t()
```

Build a complete cnpAPI session file from a list of transaction XML elements.

## Limits

- Max 20,000 changes per batch
- Max 9,999 batches per session file
- Max 1,000,000 changes per session file

## Options

- `:merchant_id` — merchant ID (required)
- `:user` — cnpAPI username (required)
- `:password` — cnpAPI password (required)
- `:batch_id` — unique batch identifier (required)
- `:report_group` — report group name
- `:num_batch_requests` — number of transactions in this batch

# `parse_account_updater_response`

```elixir
@spec parse_account_updater_response(String.t()) :: {:ok, [map()]} | {:error, term()}
```

Parse a cnpAPI Account Updater completion file.

Returns a list of update result maps, each with:
- `order_id` — original order ID
- `cnp_txn_id` — transaction ID
- `response` — response code ("000" = success)
- `updated_card` / `updated_token` — new card/token details (if updated)
- `reason_code` — network reason code

# `parse_funding_report`

```elixir
@spec parse_funding_report(String.t()) :: {:ok, [map()]} | {:error, term()}
```

Parse a Dynamic Payout funding report.

Returns a list of funding result maps, each with:
- `sub_merchant_id` — sub-merchant identifier
- `funding_amount` — amount disbursed
- `status` — "approved" | "declined" | "pending"
- `routing_number` — bank routing number
- `account_number` — (masked) bank account number
- `funding_transaction_type` — "credit" | "debit"
- `estimated_settlement_date` — ISO 8601 date string

---

*Consult [api-reference.md](api-reference.md) for complete listing*
