awais69735/multi-currency

Multi-currency transaction library for Laravel

Maintainers

Package info

github.com/awais69735/multi-currency

pkg:composer/awais69735/multi-currency

Transparency log

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.0 2026-08-05 16:20 UTC

This package is auto-updated.

Last update: 2026-08-05 16:21:03 UTC


README

A robust, production-ready multi-currency transaction library for Laravel.

Handle exchange rate fetching, currency conversion, database fallback, caching, user preferences, and more with a clean and simple API.

Latest Version Downloads License

๐Ÿ“ฆ Packagist: https://packagist.org/packages/awais69735/multi-currency

๐Ÿ’ป GitHub: https://github.com/awais69735/multi-currency

โœจ Features

  • โœ… Convert any amount between currencies
  • โœ… Fetch live exchange rates using Fixer.io (supports custom providers)
  • โœ… Cache exchange rates for improved performance
  • โœ… Database fallback when the API is unavailable
  • โœ… Store exchange rates automatically
  • โœ… Daily Artisan command to refresh rates
  • โœ… User preferred currency middleware
  • โœ… Global helper functions
  • โœ… Facade support
  • โœ… Configurable base currency
  • โœ… Laravel 9, 10, 11 & 12 compatible

๐Ÿ“‹ Requirements

  • PHP 8.0+
  • Laravel 9.x
  • Laravel 10.x
  • Laravel 11.x
  • Laravel 12.x

๐Ÿ“ฆ Installation

Install the package using Composer.

composer require awais69735/multi-currency

Publish the configuration file and migrations.

php artisan vendor:publish --provider="Awais69735\MultiCurrency\Providers\MultiCurrencyServiceProvider"

Run the migrations.

php artisan migrate

โš™๏ธ Configuration

Add the following variables to your .env file.

# Base currency
MULTI_CURRENCY_BASE=USD

# Cache duration (seconds)
MULTI_CURRENCY_CACHE_TTL=3600

# Fixer.io API Key
FIXER_API_KEY=your_fixer_api_key

# Free Fixer accounts only support EUR
FIXER_API_BASE=EUR

# Enable database fallback
MULTI_CURRENCY_DATABASE_FALLBACK=true

You may also edit the published configuration file:

config/multi_currency.php

๐Ÿš€ Usage

Basic Conversion

use Awais69735\MultiCurrency\Facades\Currency;

// Convert 100 EUR to USD
$usdAmount = Currency::convert(100, 'EUR', 'USD');

// Get exchange rate
$rate = Currency::getExchangeRate('GBP', 'JPY');

// Historical conversion
$oldAmount = Currency::convert(
    100,
    'USD',
    'GBP',
    new DateTime('2023-01-01')
);

Global Helper Functions

Instead of using the facade, you may use the built-in helpers.

Convert Currency

$usd = currency_convert(
    100,
    'EUR',
    'USD'
);

Get Exchange Rate

$rate = exchange_rate(
    'GBP',
    'JPY'
);

Convert to User Currency

$userAmount = currency_convert_to_user(
    100,
    'USD'
);

Currency Symbol

$symbol = currency_symbol('USD');

// $

๐Ÿ‘ค User Preferred Currency

The package includes middleware that automatically detects the user's preferred currency.

For Laravel 11+, register it in bootstrap/app.php.

use Awais69735\MultiCurrency\Middleware\SetUserCurrency;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(SetUserCurrency::class);
})

For Laravel 10 and below, register it inside:

app/Http/Kernel.php

The middleware checks:

  1. auth()->user()->preferred_currency
  2. session('user_currency')
  3. config('multi_currency.base_currency')

Retrieve the current user's currency:

$userCurrency = app('user_currency');

Convert automatically:

$userAmount = currency_convert_to_user(
    $amount,
    'USD'
);

๐Ÿ›  Artisan Command

Refresh exchange rates manually.

php artisan currency:refresh

Available Options

php artisan currency:refresh --base=USD
php artisan currency:refresh --date=2025-12-31

Scheduling

Automatically refresh exchange rates every day.

protected function schedule(Schedule $schedule)
{
    $schedule
        ->command('currency:refresh')
        ->daily();
}

๐Ÿ’พ Database Fallback

When the external exchange rate provider is unavailable, the package automatically loads the most recent stored rates from the database.

Database fallback is enabled by default.

Disable it by setting:

MULTI_CURRENCY_DATABASE_FALLBACK=false

Exchange rates are stored every time a successful API request is made.

โšก Caching

Exchange rates are cached automatically to minimize API requests.

Configuration:

MULTI_CURRENCY_CACHE_TTL=3600

Cache key format:

mc_rates_{base}_{date}

The cache is automatically cleared whenever rates are refreshed.

๐Ÿ”Œ Custom Rate Providers

You can replace the default provider by implementing:

RateProviderInterface

Bind your implementation inside a service provider.

$this->app->bind(
    \Awais69735\MultiCurrency\Contracts\RateProviderInterface::class,
    \App\Services\MyCustomRateProvider::class
);

This allows integration with providers such as:

  • Fixer.io
  • ExchangeRate.host
  • Open Exchange Rates
  • CurrencyLayer
  • Any custom API

๐Ÿงช Testing

Run the package tests.

vendor/bin/phpunit

๐Ÿ—บ Roadmap

  • โœ… Currency conversion
  • โœ… Exchange rate caching
  • โœ… Database fallback
  • โœ… Artisan refresh command
  • โœ… User preferred currency
  • โœ… Global helper functions
  • โณ Historical rate caching improvements
  • โณ Multiple provider auto-failover
  • โณ Crypto currency support
  • โณ Exchange rate events
  • โณ Queue support for background refresh

๐Ÿค Contributing

Contributions are welcome.

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push the branch
  5. Open a Pull Request

๐Ÿ“„ License

This package is open-source software licensed under the MIT License.

๐Ÿ‘จโ€๐Ÿ’ป Author

Awais Ali

GitHub: https://github.com/awais69735

๐Ÿ™ Credits

  • Fixer.io for exchange rate services
  • Laravel Community

๐Ÿ’ฌ Support

If you discover a bug or have a feature request, please open an issue on the GitHub repository.