Bazaar.Order (Bazaar v0.3.0)

Copy Markdown View Source

Order documents: building one from a completed checkout, applying the updates a platform sends, and recording fulfillment events.

Schema validation is delegated to the generated Bazaar.Schemas.Shopping.OrderResp.

order = Bazaar.Order.from_checkout(checkout, "order_123", "https://shop.example/orders/123")
{:ok, order} = Bazaar.Order.apply_update(order, params)
order = Bazaar.Order.add_event(order, shipped_event)

Summary

Functions

Appends a fulfillment event (shipped, delivered, ...) to an order.

Applies an update a platform sent for an order: new fulfillment.events and adjustments are appended by id. Adjustments must be a list of entries with a status of pending, completed or failed, otherwise {:error, :invalid_adjustments}.

Builds the order document for a completed checkout document.

Functions

add_event(order, event)

Appends a fulfillment event (shipped, delivered, ...) to an order.

apply_update(order, params)

Applies an update a platform sent for an order: new fulfillment.events and adjustments are appended by id. Adjustments must be a list of entries with a status of pending, completed or failed, otherwise {:error, :invalid_adjustments}.

changeset(params)

See Bazaar.Schemas.Shopping.OrderResp.changeset/1.

from_checkout(checkout, order_id, permalink_url)

Builds the order document for a completed checkout document.

Line items become order line items (quantity: %{total, fulfilled}, status: "processing"), totals and buyer are carried over, and one fulfillment expectation per method describes the selected option and destination. UCP orders require a currency, so the checkout must carry one.

new(params \\ %{})

See Bazaar.Schemas.Shopping.OrderResp.new/1.