# `MPP.AcceptPayment`
[🔗](https://github.com/ZenHive/mpp/blob/v0.10.0/lib/mpp/accept_payment.ex#L1)

Parse, format, and rank the `Accept-Payment` client-preference header.

The `Accept-Payment` header lets a client advertise which `method/intent`
pairs it can pay with, optionally weighted by a `q` value (`0.0..1.0`), so a
server can filter and reorder its offers to match. The syntax mirrors HTTP
content negotiation: `method/intent[;q=value]`, comma-separated.

    # Client: build a preference header
    MPP.AcceptPayment.format([{"stripe", "charge", 1.0}, {"tempo", "charge", 0.5}])
    # → "stripe/charge, tempo/charge;q=0.5"

    # Server: parse a request header
    MPP.AcceptPayment.parse("stripe/charge, tempo/charge;q=0.5")
    # → [{"stripe", "charge", 1.0}, {"tempo", "charge", 0.5}]

    # Server: reorder offers by client preference
    MPP.AcceptPayment.apply_header(offers, header, &offer_method_intent/1)

Malformed input is ignored (returns `[]` or a no-op) per the spec's MAY-ignore
rule; oversized headers (> 16 KiB) are ignored the same way as a DoS guard.

## API Functions
| Function | Arity | Description | Param Kinds |
| --- | --- | --- | --- |
| `rank` | 3 | Reorder server offers by client `Accept-Payment` preferences. Excludes `q=0` matches. | `offers: value`, `preferences: value`, `method_intent: value` |
| `format` | 1 | Format preference entries into an `Accept-Payment` header value. | `entries: value` |
| `apply_header` | 3 | Filter and reorder server offers using a request `Accept-Payment` header. Malformed or no-match headers are a no-op. | `offers: value`, `header: value`, `method_intent: value` |
| `parse` | 1 | Parse an `Accept-Payment` header into client preference entries. Malformed input returns `[]` (spec MAY-ignore). | `header: value` |

# `entry`

```elixir
@type entry() :: {String.t(), String.t(), float()}
```

# `apply_header`

```elixir
@spec apply_header([term()], String.t() | nil, (term() -&gt; {String.t(), String.t()})) ::
  [term()]
```

Filter and reorder server offers using an `Accept-Payment` header.

Returns `offers` unchanged when `header` is `nil`, malformed, oversized
(> 16 KiB), or matches no offers (spec MAY-ignore).

# `format`

```elixir
@spec format([entry() | map()]) :: String.t()
```

Format preference entries into an `Accept-Payment` header value.

Omits `;q=` when `q` is `1.0`. Entries may be `{method, intent, q}` tuples
or maps with `:method`, `:intent`, and `:q` keys.

# `parse`

```elixir
@spec parse(String.t()) :: [entry()]
```

Parse an `Accept-Payment` header value into preference entries.

Each entry is `{method, intent, q}` where `method` and `intent` are lowercase
tokens or `*`, and `q` is `0.0..1.0` (default `1.0`).

Returns `[]` for empty, whitespace-only, or malformed input (spec MAY-ignore).
Headers larger than 16 KiB are ignored the same way (DoS cap, applied before parsing).

# `rank`

```elixir
@spec rank([term()], [entry() | map()], (term() -&gt; {String.t(), String.t()})) :: [
  term()
]
```

Reorder server offers by client `Accept-Payment` preferences.

Offers with no matching preference or only `q=0` matches are excluded.
Sorting matches mpp-rs / mppx: highest effective `q`, then original offer order.

`method_intent` extracts `{method, intent}` from each offer (defaults to
challenge fields when omitted).

---

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