Zoonk.Billing.Price (Zoonk v0.1.0-dev)
View SourceRepresents a pricing option for a subscription plan.
Fields
Field | Type | Description |
---|---|---|
plan | plan/0 | The subscription plan |
interval | interval/0 | Payment frequency |
currency | String | The currency code (e.g., "usd", "brl") |
value | String | The price value in the specified currency |
stripe_price_id | String | The Stripe price ID for this plan |
Summary
Functions
Extracts currency information from Stripe's currency_options.
Transforms a Stripe Price object into a Price struct for a specific currency.
Types
Functions
Extracts currency information from Stripe's currency_options.
Converts the raw currency data from Stripe's format to a map of currency strings to decimal prices. The unit_amount from Stripe is in cents, so it's divided by 100 to get the actual price.
This is a helper function used internally by transform_from_stripe.
Examples
iex> extract_currencies(%{
...> "usd" => %{"unit_amount" => 500},
...> "brl" => %{"unit_amount" => 1999}
...> })
%{"usd" => "$5.00", "brl" => "R$19.99"}
Transforms a Stripe Price object into a Price struct for a specific currency.
Takes a raw Price object from the Stripe API and converts it to our internal Price struct, extracting the plan, interval, and price for the specified currency. If the currency is not available, falls back to USD, and if USD is not available, returns an error.
For more information about the Stripe Price object structure, see: https://docs.stripe.com/api/prices/object
Examples
iex> transform_from_stripe(%{
...> "lookup_key" => "plus_monthly",
...> "currency_options" => %{
...> "usd" => %{"unit_amount" => 500},
...> "brl" => %{"unit_amount" => 1999}
...> }
...> }, "brl")
{:ok, %Price{
plan: :plus,
interval: :monthly,
currency: "brl",
value: "R$19.99"
}}