# `Daraja.B2B.Callback`
[🔗](https://github.com/okothkongo/daraja/blob/v0.1.1/lib/daraja/b2b/callback.ex#L1)

Helpers for parsing asynchronous B2B callback payloads posted to `ResultURL`.

B2B transactions are asynchronous; this module parses successful and unsuccessful
callback payloads into typed structs and provides helpers to extract
`ResultParameters` values by key.

Verify inbound requests with `Daraja.Callback.Security`, deduplicate on
`originator_conversation_id` with `Daraja.Callback.Guard`, and use `parse/1`
on untrusted input.

# `accept`

```elixir
@spec accept() :: %{required(String.t()) =&gt; String.t() | non_neg_integer()}
```

Builds the JSON response body used to acknowledge a B2B result callback.

B2B callbacks are one-way notifications; M-PESA only needs the merchant to
acknowledge receipt with `ResultCode: 0`.

    Daraja.B2B.Callback.accept()
    #=> %{"ResultCode" => 0, "ResultDesc" => "Success"}

# `from_map`

```elixir
@spec from_map(map()) :: Daraja.B2B.Callback.Result.t()
```

Parses a B2B callback payload map into a `%Result{}` struct.

# `parse`

```elixir
@spec parse(map()) ::
  {:ok, Daraja.B2B.Callback.Result.t()}
  | {:error, :invalid_callback, String.t()}
```

Parses a B2B callback map from an untrusted HTTP request.

# `result_parameters_map`

```elixir
@spec result_parameters_map([map()] | map() | nil) :: %{
  optional(String.t()) =&gt; term()
}
```

Flattens `ResultParameters.ResultParameter` into `%{"Key" => value}`.

---

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