Skip to content

umpirsky/locurro

Repository files navigation

symfony upgrade fixertwig gettext extractorwisdomcentipedepermissions handlerextraloadgravatarlocurrocountry listtransliterator

Locurro Build Status

💶 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:

us fr

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.

About

💶 Local currency converter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages