Download the PHP package brightcreations/money-converter without Composer

On this page you can find all versions of the php package brightcreations/money-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package money-converter

Money Converter

A Laravel package for converting money between currencies using stored exchange rates and Brick Money.

Downloads License Last Commit Stars

Overview

brightcreations/money-converter converts amounts between currencies in minor units (cents). It reads rates from your database (populated by brightcreations/exchange-rates) and supports current, fresh, historical, interpolated, and extrapolated conversions.

Requirements

Dependency Version
PHP >=8.1
Laravel 10, 11, 12, or 13 (database component; Laravel 13 needs PHP 8.3+)
brightcreations/exchange-rates ^0.9.0, ^0.10.0, or ^0.11.0 (Laravel 13 needs ^0.11.0)

Installation

Both packages auto-register their service providers.

Integration guide

Follow these steps to go from zero to a working conversion.

1. Publish exchange-rates config and migrations

2. Configure exchange-rate API keys

Add provider credentials to .env. See the exchange-rates installation guide for full details.

3. Publish money-converter config

4. Populate exchange rates

Load rates into the database using either approach:

5. Convert

Configuration

Published to config/money-converter.php.

Key Default Description
default_provider PDO builder Brick ExchangeRateProvider used for current/fresh conversion (ExchangeRateProvidersEnum::PDO)
proxy_currency_code USD Base currency for historical proxy cross-rates when a direct pair is missing
rounding_mode RoundingMode::DOWN Brick rounding when converting to minor units
exchange_rates.pdo.table currency_exchange_rates Same table written by exchange-rates
exchange_rates.pdo.column exchange_rate Rate column
exchange_rates.pdo.source_currency_column base_currency_code Source currency column
exchange_rates.pdo.target_currency_column target_currency_code Target currency column
exchange_rates.configurable.rates see config file Base → target rate map for local dev (no DB)

Environment overrides: EXCHANGE_RATE_DB_TABLE, EXCHANGE_RATE_DB_COLUMN, EXCHANGE_RATE_DB_SOURCE_CURRENCY_COLUMN, EXCHANGE_RATE_DB_TARGET_CURRENCY_COLUMN.

PDO column names must match the exchange-rates schema.

Local development without a database

Set default_provider to the configurable builder class so Brick reads static rates from config:

Edit exchange_rates.configurable.rates in config/money-converter.php to add or change pairs. This provider is intended for local/testing only; production should use PDO with exchange-rates populated data.

Usage

Minor units

All amounts are in minor units (cents, pence, etc.):

Input Meaning
10000 with USD 100.00 USD
5000 with EUR 50.00 EUR

Same-currency conversion returns the input unchanged.

Basic conversion

Resolving the service

Constructor injection

Container

Facade

Note: MoneyConverter is registered as a singleton, but fluent methods (fetchOnFail(), extrapolate(), interpolate(), etc.) return a new configured instance and do not mutate the shared singleton. The optional $on_fail argument on convert() is also scoped to that call only.

API reference

Conversion methods

Method Description
convert($money, $from, $to, $dateTime = null, $onFail = null, $options = null) Routes to current, fresh, or historical conversion based on date and flags
convertCurrent($money, $from, $to, $options = null) Uses rates in the database (PDO provider)
convertFresh($money, $from, $to, $options = null) Fetches fresh rates via exchange-rates, then converts
convertToday($money, $from, $to, $options = null) Historical conversion at today's startOfDay()
convertHistorical($money, $from, $to, $dateTime, $options = null) Historical fallback chain (see below)
convertWithResult($money, $from, $to, $dateTime = null, $onFail = null, $options = null) Same routing as convert() but returns MoneyConversionResult (amount, rate, strategy, provider)
convertBulk(ConversionItem[] $items, $options = null) Batch conversion; returns int[] in input order
convertBulkWithResult(ConversionItem[] $items, $options = null) Batch conversion with metadata per item

ConversionItem accepts amount, from, to, and optional date for historical rows.

Fluent methods

Method Description
extrapolate(bool $enable = true) Nearest-neighbour rate when target is outside stored date range; returns a new instance
interpolate(bool $enable = true) Linear interpolation between two bounding historical rates; returns a new instance
needsFresh(bool $enable = true) Route convert() without a date through convertFresh(); returns a new instance
throwOnFail() Throw on conversion failure (default); returns a new instance
fetchOnFail() Fetch rates from API on failure where the provider supports it; returns a new instance
isThrowOnFail() / isFetchOnFail() Inspect current failure mode
withOptions(MoneyConverterOptions $options) Return a new instance with the given options object

Options object

For explicit per-call configuration without a fluent chain, pass a MoneyConverterOptions instance:

Set application-wide defaults in config/money-converter.php:

MoneyConverter reads these when resolved from the container. Per-call $options or fluent methods override them.

Precedence for convert() / convertWithResult():

  1. Explicit $on_fail argument (when non-null) overrides options->onFail for that call
  2. $options argument (when non-null) overrides instance options
  3. Instance options from fluent methods or withOptions()
  4. Config default_options (constructor baseline)

Audit events

After each successful conversion, the package dispatches BrightCreations\MoneyConverter\Events\ConversionPerformed (one event per bulk item). Listeners are registered from config/money-converter.php; the default includes LogConversionPerformed, which writes an info log with input/output amounts, currencies, rate, strategy, and provider.

Disable event dispatch via .env:

Configure listeners in config/money-converter.php (remove LogConversionPerformed to turn off package logging, or add your own):

Or in your app's EventServiceProvider:

Constants

Constant Value Meaning
ON_FAIL_THROW_EXCEPTION 1 Throw MoneyConversionException on failure
ON_FAIL_FETCH_EXCHANGE_RATES 2 Attempt to fetch rates before failing

Pass as the fifth argument to convert() to temporarily set failure mode:

Historical conversion

Historical conversion runs a fallback chain: exact DB lookup → optional API fetch (fetchOnFail()) → proxy-currency cross-rate → optional interpolate() → optional extrapolate().

Datetime semantics

fetchOnFail() and providers

When fetchOnFail() is set, historical conversion attempts an API fetch after a DB miss. Behaviour depends on your exchange-rates provider:

Provider Auto-fetch on historical miss Granularity
Open Exchange Rates Yes Daily
Exchange Rate API Yes Daily
World Bank No (DB only) Yearly

For World Bank or DB-only setups, run php artisan exchange-rates:backfill to populate historical data.

interpolate() and extrapolate()

Exceptions

Exception When
MoneyConversionException Conversion fails after all strategies are exhausted, or a non-recoverable error occurs in a convert method
InvalidArgumentException Invalid $on_fail value passed to convert() (must be ON_FAIL_THROW_EXCEPTION or ON_FAIL_FETCH_EXCHANGE_RATES)

MoneyConversionException wraps the underlying cause when applicable (e.g. missing rate, unsupported historical provider).

Rate sourcing

money-converter does not fetch exchange rates on its own for day-to-day storage — that is handled by brightcreations/exchange-rates. Install and configure exchange-rates to populate currency_exchange_rates and currency_exchange_rates_history, then use money-converter to convert.

Contributing

Contributions are welcome. Please open an issue or pull request on GitHub.

License

MIT License. See LICENSE.

Author

Kareem Mohamed — Bright Creations


All versions of money-converter with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
illuminate/support Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/http Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/console Version ^10.0 || ^11.0 || ^12.0 || ^13.0
brick/money Version ^0.10.1
brick/math Version ^0.12.0 || ^0.13.0 || ^0.14.0
brightcreations/exchange-rates Version ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brightcreations/money-converter contains the following files

Loading the files please wait ...