Currency schema for PhoenixKit Billing system.
Manages supported currencies with exchange rates for multi-currency billing.
Schema Fields
code: ISO 4217 currency code (e.g., "EUR", "USD", "GBP")name: Full currency name (e.g., "Euro", "US Dollar")symbol: Currency symbol (e.g., "€", "$", "£")decimal_places: Number of decimal places (usually 2)is_default: Whether this is the default currencyenabled: Whether currency is available for useexchange_rate: Rate relative to base currencysort_order: Display order in currency lists
Usage Examples
# List all enabled currencies
currencies = PhoenixKit.Modules.Billing.list_currencies()
# Get default currency
currency = PhoenixKit.Modules.Billing.get_default_currency()
# Format amount in currency
PhoenixKit.Modules.Billing.Currency.format_amount(99.99, currency)
# => "€99.99"
Summary
Functions
Creates a changeset for currency creation and updates.
Converts amount from one currency to another.
Formats an amount with currency symbol.
Formats an amount without currency symbol.
Functions
Creates a changeset for currency creation and updates.
Converts amount from one currency to another.
Examples
iex> from = %Currency{exchange_rate: Decimal.new("1.0")} # EUR (base)
iex> to = %Currency{exchange_rate: Decimal.new("1.1")} # USD
iex> Currency.convert(100, from, to)
Decimal.new("110.00")
Formats an amount with currency symbol.
Examples
iex> currency = %Currency{symbol: "€", decimal_places: 2}
iex> Currency.format_amount(Decimal.new("99.99"), currency)
"€99.99"
iex> Currency.format_amount(1234.5, currency)
"€1,234.50"
Formats an amount without currency symbol.