Use this package to convert prices from one currency to another by the exchange rate using a base currency.
You can install the package via composer:
composer require gnahotelsolutions/currency-converter
Before anything, you need to create a repository of currencies to be loaded into the Converter
.
A currency needs a name
, exchange rate
and decimals
to be shown after the conversion.
$repository = new CurrenciesRepository([
new Currency('EUR', 1, 2),
new Currency('USD', 1.1, 2),
// ...
]);
When declaring a Converter
, you'll also have to tell what's your base currency from where the exchange rates are calculated.
$baseCurrency = new Currency('EUR', 1, 2);
$converter = new Converter($baseCurrency, $repository);
Once your Converter
is ready, you can transform a Price
using the fluent interface. The result will be a new Price
instance with the converted amount and the desired currency
$price = new Price(1000, 'EUR');
$converter->from($price)->to('USD')->convert(); // new Price(1100, 'USD')
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.