currency-converter
Simple API for currency converting., (*1)
Currently using ECB currency rates service.
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml, (*2)
Instalation:
composer require ineersa/converter
, (*3)
Features:
- results caching
- easy to extend
- fast?
Examples of usage:
Basic usage:, (*4)
use Ineersa\Converter\Converter;
use Ineersa\Converter\Services\EcbService;
$converter = new Converter(new EcbService());
echo $converter->convert('USD','RUB',100);
Get available currencies list:, (*5)
$service = new EcbService();
$service->getCurrenciesList();
Get single currency rate for euro:, (*6)
$service = new EcbService();
echo $service->getRate('USD');
You can control what client, adapter or cache you want to use via service. For example:, (*7)
$cache = new MemcacheCache();
$service = new EcbService($cache);
echo $service->getRate('USD');
To get appp_id token visit openexchangerates and sign up., (*8)
Free plan exists (1000 requests per month), which is fairly enough for simple usage., (*9)
Examples of usage:
Basic usage:, (*10)
$service = new OpenExchangeRatesService();
$service->getClient()->setAppId('YOUR_APP_ID_TOKEN');
$converter = new Converter($service);
echo $converter->convert('USD','RUB',1);
Specific features for paid plans:, (*11)
$service = new OpenExchangeRatesService();
$service->getClient()->setAppId('YOUR_APP_ID_TOKEN');
$service->getClient()->setBase('EUR');//You can control your base currency
$service->getClient()->setSymbols('EUR,USD,RUB');//You can control what currencies you need in response
$converter = new Converter($service);
echo $converter->convert('USD','RUB',1);
By default Memcached, Guzzle used. To use your own, implement appropriate interfaces., (*12)
Demo, (*13)