### Start Exchange Rates Retrieval Service Source: https://context7_llms Starts the exchange rates retrieval service. This function initializes and begins the operation of the service, which will then periodically fetch exchange rates. ```elixir Money.ExchangeRates.Retriever.start/1 ``` -------------------------------- ### Calculate Next Interval Start Date (Money.Subscription.next_interval_starts/3) Source: https://context7_llms Calculates the start date of the next interval for a given subscription plan. Requires the plan and the current interval's start date. Returns the next interval start date as a `Date.t`. ```elixir alias Money.Subscription alias Money.Subscription.Plan # Example for a monthly plan plan_monthly = Plan.new!(Money.new!(:USD, 100), :month) current_start_monthly = ~D[2018-03-01] next_start_monthly = Money.Subscription.next_interval_starts(plan_monthly, current_start_monthly) # => ~D[2018-04-01] # Example for a daily plan with a 30-day interval plan_daily = Plan.new!(Money.new!(:USD, 100), :day, 30) current_start_daily = ~D[2018-02-01] next_start_daily = Money.Subscription.next_interval_starts(plan_daily, current_start_daily) # => ~D[2018-03-03] ``` -------------------------------- ### Money.Subscription.current_plan_start_date/1 Source: https://context7_llms Returns the start date of the current active plan for a subscription. ```APIDOC ## Money.Subscription.current_plan_start_date/1 ### Description Returns the start date of the plan that is currently in effect for a subscription. ### Method `Money.Subscription.current_plan_start_date` ### Parameters #### Arguments - `subscription` - `Money.Subscription.t` or a map providing the `:plans` field. ### Returns - `Date.t`: The start date of the current plan. ### Request Example ```elixir # Assuming 'subscription' is a Money.Subscription.t struct Money.Subscription.current_plan_start_date(subscription) ``` ### Response Example (Success) ```elixir ~D[2018-01-01] ``` ``` -------------------------------- ### Money.ExchangeRates.OpenExchangeRates.init/1 Source: https://context7_llms Initializes the retriever configuration to include requirements for Open Exchange Rates. This function is called when the exchange rate service starts up. ```APIDOC ## Money.ExchangeRates.OpenExchangeRates.init/1 ### Description Updates the retriever configuration to include the requirements for Open Exchange Rates. This function is invoked when the exchange rate service starts up, just after the ets table :exchange_rates is created. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir # No direct request example, this is an internal function call. ``` ### Response #### Success Response - `:config` (map) - The configuration either unchanged or updated with additional configuration specific to this exchange rates retrieval module. #### Response Example ```elixir # Example of updated configuration, exact structure may vary %{... exchange_rates: %{... module: Money.ExchangeRates.OpenExchangeRates, ... } } ``` ``` -------------------------------- ### Exchange Rates Supervisor Management Source: https://context7_llms Functions to start, stop, and restart the exchange rates supervisor. ```APIDOC ## Money.ExchangeRates.Supervisor.start_link/0 ### Description Starts the Exchange Rates supervisor and optionally starts the exchange rates retrieval service as well. ### Method POST ### Endpoint /money/exchange_rates/supervisor/start_link ### Parameters #### Request Body - **options** (object) - Optional - Configuration options for starting the supervisor. - **restart** (boolean) - Optional - If the supervisor is to be restarted. Defaults to `false`. - **start_retriever** (boolean) - Optional - If the exchange rates retriever is to be started. Defaults to the value of `:auto_start_exchange_rate_service` configuration key. ### Request Example ```json { "options": { "restart": true, "start_retriever": true } } ``` ### Money.ExchangeRates.Supervisor.stop/1 ### Description Stops the Money.ExchangeRates.Supervisor. ### Method POST ### Endpoint /money/exchange_rates/supervisor/stop ### Parameters #### Path Parameters - **reason** (any) - The reason for stopping the supervisor. ### Money.ExchangeRates.Supervisor.restart_retriever/0 ### Description Restarts the exchange rates retriever. ### Method POST ### Endpoint /money/exchange_rates/supervisor/restart_retriever ``` -------------------------------- ### Cache Initialization (Elixir) Source: https://context7_llms Initializes the cache when the exchange rates retriever process starts. This is a callback implementation for the `Money.ExchangeRates.Cache` behaviour. ```elixir Money.ExchangeRates.Cache.init() ``` -------------------------------- ### Money.ExchangeRates.Retriever.child_spec/1 Source: https://context7_llms Returns a specification to start the Money.ExchangeRates.Retriever module under a supervisor. ```APIDOC ## Money.ExchangeRates.Retriever.child_spec/1 ### Description Returns a specification to start this module under a supervisor. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```elixir Money.ExchangeRates.Retriever.child_spec(config) ``` ### Response #### Success Response - `:supervisor_spec` (tuple) - A supervisor child specification for the `Money.ExchangeRates.Retriever` GenServer. #### Response Example ```elixir {:ok, %{id: Money.ExchangeRates.Retriever, start: {Money.ExchangeRates.Retriever, :start_link, [config]}}} ``` ``` -------------------------------- ### Get Configuration (Elixir) Source: https://context7_llms Returns the current configuration for `ex_money`, including merged settings from the configured exchange rates retriever module. ```elixir Money.ExchangeRates.config() ``` -------------------------------- ### Get Default Configuration (Elixir) Source: https://context7_llms Returns the default configuration settings for the exchange rates retriever module. ```elixir Money.ExchangeRates.default_config() ``` -------------------------------- ### Get Number of Days in Plan Interval (Money.Subscription.plan_days/3) Source: https://context7_llms Determines the number of days within a specific interval of a subscription plan. Takes the plan and the start date of the current interval as arguments. Returns the count of days as an integer. ```elixir alias Money.Subscription alias Money.Subscription.Plan plan = Plan.new!(Money.new!(:USD, 100), :month, 1) # Leap year February Money.Subscription.plan_days(plan, ~D[2018-02-01]) # => 28 # Non-leap year January Money.Subscription.plan_days(plan, ~D[2018-01-01]) # => 31 # April Money.Subscription.plan_days(plan, ~D[2018-04-01]) # => 30 ``` -------------------------------- ### Money.Subscription.current_interval_start_date/2 Source: https://context7_llms Retrieves the start date of the current billing interval for a subscription or changeset. ```APIDOC ## Money.Subscription.current_interval_start_date/2 ### Description Returns the first date of the current billing interval for a given subscription or changeset. ### Method `Money.Subscription.current_interval_start_date` ### Parameters #### Arguments - `:subscription_or_changeset` - `Money.Subscription.t` or a `{Change.t, Plan.t}` tuple. - `:options` - Keyword list of options: - `:today` (`Date.t`, optional): A date representing today. Defaults to `Date.utc_today`. ### Returns - The `Date.t` representing the first date of the current interval. ### Request Example ```elixir # Assuming 'subscription' is a Money.Subscription.t struct Money.Subscription.current_interval_start_date(subscription, today: ~D[2018-01-10]) ``` ### Response Example (Success) ```elixir ~D[2018-01-01] ``` ``` -------------------------------- ### Dets Cache Implementation Get (Elixir) Source: https://context7_llms Implementation of the `get/1` function for the `Money.ExchangeRates.Cache.Dets` module, which uses :dets for caching. ```elixir Money.ExchangeRates.Cache.Dets.get(key) ``` -------------------------------- ### Money.Subscription.latest_plan/1 Source: https://context7_llms Retrieves the latest plan associated with a subscription, which may have a future start date. ```APIDOC ## Money.Subscription.latest_plan/1 ### Description Returns the most recently defined plan for a subscription. This plan might not be active yet if its start date is in the future. ### Method `Money.Subscription.latest_plan` ### Parameters #### Arguments - `subscription` - `Money.Subscription.t` or a map providing the `:plans` field. ### Returns - `Money.Subscription.Plan.t`: The latest plan defined for the subscription. ### Request Example ```elixir # Assuming 'subscription' is a Money.Subscription.t struct Money.Subscription.latest_plan(subscription) ``` ### Response Example (Success) ```elixir %Money.Subscription.Plan{... ``` ``` -------------------------------- ### Get Latest Subscription Plan (Money.Subscription.latest_plan/1) Source: https://context7_llms Retrieves the most recent plan for a given subscription, regardless of whether it's the currently active one. It expects a `Money.Subscription.t` or a map with a `:plans` field as input. ```elixir alias Money.Subscription # Assuming `subscription` is a Money.Subscription.t latest_plan = Subscription.latest_plan(subscription) ``` -------------------------------- ### Initialize Open Exchange Rates Configuration Source: https://context7_llms Updates the retriever configuration to include requirements for Open Exchange Rates. This function is called when the exchange rate service starts up, after the ets table :exchange_rates is created. It takes the default configuration and returns it, potentially updated with Open Exchange Rates specific settings. ```elixir Money.ExchangeRates.OpenExchangeRates.init/1 ``` -------------------------------- ### Get Last Updated Timestamp (Elixir) Source: https://context7_llms Returns the timestamp of the last successful exchange rate retrieval. If no timestamp is known, it returns `{:error, reason}`. An example shows a successful return value. ```elixir Money.ExchangeRates.last_updated() ``` -------------------------------- ### Money.Subscription.Plan.new!/3 Source: https://context7_llms Creates a new subscription plan, raising an exception on failure. It accepts the same arguments as Money.Subscription.Plan.new/3. ```APIDOC ## POST /money/subscription/plan! ### Description Creates a new subscription plan, raising an exception on failure. It accepts the same arguments as `Money.Subscription.Plan.new/3`. ### Method POST ### Endpoint /money/subscription/plan! ### Parameters #### Query Parameters - **price** (Money.t) - Required - The price of the subscription plan. - **interval** (atom) - Required - The interval period of the plan. Valid options are `:day`, `:week`, `:month`, or `:year`. - **interval_count** (integer) - Optional - The number of intervals for the plan. Defaults to 1. ### Request Example ```json { "price": {"currency": "USD", "amount": 100}, "interval": "day", "interval_count": 30 } ``` ### Response #### Success Response (200) - **plan** (Money.Subscription.Plan.t) - The newly created subscription plan. #### Response Example ```json { "plan": { "price": {"currency": "USD", "amount": 100}, "interval": "day", "interval_count": 30 } } ``` ``` -------------------------------- ### Dets Cache Implementation Init (Elixir) Source: https://context7_llms Callback implementation for `Money.ExchangeRates.Cache.init/0` using the :dets backend. ```elixir Money.ExchangeRates.Cache.Dets.init() ``` -------------------------------- ### Create New Subscription (Money.Subscription.new/3) Source: https://context7_llms Creates a new subscription with a specified initial plan and effective date. Accepts optional parameters like a unique subscription ID and creation timestamp. Returns `{:ok, Money.Subscription.t}` on success or `{:error, {exception, message}}` on failure. ```elixir alias Money.Subscription alias Money.Subscription.Plan # Example: Creating a monthly subscription plan = Plan.new!(Money.new!(:USD, 100), :month) effective_date = ~D[2023-01-15] # With default options {:ok, subscription} = Subscription.new(plan, effective_date) # With custom options options = [id: "sub-123", created_at: DateTime.utc_now()] {:ok, subscription_with_options} = Subscription.new(plan, effective_date, options) ``` -------------------------------- ### Money.Subscription.Plan.new/3 Source: https://context7_llms Creates a new subscription plan with specified price, interval, and interval count. Returns an {:ok, plan} tuple on success or an {:error, reason} tuple on failure. ```APIDOC ## POST /money/subscription/plan ### Description Creates a new subscription plan with specified price, interval, and interval count. ### Method POST ### Endpoint /money/subscription/plan ### Parameters #### Query Parameters - **price** (Money.t) - Required - The price of the subscription plan. - **interval** (atom) - Required - The interval period of the plan. Valid options are `:day`, `:week`, `:month`, or `:year`. - **interval_count** (integer) - Optional - The number of intervals for the plan. Defaults to 1. ### Request Example ```json { "price": {"currency": "USD", "amount": 100}, "interval": "month", "interval_count": 1 } ``` ### Response #### Success Response (200) - **plan** (Money.Subscription.Plan.t) - The newly created subscription plan. #### Error Response (400) - **reason** (any) - The reason for the creation failure. #### Response Example ```json { "plan": { "price": {"currency": "USD", "amount": 100}, "interval": "month", "interval_count": 1 } } ``` ``` -------------------------------- ### Create New Subscription or Raise (Money.Subscription.new!/3) Source: https://context7_llms Creates a new subscription similar to `Money.Subscription.new/3`, but raises an exception if an error occurs instead of returning an error tuple. Expects the initial plan, effective date, and optional keyword list of options. ```elixir alias Money.Subscription alias Money.Subscription.Plan # Example: Creating a daily subscription plan = Plan.new!(Money.new!(:USD, 50), :day, 30) effective_date = ~D[2023-02-20] # Creates and returns the subscription, raises on error subscription = Subscription.new!(plan, effective_date) # With options options = [id: "sub-456"] subscription_with_options = Subscription.new!(plan, effective_date, options) ``` -------------------------------- ### Subscription Management Source: https://context7_llms Functions for creating, upgrading, and downgrading subscriptions between plans. ```APIDOC ## Money.Subscription.new/3 ### Description Creates a new subscription with a specified plan, effective date, and options. ### Method POST ### Endpoint /money/subscription/new ### Parameters #### Request Body - **plan** (object) - Required - The initial plan for the subscription. - **effective_date** (date) - Required - The effective date of the initial plan. - **options** (object) - Optional - Additional options like `:created_at` and `:id`. ### Request Example ```json { "plan": { ... }, "effective_date": "2023-10-27", "options": { "created_at": "2023-10-27T10:00:00Z", "id": "sub_123" } } ``` ### Money.Subscription.change_plan/3 ### Description Changes a subscription to a new plan using a specified strategy. ### Method PUT ### Endpoint /money/subscription/change_plan ### Parameters #### Request Body - **subscription** (object) - Required - The current subscription details. - **new_plan** (object) - Required - The definition of the new plan. - **strategy** (string) - Required - The strategy for changing the plan (`'end_of_period'` or `'immediate'`). ``` -------------------------------- ### Money.new/3 Source: https://context7_llms Creates a %Money{} struct from a currency code and an amount, with optional keyword list for configuration. ```APIDOC ## POST /money/new ### Description Creates a %Money{} struct from a currency code and an amount. Supports various input types for currency and amount, and accepts options for locale, backend, and separators. ### Method POST ### Endpoint /money/new ### Parameters #### Query Parameters - **currency_code** (string | atom) - Required - ISO4217 binary or atom currency code or ISO 24165 token identifier or shortname. - **amount** (integer | string | Decimal) - Required - The monetary amount. - **options** (keyword list) - Optional - Configuration options like :locale, :backend, :separators. ### Request Example ```json { "currency_code": "USD", "amount": 100, "options": { "locale": "en-US", "backend": "Money.CldrBackend" } } ``` ### Response #### Success Response (200) - **money_struct** (%Money{}) - The created Money struct. #### Response Example ```json { "currency": "USD", "amount": "100" } ``` #### Error Response (400) - **error** (object) - Contains error details if the currency code is invalid or amount is not supported. #### Error Response Example ```json { "error": { "type": "Money.UnknownCurrencyError", "message": "The currency :XYZZ is invalid" } } ``` ``` -------------------------------- ### Get Maximum Money Amount - Money.max/2 Source: https://context7_llms Returns the maximum of two Money structs. Both money amounts must be of the same currency. Returns `{:ok, maximum_money}` or `{:error, reason}`. ```elixir # Example usage would involve creating two Money structs of the same currency ``` -------------------------------- ### Money.Subscription.Plan.to_string/2 Source: https://context7_llms Returns a localized string representation of a subscription plan. Accepts the plan and an optional keyword list of options. ```APIDOC ## POST /money/subscription/plan/to_string ### Description Returns a localized string representation of a subscription plan. Accepts the plan and an optional keyword list of options. ### Method POST ### Endpoint /money/subscription/plan/to_string ### Parameters #### Request Body - **plan** (Money.Subscription.Plan.t) - Required - The subscription plan to convert to a string. - **options** (keyword list) - Optional - A keyword list of options, see `Cldr.Unit.to_string/1` for available options. Example: `{"locale": ":ja", "style": ":narrow"}`. ### Request Example ```json { "plan": { "price": {"currency": "USD", "amount": 10}, "interval": "year", "interval_count": 1 }, "options": {"locale": "de", "style": "short"} } ``` ### Response #### Success Response (200) - **localized_string** (string) - The localized string representation of the plan. #### Error Response (400) - **reason** (any) - The reason for the conversion failure. #### Response Example ```json { "localized_string": "10.00 $/J" } ``` ``` -------------------------------- ### Generate Supervisor Child Specification Source: https://context7_llms Returns a specification for starting the Money.ExchangeRates.Retriever module under a supervisor. This is a standard pattern for OTP applications in Elixir, allowing the module to be managed by the supervision tree. ```elixir Money.ExchangeRates.Retriever.child_spec/1 ``` -------------------------------- ### Money.new!/3 Source: https://context7_llms Creates a %Money{} struct, raising an exception if the currency code is invalid. ```APIDOC ## POST /money/new! ### Description Creates a %Money{} struct from a currency code and an amount. This function will raise an exception if the currency code is invalid, unlike `Money.new/3`. ### Method POST ### Endpoint /money/new! ### Parameters #### Query Parameters - **currency_code** (string | atom) - Required - ISO4217 binary or atom currency code or ISO 24165 token identifier or shortname. - **amount** (integer | float | Decimal) - Required - The monetary amount. - **options** (keyword list) - Optional - Configuration options passed to `Money.new/3`. ### Request Example ```json { "currency_code": "EUR", "amount": 50.50 } ``` ### Response #### Success Response (200) - **money_struct** (%Money{}) - The created Money struct. #### Response Example ```json { "currency": "EUR", "amount": "50.50" } ``` #### Error Response (500) - **exception** (object) - Details of the exception raised, e.g., `Money.UnknownCurrencyError`. #### Error Response Example ```json { "exception": { "type": "Money.UnknownCurrencyError", "message": "Currency :XYZZ is not known" } } ``` ``` -------------------------------- ### Change Subscription Plan - Money.Subscription Source: https://context7_llms Demonstrates how to change a subscription plan. It covers scenarios with no proration, generating credit amounts, and generating credit periods. This function is used to transition a subscription from a current plan to a new one, with options for handling partial periods and calculating financial adjustments. ```elixir iex> current = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 1) iex> new = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 3) iex> Money.Subscription.change_plan current, new, current_interval_started: ~D[2018-01-01] {:ok, %Money.Subscription.Change{ carry_forward: Money.zero(:USD), credit_amount: Money.zero(:USD), credit_amount_applied: Money.zero(:USD), credit_days_applied: 0, credit_period_ends: nil, next_interval_starts: ~D[2018-05-01], first_billing_amount: Money.new(:USD, 10), first_interval_starts: ~D[2018-02-01] }} # Change during the current plan generates a credit amount iex> current = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 1) iex> new = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 3) iex> Money.Subscription.change_plan current, new, current_interval_started: ~D[2018-01-01], effective: ~D[2018-01-15] {:ok, %Money.Subscription.Change{ carry_forward: Money.zero(:USD), credit_amount: Money.new(:USD, "5.49"), credit_amount_applied: Money.new(:USD, "5.49"), credit_days_applied: 0, credit_period_ends: nil, next_interval_starts: ~D[2018-04-15], first_billing_amount: Money.new(:USD, "4.51"), first_interval_starts: ~D[2018-01-15] }} # Change during the current plan generates a credit period iex> current = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 1) iex> new = Money.Subscription.Plan.new!(Money.new(:USD, 10), :month, 3) iex> Money.Subscription.change_plan current, new, current_interval_started: ~D[2018-01-01], effective: ~D[2018-01-15], prorate: :period {:ok, %Money.Subscription.Change{ carry_forward: Money.zero(:USD), credit_amount: Money.new(:USD, "5.49"), credit_amount_applied: Money.zero(:USD), credit_days_applied: 50, credit_period_ends: ~D[2018-03-05], next_interval_starts: ~D[2018-06-04], first_billing_amount: Money.new(:USD, 10), first_interval_starts: ~D[2018-01-15] }} ``` -------------------------------- ### Get Known Tender Currencies Source: https://context7_llms Retrieves a list of all legal tender ISO 4217 currency codes. This function takes no arguments and returns a list of atoms representing currency codes. ```elixir iex> Money.Currency.known_tender_currencies() [:ADP, :AED, :AFA, :AFN, :ALK, :ALL, :AMD, :ANG, :AOA, :AOK, :AON, :AOR, :ARA, :ARL, :ARM, :ARP, :ARS, :ATS, :AUD, :AWG, :AZM, :AZN, :BAD, :BAM, :BAN, :BBD, :BDT, :BEC, :BEF, :BEL, :BGL, :BGM, :BGN, :BGO, :BHD, :BIF, :BMD, :BND, :BOB, :BOL, :BOP, :BOV, :BRB, :BRC, :BRE, :BRL, :BRN, :BRR, :BRZ, :BSD, :BTN, :BUK, :BWP, :BYB, :BYN, :BYR, :BZD, :CAD, :CDF, :CHE, :CHF, :CHW, :CLE, :CLF, :CLP, :CNH, :CNX, :CNY, :COP, :COU, :CRC, :CSD, :CSK, :CUC, :CUP, :CVE, :CYP, :CZK, :DDM, :DEM, :DJF, :DKK, :DOP, :DZD, :ECS, :ECV, :EEK, :EGP, :ERN, :ESA, :ESB, :ESP, :ETB, :EUR, :FIM, :FJD, :FKP, :FRF, :GBP, :GEK, :GEL, :GHC, :GHS, :GIP, :GMD, :GNF, :GNS, :GQE, :GRD, :GTQ, :GWE, :GWP, :GYD, :HKD, :HNL, :HRD, :HRK, :HTG, :HUF, :IDR, :IEP, :ILP, :ILR, :ILS, :INR, :IQD, :IRR, :ISJ, :ISK, :ITL, :JMD, :JOD, :JPY, :KES, :KGS, :KHR, :KMF, :KPW, :KRH, :KRO, :KRW, :KWD, :KYD, :KZT, :LAK, :LBP, :LKR, :LRD, :LSL, :LTL, :LTT, :LUC, :LUF, :LUL, :LVL, :LVR, :LYD, :MAD, :MAF, :MCF, :MDC, :MDL, :MGA, :MGF, :MKD, :MKN, :MLF, :MMK, :MNT, :MOP, :MRO, :MRU, :MTL, :MTP, :MUR, :MVP, :MVR, :MWK, :MXN, :MXP, :MXV, :MYR, :MZE, :MZM, :MZN, :NAD, :NGN, :NIC, :NIO, :NLG, :NOK, :NPR, :NZD, :OMR, :PAB, :PEI, :PEN, :PES, :PGK, :PHP, :PKR, :PLN, :PLZ, :PTE, :PYG, :QAR, :RHD, :ROL, :RON, :RSD, :RUB, :RUR, :RWF, :SAR, :SBD, :SCR, :SDD, :SDG, :SDP, :SEK, :SGD, :SHP, :SIT, :SKK, :SLE, :SLL, :SOS, :SRD, :SRG, :SSP, :STD, :STN, :SUR, :SVC, :SYP, :SZL, :THB, :TJR, :TJS, :TMM, :TMT, :TND, :TOP, :TPE, :TRL, :TRY, :TTD, :TWD, :TZS, :UAH, :UAK, :UGS, :UGX, :USD, :USN, :USS, :UYI, :UYP, :UYU, :UYW, :UZS, :VEB, :VED, :VEF, :VES, :VND, :VNN, :VUV, :WST, :XAF, :XAG, :XAU, :XBA, :XBB, :XBC, :XBD, :XCD, :XCG, :XDR, :XEU, :XFO, :XFU, :XOF, :XPD, :XPF, :XPT, :XRE, :XSU, :XTS, :XUA, :XXX, :YDD, :YER, :YUD, :YUM, :YUN, :YUR, :ZAL, :ZAR, :ZMK, :ZMW, :ZRN, :ZRZ, :ZWD, :ZWG, :ZWL, :ZWR] ``` -------------------------------- ### Get Known Historic Currencies Source: https://context7_llms Retrieves a list of all known historic ISO 4217 currency codes. This function does not require any arguments and returns a list of atoms representing currency codes. ```elixir iex> Money.Currency.known_historic_currencies() [:ADP, :AFA, :ALK, :AOK, :AON, :AOR, :ARA, :ARL, :ARM, :ARP, :ATS, :AZM, :BAD, :BAN, :BEC, :BEF, :BEL, :BGL, :BGM, :BGO, :BOL, :BOP, :BRB, :BRC, :BRE, :BRN, :BRR, :BRZ, :BUK, :BYB, :BYR, :CLE, :CNH, :CNX, :CSD, :CSK, :CYP, :DDM, :DEM, :ECS, :ECV, :EEK, :ESA, :ESB, :ESP, :FIM, :FRF, :GEK, :GHC, :GNS, :GQE, :GRD, :GWE, :GWP, :HRD, :IEP, :ILP, :ILR, :ISJ, :ITL, :KRH, :KRO, :LTL, :LTT, :LUC, :LUF, :LUL, :LVL, :LVR, :MAF, :MCF, :MDC, :MGF, :MKN, :MLF, :MRO, :MTL, :MTP, :MVP, :MXP, :MZE, :MZM, :NIC, :NLG, :PEI, :PES, :PLZ, :PTE, :RHD, :ROL, :RUR, :SDD, :SDP, :SIT, :SKK, :SLE, :SRG, :STD, :SUR, :TJR, :TMM, :TPE, :TRL, :UAK, :UGS, :USS, :UYP, :VEB, :VED, :VEF, :VNN, :XCG, :XEU, :XFO, :XFU, :XRE, :YDD, :YUD, :YUM, :YUN, :YUR, :ZAL, :ZMK, :ZRN, :ZRZ, :ZWD, :ZWG, :ZWR] ``` -------------------------------- ### Manage Exchange Rates Retriever Supervisor Source: https://context7_llms Provides functions to manage the starting, stopping, deleting, and restarting of the Exchange Rates Retriever. This module acts as an interface for controlling the retriever's lifecycle. ```elixir defmodule Money.ExchangeRates.Supervisor do # ... functions for managing the retriever ... end ``` -------------------------------- ### Money.ExchangeRates.OpenExchangeRates Source: https://context7_llms Implements the Money.ExchangeRates for the Open Exchange Rates service. ```APIDOC ## Money.ExchangeRates.OpenExchangeRates Module ### Description Implements the `Money.ExchangeRates` behaviour for the Open Exchange Rates service. ### Configuration The `:open_exchange_rates_app_id` configuration key must be set to your Open Exchange Rates App ID. This can be done in your application's configuration file. ```elixir config :ex_money, open_exchange_rates_app_id: "your_app_id" ``` Alternatively, it can be configured via an environment variable: ```elixir config :ex_money, open_exchange_rates_app_id: {:system, "OPEN_EXCHANGE_RATES_APP_ID"} ``` An alternative base URL for the service can also be configured using `:open_exchange_rates_url`: ```elixir config :ex_money, open_exchange_rates_app_id: "your_app_id", open_exchange_rates_url: "https://openexchangerates.org/alternative_api" ``` ### Functions #### `get_historic_rates(date, config)` Retrieves the historic exchange rates from the Open Exchange Rates site. * `date`: A date struct with `:year`, `:month`, and `:day` elements. * `config`: The retrieval configuration. Typically the result of `Money.ExchangeRates.config/0`. Returns: * `{:ok, rates}` on success. * `{:error, reason}` on failure. #### `get_latest_rates(config)` Retrieves the latest exchange rates from the Open Exchange Rates site. * `config`: The retrieval configuration. Typically the result of `Money.ExchangeRates.config/0`. Returns: * `{:ok, rates}` on success. * `{:error, reason}` on failure. ``` -------------------------------- ### Dets Cache Implementation Historic Rates (Elixir) Source: https://context7_llms Callback implementation for `Money.ExchangeRates.Cache.historic_rates/1` using the :dets backend. ```elixir Money.ExchangeRates.Cache.Dets.historic_rates(date) ``` -------------------------------- ### Get Currency Code as Atom Source: https://context7_llms Extracts the currency code from a Money struct and returns it as an atom. This is useful for identifying the currency type of a monetary value. It requires a valid Money struct as input. ```elixir iex> m = Money.new("USD", 100) iex> Money.to_currency_code(m) :USD ``` -------------------------------- ### Configure OpenExchangeRates App ID in Elixir Source: https://context7_llms Demonstrates how to configure the Open Exchange Rates integration in Elixir. This includes setting the `open_exchange_rates_app_id` and optionally an alternative API URL. ```elixir config :ex_money, open_exchange_rates_app_id: "your_app_id" config :ex_money, open_exchange_rates_app_id: {:system, "OPEN_EXCHANGE_RATES_APP_ID"} config :ex_money, open_exchange_rates_app_id: "your_app_id", open_exchange_rates_url: "https://openexchangerates.org/alternative_api" ``` -------------------------------- ### Get Historic Exchange Rates from OpenExchangeRates API in Elixir Source: https://context7_llms Fetches historical exchange rates from the Open Exchange Rates service for a specified date. It requires the date and configuration, returning a success or error tuple. ```elixir def get_historic_rates(date, config) do # Implementation to fetch historic rates from OpenExchangeRates # Returns {:ok, rates} or {:error, reason} end ``` -------------------------------- ### Delete Retriever Child Specification from Supervisor Source: https://context7_llms Deletes the retriever's child specification from the exchange rates supervisor. This is useful for reconfiguring the retriever after it has been stopped and before it is restarted. The typical sequence is stop, delete, then start with new configuration. ```elixir iex> Money.ExchangeRates.Retriever.stop iex> Money.ExchangeRates.Retriever.delete iex> Money.ExchangeRates.Retriever.start(config) ``` -------------------------------- ### Define Subscription Plan Structure - Elixir Source: https://context7_llms Defines the structure for a standard subscription plan, including its price, interval, and interval count. The `new/3` function creates a plan, returning an :ok tuple with the plan details or an :error tuple if the definition is invalid. The `new!/3` variant raises an exception on error. ```Elixir iex> Money.Subscription.Plan.new Money.new(:USD, 100), :month, 1 {:ok, %Money.Subscription.Plan{ interval: :month, interval_count: 1, price: Money.new(:USD, 100) }} iex> Money.Subscription.Plan.new Money.new(:USD, 100), :month {:ok, %Money.Subscription.Plan{ interval: :month, interval_count: 1, price: Money.new(:USD, 100) }} iex> Money.Subscription.Plan.new Money.new(:USD, 100), :day, 30 {:ok, %Money.Subscription.Plan{ interval: :day, interval_count: 30, price: Money.new(:USD, 100) }} iex> Money.Subscription.Plan.new 23, :day, 30 {:error, {Money.Invalid, "Invalid subscription plan definition"}} iex> Money.Subscription.Plan.new! Money.new(:USD, 100), :day, 30 %Money.Subscription.Plan{ interval: :day, interval_count: 30, price: Money.new(:USD, 100) } ``` -------------------------------- ### Get Latest Exchange Rates from OpenExchangeRates API in Elixir Source: https://context7_llms Retrieves the most current exchange rates from the Open Exchange Rates service. It requires configuration, typically provided by `Money.ExchangeRates.config/0`, and returns a tuple indicating success or failure. ```elixir def get_latest_rates(config) do # Implementation to fetch latest rates from OpenExchangeRates # Returns {:ok, rates} or {:error, reason} end ``` -------------------------------- ### Compare Minimum Money Values with Money.min/2 Source: https://context7_llms Compares two Money values and returns the smaller one. It returns {:ok, minimum_money} for matching currencies and {:error, reason} for differing currencies. ```elixir iex> Money.min(Money.new(:USD, 200), Money.new(:USD, 300)) {:ok, Money.new(:USD, 200)} iex> Money.min(Money.new(:USD, 200), Money.new(:AUD, 200)) {:error, {ArgumentError, "Cannot compare monies with different currencies. Received :USD and :AUD."}} ``` -------------------------------- ### Get Latest Exchange Rates (Elixir) Source: https://context7_llms Retrieves the most recent exchange rates from the configured service. It looks up rates in an ETS table and uses `Money.ExchangeRates.Retriever.latest_rates/0` for actual retrieval. Returns `{:ok, rates}` on success or `{:error, reason}` on failure. ```elixir Money.ExchangeRates.latest_rates() ``` -------------------------------- ### Money.ExchangeRates.Retriever.config/0 Source: https://context7_llms Retrieves the current configuration of the Exchange Rates Retrieval service. ```APIDOC ## Money.ExchangeRates.Retriever.config/0 ### Description Return the current configuration of the Exchange Rates Retrieval service. ### Parameters None ### Request Example ```elixir Money.ExchangeRates.Retriever.config() ``` ### Response #### Success Response - `:configuration` (map) - The current configuration map for the exchange rates service. #### Response Example ```elixir %{retrieve_every: 300_000, module: Money.ExchangeRates.OpenExchangeRates, ...} ``` ``` -------------------------------- ### Get Decimal Amount from Money Source: https://context7_llms Retrieves the monetary amount from a Money struct as a Decimal type. This function is useful when you need to perform precise arithmetic operations on the monetary value. It takes a Money struct as input and returns a Decimal. ```elixir iex> m = Money.new("USD", 100) iex> Money.to_decimal(m) Decimal.new(100) ``` -------------------------------- ### Get Absolute Value of Money - Elixir Source: https://context7_llms Calculates the absolute value of a given monetary amount. It takes a `t:Money.t/0` type as input and returns a `t:Money.t/0` with a positive sign for the amount. This function ensures the amount is always positive, regardless of the original sign. ```Elixir iex> m = Money.new("USD", -100) iex> Money.abs(m) Money.new(:USD, "100") ``` -------------------------------- ### Money.Currency.known_historic_currencies/0 Source: https://context7_llms Retrieves a list of historic ISO 4217 currency codes. ```APIDOC ## Money.Currency.known_historic_currencies/0 ### Description Returns the list of historic ISO 4217 currency codes. ### Method `Money.Currency.known_historic_currencies()` ### Parameters None ### Request Example ```elixir Moneys.Currency.known_historic_currencies() ``` ### Response #### Success Response (200) A list of atoms representing historic ISO 4217 currency codes. #### Response Example ```json ["XFO", "XFU", "SUR"] ``` ``` -------------------------------- ### Set Fractional Part of Money - Elixir Source: https://context7_llms Sets the fractional part of a Money struct. The provided fraction must be an integer and compatible with the currency's decimal digit count. For example, a currency with 2 decimal digits can only accept fractions up to 99. ```elixir # Assuming a currency with 2 decimal digits # money = Money.new(:USD, "100") # Money.put_fraction(money, 50) # Sets the fraction to 50 # Money.put_fraction(money, 150) # This would raise an error if USD has only 2 decimal digits ``` -------------------------------- ### Create Money Struct with new/3 Source: https://context7_llms Creates a %Money{} struct from a currency code and amount. Handles various input types for amount and supports locale-specific parsing. Raises Money.UnknownCurrencyError for invalid currency codes and Money.InvalidAmountError for unsupported amount types like floats. ```elixir iex> Money.new(:USD, 100) Money.new(:USD, "100") iex> Money.new(100, :USD) Money.new(:USD, "100") iex> Money.new("USD", 100) Money.new(:USD, "100") iex> Money.new("thb", 500) Money.new(:THB, "500") iex> Money.new("EUR", Decimal.new(100)) Money.new(:EUR, "100") iex> Money.new(:EUR, "100.30") Money.new(:EUR, "100.30") iex> Money.new(:EUR, "100.30", fractional_digits: 4) Money.new(:EUR, "100.30", fractional_digits: 4) iex> Money.new(:XYZZ, 100) {:error, {Money.UnknownCurrencyError, "The currency :XYZZ is invalid"}} iex> Money.new("1.000,99", :EUR, locale: "de") Money.new(:EUR, "1000.99") iex> Money.new 123.445, :USD {:error, {:Money.InvalidAmountError, "Float amounts are not supported in new/2 due to potenial " <> "rounding and precision issues. If absolutely required, " <> "use Money.from_float/2"}} ```