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

Worldpay **RAFT 610 Interface** — ISO 8583 card-present processing.

Covers all payment types supported by the RAFT platform:
Credit, Debit, EBT (SNAP/WIC), Gift Card, Fleet, Check/ACH, WIC.

This module provides:

1. `Worldpay.RAFT.Message` — ISO 8583 message builders
2. `Worldpay.RAFT.Response` — response field extractors
3. `Worldpay.RAFT` — submit messages over TCP/TLS to RAFT

## RAFT transaction types

### Credit card
- Authorization (0100)
- Sale (0200)
- Capture (0220)
- Reversal — full (0420), partial (0420 with partial flag)
- Refund (0200 with reversal indicator)
- Incremental authorization

### Debit card
- Authorization (0100)
- Pre-authorization / DUKPT key exchange
- Reversal
- Balance Inquiry (0100)

### EBT (Electronic Benefits Transfer)
- SNAP purchase
- SNAP return
- Cash Benefits withdrawal
- Balance Inquiry
- Voice Authorization / Voucher Clear

### Gift Card
- Activation (0200)
- Balance Inquiry (0100)
- Mini-Statement (0100)
- Mass Transaction (0200)
- Reload / Add Value (0200)

### Fleet Card
- Authorization
- Reversal

### Check / ACH
- Enhanced Check Authorization (0200)
- Reversal (0420)

### WIC (Women, Infants, Children)
- Authorization
- Reconciliation records

## Network management
- System Health Check (0800)
- Key Change Request (0800)
- Lane Validation Request
- FleetOne Batch Close
- Reconciliation (0500/0510): Batch Inquiry, Batch Release, Batch Totals

# `build_auth`

```elixir
@spec build_auth(keyword()) :: auth_msg()
```

Build a credit card authorization request.

## Required opts

- `:pan` — primary account number
- `:expiry` — MMYY format
- `:amount` — in cents/pennies (integer)
- `:merchant_id` — RAFT merchant ID
- `:terminal_id` — terminal identifier
- `:stan` — systems trace audit number (6 digits)
- `:entry_mode` — `"022"` (swipe) | `"051"` (EMV) | `"071"` (contactless) | `"011"` (keyed)

## Optional opts

- `:cvv2` — card verification value
- `:avs_zip` — zip for AVS check
- `:avs_address` — address for AVS
- `:track2` — raw track 2 data (card-present)
- `:emv_data` — EMV TLV hex string (Field 55)
- `:cashback_amount` — cashback in cents (debit)
- `:pin_block` — encrypted PIN (DUKPT, debit/EBT)
- `:incremental` — boolean (incremental auth)
- `:original_amount` — original auth amount (for incremental)

# `build_balance_inquiry`

```elixir
@spec build_balance_inquiry(keyword()) :: balance_inquiry_msg()
```

Build a balance inquiry message.

# `build_batch_inquiry`

```elixir
@spec build_batch_inquiry(keyword()) :: batch_inquiry_msg()
```

Build a batch inquiry message (0500).

# `build_batch_release`

```elixir
@spec build_batch_release(keyword()) :: batch_release_msg()
```

Build a batch release (close) message (0500).

# `build_batch_totals`

```elixir
@spec build_batch_totals(keyword()) :: batch_totals_msg()
```

Build a batch totals request.

# `build_capture`

```elixir
@spec build_capture(keyword()) :: capture_msg()
```

Build a capture (settlement) message.

# `build_check_auth`

```elixir
@spec build_check_auth(keyword()) :: check_auth_msg()
```

Build a Check/ACH Enhanced Check Authorization.

# `build_ebt_cash`

```elixir
@spec build_ebt_cash(keyword()) :: ebt_cash_msg()
```

Build an EBT Cash Benefits withdrawal.

# `build_ebt_return`

```elixir
@spec build_ebt_return(keyword()) :: ebt_return_msg()
```

Build an EBT SNAP return/refund.

# `build_ebt_snap_purchase`

```elixir
@spec build_ebt_snap_purchase(keyword()) :: ebt_snap_purchase_msg()
```

Build an EBT SNAP purchase message.

# `build_fleet_auth`

```elixir
@spec build_fleet_auth(keyword()) :: fleet_auth_msg()
```

Build a Fleet card authorization.

# `build_fleet_batch_close`

```elixir
@spec build_fleet_batch_close(keyword()) :: fleet_batch_close_msg()
```

Build a FleetOne batch close request.

# `build_gift_activation`

```elixir
@spec build_gift_activation(keyword()) :: gift_activation_msg()
```

Build a Gift Card activation message.

# `build_gift_mini_statement`

```elixir
@spec build_gift_mini_statement(keyword()) :: gift_mini_statement_msg()
```

Build a Gift Card mini-statement message.

# `build_gift_reload`

```elixir
@spec build_gift_reload(keyword()) :: gift_activation_msg()
```

Build a Gift Card add-value (reload) message.

# `build_health_check`

```elixir
@spec build_health_check(keyword()) :: health_check_msg()
```

Build a system health check message (0800).

# `build_key_change`

```elixir
@spec build_key_change(keyword()) :: key_change_msg()
```

Build a DUKPT key change request (0800).

# `build_lane_validation`

```elixir
@spec build_lane_validation(keyword()) :: lane_validation_msg()
```

Build a lane validation request.

# `build_refund`

```elixir
@spec build_refund(keyword()) :: refund_msg()
```

Build a refund / credit message.

# `build_reversal`

```elixir
@spec build_reversal(keyword()) :: reversal_msg()
```

Build a full reversal message.

# `build_sale`

```elixir
@spec build_sale(keyword()) :: auth_msg()
```

Build a credit card sale (auth + auto-capture).

# `build_wic_auth`

```elixir
@spec build_wic_auth(keyword()) :: wic_auth_msg()
```

Build a WIC authorization.

# `submit`

```elixir
@spec submit(%{required(atom()) =&gt; term()}, Worldpay.Config.t()) ::
  {:ok, %{required(String.t()) =&gt; term()}} | {:error, Worldpay.Error.t()}
```

Submit a RAFT ISO 8583 message over TCP/TLS.

In production, RAFT connection details (host, port, TLS certs) are
supplied by Worldpay Implementation Manager. This function establishes
a TLS connection, frames the message in the RAFT envelope, sends it,
and parses the response.

**Note:** The actual ISO 8583 bit-map encoding and field serialization
are proprietary to RAFT. This function is a integration point; replace
`serialize/1` and `deserialize/1` with the RAFT-specific codec
provided by Worldpay.

---

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