Order event delivery to platforms.
A platform learns about orders through webhooks: the full order document is
POSTed to the webhook_url the platform advertises in its profile, with
Webhook-Id and Webhook-Timestamp headers, once when the order is created
and again whenever it changes. Failed deliveries are retried with the same
body and headers, so the platform can deduplicate.
Build the event once, then deliver it off the request path:
{:ok, url} = Bazaar.Platform.webhook_url(conn.assigns.ucp_agent_profile, http_client: &MyApp.Http.get/1)
event = Bazaar.Webhook.event(order, url)
Task.Supervisor.start_child(MyApp.TaskSupervisor, fn ->
Bazaar.Webhook.deliver(event, http_client: &MyApp.Http.post/3, signer: {key, profile_url})
end)Delivery blocks the calling process through its retries, so never run it inside the completion request: the platform is waiting on that response.
Signing
With a :signer, each attempt carries UCP-Agent, Content-Digest,
Signature-Input and Signature per Bazaar.Signing.HttpSignature, and the
platform verifies them against the keys[] in your discovery profile.
Without one, none of the four headers is sent.
Summary
Functions
Delivers an event, retrying transport errors, 5xx and 429 with exponential backoff. A 4xx is final.
Builds the event for an order document and the platform's webhook URL.
Functions
Delivers an event, retrying transport errors, 5xx and 429 with exponential backoff. A 4xx is final.
Options
:http_client- required,fn url, body, headers -> {:ok, %{status: integer, body: term}} | {:error, reason} end:signer-{Bazaar.Signing.Key.t(), profile_url};profile_urlis this business's/.well-known/ucp, sent asUCP-Agentso the platform knows whose keys to check:max_attempts(3),:base_delay(500ms),:max_delay(5000ms)
Returns {:ok, %{status: status, attempts: n}}, {:error, {:http_error, status, body}}
for a final 4xx, or {:error, {:max_attempts_reached, n, last_error}}.
Builds the event for an order document and the platform's webhook URL.