Behaviour for implementing UCP merchant handlers.
Implement this behaviour to define your commerce logic. The callbacks correspond to UCP capabilities (checkout, orders, identity).
Example
defmodule MyApp.Commerce.Handler do
use Bazaar.Handler
@impl Bazaar.Handler
def capabilities, do: [:checkout, :orders]
@impl Bazaar.Handler
def create_checkout(params, conn) do
case MyApp.Checkouts.create(params) do
{:ok, checkout} -> {:ok, checkout}
{:error, changeset} -> {:error, changeset}
end
end
@impl Bazaar.Handler
def get_checkout(id, _conn) do
case MyApp.Checkouts.get(id) do
nil -> {:error, :not_found}
checkout -> {:ok, checkout}
end
end
endRequired Callbacks
Depending on which capabilities you declare, you must implement the corresponding callbacks:
Checkout Capability
create_checkout/2- Create a new checkout sessionget_checkout/2- Retrieve a checkout sessionupdate_checkout/3- Update a checkout sessioncomplete_checkout/2- Complete a checkout session and create an ordercancel_checkout/2- Cancel a checkout session
Orders Capability
get_order/2- Retrieve an ordercancel_order/2- Cancel an order
Catalog Capability
list_products/2- List products with optional filters (category, limit, cursor)get_product/2- Get a single product by ID or SKUsearch_products/2- Search products by query string
Identity Capability
link_identity/2- Link a user identity via OAuth
Summary
Types
@type capability() ::
:checkout
| :orders
| :identity
| :fulfillment
| :discount
| :buyer_consent
| :catalog
@type conn() :: Plug.Conn.t()
@type id() :: String.t()
@type params() :: map()
Callbacks
@callback business_profile() :: map()
@callback capabilities() :: [capability()]
@callback fulfillment_config() :: map()