nbg-currency icon indicating copy to clipboard operation
nbg-currency copied to clipboard

๐Ÿ’ต National Bank of Georgia (NBG) currency service API wrapper in PHP

NBG Currency

Build Status Latest Stable Version Total Downloads

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