umpirsky / locurro
Local currency converter.
Requires
- php: >=5.4
- florianv/swap: ^2.2
- geoip2/geoip2: ^2.3
- mathiasverraes/money: ^1.2
- willdurand/geocoder: ^3.0
- zf1/zend-currency: ^1.12
- zf1/zend-locale: ^1.12
Requires (Dev)
- doctrine/cache: ^1.4
- phpspec/phpspec: ^2.2
- twig/twig: ^1.21
Suggests
- doctrine/cache: ^1.4
- twig/twig: ^1.21
This package is not auto-updated.
Last update: 2024-12-19 01:08:12 UTC
README
symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliterator
Locurro
💶 Local currency converter.
Use Case
Imagine you have an online store, and you are selling products in many different countries. Some of your buyers might live in country that uses currency other then one you use in your store. It would be cool to give them estimation of product costs in their domestic currency.
Here is one example of showing approximate price under the brackets:
And it automatically detects users default currency based on their IP address for example.
Pretty cool, huh? 😄
Basic Usage
Convert based on currency
<?php /* @var $converter Locurro\Converter\Currency */ $converter->convert( new Money\Money(100, new Money\Currency('EUR')), new Money\Currency('RSD') );
Full example in examples/currency.php.
Convert based on locale
<?php /* @var $converter Locurro\Converter\Locale */ $converter->convert( new Money\Money(100, new Money\Currency('EUR')), 'sr-Cyrl-RS' );
Full example in examples/locale.php.
Convert based on country
<?php /* @var $converter Locurro\Converter\Country */ $converter->convert( new Money\Money(100, new Money\Currency('EUR')), 'RS' );
Full example in examples/country.php.
Convert based on IP address
<?php /* @var $converter Locurro\Converter\IpAddress */ $converter->convert( new Money\Money(100, new Money\Currency('EUR')), '109.92.115.78' );
Full example in examples/ip.php.
Advanced Usage
Chaining providers
Locurro uses Swap library for exchange rates.
There are multiple exchange rate providers supported:
- European Central Bank Supports only EUR as base currency.
- Google Finance Supports multiple currencies as base and quote currencies.
- Open Exchange Rates Supports only USD as base currency for the free version and multiple ones for the enterprise version.
- Xignite
You must have access to the
XigniteGlobalCurrencies
API. Supports multiple currencies as base and quote currencies. - Yahoo Finance Supports multiple currencies as base and quote currencies.
- WebserviceX Supports multiple currencies as base and quote currencies.
- National Bank of Romania Supports only RON as base currency.
Array
Retrieves rates from a PHP array.
You can chain them, see example in examples/ip-chained.php.
Caching
You can cache exchange rates using Doctrine cache or Illuminate cache.
Example is available in examples/ip-cached.php.
Twig integration
There is a Twig extension provded in the source code.