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

Worldpay **Enhanced Merchant Activity File (eMAF)** parser.

eMAF is Worldpay's daily settlement reconciliation file (v1.43, Apr 2026).
Delivered via SFTP. Covers Credit, Debit POS, EBT (SNAP/WIC), Gift Card,
POS Check Services, and WIC.

## Record types (Credit)

| Record | Description |
|---|---|
| 1 | Credit Reconciliation Detail Transaction |
| 2 | Credit Reconciliation Detail Transaction (additional fields) |
| 3 | DCC / MCP Information |
| 4 | Risk Holds and Releases |
| 5 | Reward Data (Summary Level) |
| 7 | Customer Discretionary Data |

## Usage

    {:ok, records} = Worldpay.Reporting.EMAF.parse_file("/path/to/emaf.dat")
    {:ok, records} = Worldpay.Reporting.EMAF.parse_string(file_contents)

    # Group by record type
    by_type = Worldpay.Reporting.EMAF.group_by_type(records)

    # Extract credit detail records
    credit_records = Worldpay.Reporting.EMAF.credit_records(records)

    # Find transactions with PAR
    par_records = Worldpay.Reporting.EMAF.with_par(records)

    # Find digital wallet transactions
    wallet_records = Worldpay.Reporting.EMAF.wallet_transactions(records)

## Key fields added in recent releases

- Transaction Integrity Classification (TIC) Indicator
- Payment Account Reference (PAR)
- Convenience Fee Amount
- Digital Wallet fields (Auth Detail + Reconciliation Detail)
- Pin Conversion Flag (Debit POS Record 2)
- FraudSight records for WIC and EBT transactions

# `record`

```elixir
@type record() :: %{
  record_type: record_type(),
  record_number: String.t(),
  fields: [String.t()],
  raw: String.t()
}
```

# `record_type`

```elixir
@type record_type() ::
  :credit_detail
  | :credit_detail_2
  | :dcc_mcp
  | :risk_hold
  | :reward_summary
  | :customer_discretionary
  | :debit_detail
  | :debit_detail_2
  | :ebt_detail
  | :gift_detail
  | :wic_detail
  | :check_detail
  | :header
  | :trailer
  | :unknown
```

# `credit_records`

```elixir
@spec credit_records([record()]) :: [record()]
```

Filter for credit detail records (Record 1).

# `dcc_mcp_records`

```elixir
@spec dcc_mcp_records([record()]) :: [record()]
```

Filter for DCC/MCP information records (Record 3).

# `debit_records`

```elixir
@spec debit_records([record()]) :: [record()]
```

Filter for debit POS detail records.

# `ebt_records`

```elixir
@spec ebt_records([record()]) :: [record()]
```

Filter for EBT records.

# `fraudsight_records`

```elixir
@spec fraudsight_records([record()]) :: [record()]
```

Filter transactions with FraudSight data.

# `get_field`

```elixir
@spec get_field(record(), atom()) :: String.t() | nil
```

Extract a named field from a parsed record.

# `gift_records`

```elixir
@spec gift_records([record()]) :: [record()]
```

Filter for Gift Card records.

# `group_by_type`

```elixir
@spec group_by_type([record()]) :: %{required(record_type()) =&gt; [record()]}
```

Group records by type.

# `parse_file`

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

Parse an eMAF file from disk.

# `parse_string`

```elixir
@spec parse_string(String.t()) :: {:ok, [record()]}
```

Parse an eMAF file from a string.

# `reconciliation_summary`

```elixir
@spec reconciliation_summary([record()]) :: %{
  total_records: non_neg_integer(),
  credit_count: non_neg_integer(),
  debit_count: non_neg_integer(),
  ebt_count: non_neg_integer(),
  gift_count: non_neg_integer(),
  wic_count: non_neg_integer(),
  dcc_count: non_neg_integer(),
  risk_hold_count: non_neg_integer(),
  credit_total: integer(),
  debit_total: integer(),
  wallet_transactions: non_neg_integer(),
  par_transactions: non_neg_integer()
}
```

Generate a reconciliation summary from eMAF records.

# `risk_hold_records`

```elixir
@spec risk_hold_records([record()]) :: [record()]
```

Filter for Risk Hold and Release records (Record 4).

# `sum_amounts`

```elixir
@spec sum_amounts([record()]) :: integer()
```

Sum transaction amounts for a list of records.

# `wallet_transactions`

```elixir
@spec wallet_transactions([record()]) :: [record()]
```

Filter digital wallet transactions.

# `wic_records`

```elixir
@spec wic_records([record()]) :: [record()]
```

Filter for WIC records.

# `with_par`

```elixir
@spec with_par([record()]) :: [record()]
```

Filter records that have a Payment Account Reference (PAR).

---

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