nbg-currency
nbg-currency copied to clipboard
๐ต National Bank of Georgia (NBG) currency service API wrapper in PHP
NBG Currency
National Bank of Georgia (NBG) currency service API wrapper in PHP
Installation
Install this package via Composer.
composer require stichoza/nbg-currency
Note: PHP 7.1.8 or later is required. For older versions, use
^1.2
version of this package.
Usage
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.
Methods
rate($currency)
Get the currency rate.
NbgCurrency::rate('usd'); // 2.3966
diff($currency)
Get the rate difference.
NbgCurrency::diff('usd'); // 0.0017
change($currency)
Currency rate change. -1
if decreased, 0
if unchanged and 1
if increased.
NbgCurrency::change('usd'); // 1
description($currency)
Get the description of currency rate.
NbgCurrency::description('eek'); // 10 แแกแขแแแฃแ แ แแ แแแ
date()
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.
get($currency)
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.
isSupported($currency)
Check if the currency is supported.
NbgCurrency::isSupported('usd'); // true
NbgCurrency::isSupported('lol'); // false
Fluent Methods
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.
General Recommendations
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.
DO:
$dollars = [199, 340.5, 230.25, 30, 78.99];
$usdRate = NbgCurrency::rateUsd();
foreach ($dollars as $d) {
echo $d * $usdRate;
}
DO NOT:
$dollars = [199, 340.5, 230.25, 30, 78.99];
foreach ($dollars as $d) {
echo $d * NbgCurrency::rateUsd();
}
Keywords
แแแ แแก แแฃแ แกแ, แแ แแแแฃแแ แแแแแแก แแแชแแแแแ แแฃแ แกแ, แแแแฃแขแ, แแแ แแก แแแแฃแขแแก แแฃแ แกแ, laris kursi, laris valuta, lari currency, national bank of georgia, nbg