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.
Summary
Functions
Builds the JSON response body used to acknowledge a B2B result callback.
Parses a B2B callback payload map into a %Result{} struct.
Parses a B2B callback map from an untrusted HTTP request.
Flattens ResultParameters.ResultParameter into %{"Key" => value}.
Functions
@spec accept() :: %{required(String.t()) => 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"}
@spec from_map(map()) :: Daraja.B2B.Callback.Result.t()
Parses a B2B callback payload map into a %Result{} struct.
@spec parse(map()) :: {:ok, Daraja.B2B.Callback.Result.t()} | {:error, :invalid_callback, String.t()}
Parses a B2B callback map from an untrusted HTTP request.
Flattens ResultParameters.ResultParameter into %{"Key" => value}.