National Bank of Georgia (NBG) currency service API wrapper in PHP
Install this package via Composer.
composer require stichoza/nbg-currency
The class is namespaced as Stichoza\NbgCurrency\NbgCurrency
, so use it like
use Stichoza\NbgCurrency\NbgCurrency;
This package is very easy to use and has a few methods. Keep in mind that method names are not same as NBG's SOAP service. This package has more intuitive method names.
In addition, currencies are not case-sensitive here.
Get the currency rate.
NbgCurrency::rate('usd'); // 2.3966
Get the rate difference.
NbgCurrency::diff('usd'); // 0.0017
Currency rate change. -1
if decreased, 0
if unchanged and 1
if increased.
NbgCurrency::change('usd'); // 1
Get the description of currency rate.
NbgCurrency::description('eek'); // 10 αα‘α’ααα£α α αα ααα
Get the date of currency rates. Returns Carbon object representing the date. All carbon methods are available on this object.
NbgCurrency::date(); // 2016-01-01 00:00:00
NbgCurrency::date()->format('j F Y'); // 1 January 2016
NbgCurrency::date()->diffForHumans(); // 2 days ago
NbgCurrency::date()->isPast(); // true
// etc.
This method returns an object containing all data described above.
$currency = NbgCurrency::get('usd');
$currency->date->format('j F Y'); // 1 January 2016
$currency->rate; // 2.3966
$currency->diff; // 0.0017
// etc.
Check if the currency is supported.
NbgCurrency::isSupported('usd'); // true
NbgCurrency::isSupported('lol'); // false
Some methods (get
, rate
, description
, change
, diff
) are available to call fluently like so:
NbgCurrency::rateUsd(); // same as NbgCurrency::rate('usd');
NbgCurrency::ratePln(); // same as NbgCurrency::rate('pln');
NbgCurrency::diffEur(); // same as NbgCurrency::diff('eur');
NbgCurrency::getUah(); // same as NbgCurrency::get('uah');
// etc.
Each method call maps to a SOAP web service method. So it's better to remember a rate in a variable or even store a result in a cache if possible.
$dollars = [199, 340.5, 230.25, 30, 78.99];
$usdRate = NbgCurrency::rateUsd();
foreach ($dollars as $d) {
echo $d * $usdRate;
}
$dollars = [199, 340.5, 230.25, 30, 78.99];
foreach ($dollars as $d) {
echo $d * NbgCurrency::rateUsd();
}
ααα αα‘ αα£α α‘α, αα αααα£αα αααααα‘ αααͺααααα αα£α α‘α, αααα£α’α, ααα αα‘ αααα£α’αα‘ αα£α α‘α, laris kursi, laris valuta, lari currency, national bank of georgia, nbg