Dont worry about your favorite service suddenly shutting down or switching plans on you. Switch away easily.
- FixerIO = fixerio
CurrencyLayercoming soon = currencylayerOpen Exchange Ratescoming soon = open_exchange_ratesjson ratescoming soon = json_ratesCurrency Converter APIcoming soon = currency_converter_api
You just require using composer and you're good to go!
composer require rackbeat/php-currency-api
If you're using Laravel, a service provider and facade is included to provide configuration of driver etc.
$api = Rackbeat\Currency\API::make('fixerio'); // driver from supported drivers.
$api->setBase(Rackbeat\Currency\Symbol::USD);
$api->setSymbols([ Rackbeat\Currency\Symbol::DKK, Rackbeat\Currency\Symbol::EUR, Rackbeat\Currency\Symbol::USD ]);
Please note, you are not required to use Rackbeat\Currency\Symbol
to specify symbols. It's simply a convenience helper.
$api->get(); // Get latest rates for selected symbols, using set base currency
$api->get('DKK'); // Get latest rates for selected symbols, using DKK as base currency
$api->convert($fromCurrency = 'DKK', $toCurrency = 'EUR', 10.00); // Convert 10 DKK to EUR
$api->historical($date = '2018-01-01'); // Get currency rate for base on 1st of January 2018
$api->historical($date = '2018-01-01', 'GBP'); // Get currency rate for GBP on 1st of January 2018
... todo
- PHP >= 7.1
- Possibly a paid plan for your desired API. Check their pricing.