Accrue.Checkout.LineItem (accrue v0.2.0)

Copy Markdown View Source

Helpers for constructing Stripe Checkout line_items array entries (CHKT-03).

Line items are plain string-keyed maps in the shape Stripe Checkout expects. Two constructors are provided:

Host apps SHOULD prefer from_price/2 whenever possible — catalog prices are the audit-trail-friendly path.

Summary

Functions

Builds a line item referencing a catalog price by id.

Builds a line item from an inline price_data map. The :quantity key is hoisted to the top level (Stripe expects it outside price_data); the rest is forwarded into the price_data payload as string-keyed entries.

Functions

from_price(price_id, quantity \\ 1)

@spec from_price(String.t(), pos_integer()) :: map()

Builds a line item referencing a catalog price by id.

Examples

iex> Accrue.Checkout.LineItem.from_price("price_basic_monthly", 1)
%{"price" => "price_basic_monthly", "quantity" => 1}

from_price_data(params)

@spec from_price_data(map() | keyword()) :: map()

Builds a line item from an inline price_data map. The :quantity key is hoisted to the top level (Stripe expects it outside price_data); the rest is forwarded into the price_data payload as string-keyed entries.

Examples

Accrue.Checkout.LineItem.from_price_data(%{
  currency: "usd",
  unit_amount: 1500,
  product_data: %{name: "One-off"},
  quantity: 2
})