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:
from_price/2— by-reference to a catalog pricefrom_price_data/1— inlineprice_datafor ad-hoc pricing
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
@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}
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
})