PHPackages                             orkhanahmadov/cbar-currency - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. orkhanahmadov/cbar-currency

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

orkhanahmadov/cbar-currency
===========================

PHP library to work with cbar.az currency rates

1.5.0(3y ago)83393MITPHPPHP ^7.3|^8.0CI failing

Since May 3Pushed 3y ago1 watchersCompare

[ Source](https://github.com/orkhanahmadov/cbar-currency)[ Packagist](https://packagist.org/packages/orkhanahmadov/cbar-currency)[ Docs](https://github.com/orkhanahmadov/cbar-currency)[ GitHub Sponsors](https://github.com/orkhanahmadov)[ RSS](/packages/orkhanahmadov-cbar-currency/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (3)Versions (7)Used By (0)

💵 PHP library to work with [CBAR](https://www.cbar.az/home?language=en) currency rates
======================================================================================

[](#dollar-php-library-to-work-with-cbar-currency-rates)

[![Latest Stable Version](https://camo.githubusercontent.com/ad3d0eee3b2ebd33eac61f19ab855e84845e282fa4eaaf40736688d0855f4856/68747470733a2f2f706f7365722e707567782e6f72672f6f726b68616e61686d61646f762f636261722d63757272656e63792f762f737461626c65)](https://packagist.org/packages/orkhanahmadov/cbar-currency)[![Latest Unstable Version](https://camo.githubusercontent.com/0ce503266941baaf120da41c3e77a347165b4aa658f6b9c40fe2277d0665ebe5/68747470733a2f2f706f7365722e707567782e6f72672f6f726b68616e61686d61646f762f636261722d63757272656e63792f762f756e737461626c65)](https://packagist.org/packages/orkhanahmadov/cbar-currency)[![Total Downloads](https://camo.githubusercontent.com/ed2675f0abd0497dc3ce60e91bed1eb3fd7ad9d68e31dd31481c969b61e47994/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f726b68616e61686d61646f762f636261722d63757272656e6379)](https://packagist.org/packages/orkhanahmadov/cbar-currency)[![GitHub license](https://camo.githubusercontent.com/a350feb75c9a3aa0bc33a4f9e9b1c2257e4f78228204acf59948cb4137b6c503/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f726b68616e61686d61646f762f636261722d63757272656e63792e737667)](https://github.com/orkhanahmadov/cbar-currency/blob/master/LICENSE.md)

[![Build Status](https://camo.githubusercontent.com/dafbca4b60f65b06c6356401d56121cd58514222c0076fe9b373262422d02bd7/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6f726b68616e61686d61646f762f636261722d63757272656e63792e737667)](https://travis-ci.org/orkhanahmadov/cbar-currency)[![Test Coverage](https://camo.githubusercontent.com/289189328edd119caaac33f19923afe4c4b8cd8dc9637c26d6f3420c3d2a225d/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64356366326334326233663666656262366132392f746573745f636f766572616765)](https://codeclimate.com/github/orkhanahmadov/cbar-currency/test_coverage)[![Maintainability](https://camo.githubusercontent.com/231776fb54ae0c496b3e33e975f1f680ca5340f67190721f27cd37be54e6680c/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f64356366326334326233663666656262366132392f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/orkhanahmadov/cbar-currency/maintainability)[![Quality Score](https://camo.githubusercontent.com/4e6d2c39c4edd22cb73fddd2377112442b71a5049efadb266d43b354580455d1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f726b68616e61686d61646f762f636261722d63757272656e63792e737667)](https://scrutinizer-ci.com/g/orkhanahmadov/cbar-currency)[![StyleCI](https://camo.githubusercontent.com/aa9bc3e4d8da0ac534ba153acd32a214ee1cf768d95ea4ec340ac8dfa992f733/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3138343539323332322f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/184592322)

[![](https://raw.githubusercontent.com/orkhanahmadov/cbar-currency/master/screenshot.png)](https://raw.githubusercontent.com/orkhanahmadov/cbar-currency/master/screenshot.png)

Requirements
------------

[](#requirements)

**PHP 7.2** or higher, `simplexml` and `bcmath` extensions.

Installation
------------

[](#installation)

```
composer require orkhanahmadov/cbar-currency
```

Usage
-----

[](#usage)

### Fetching rates from CBAR

[](#fetching-rates-from-cbar)

Instantiate `Orkhanahmadov\CBARCurrency\CBAR` with date you want to fetch rates for. If you don't pass a date, current date will be used:

```
use Orkhanahmadov\CBARCurrency\CBAR;

$cbar = new CBAR(); // this will fetch rates for current date
$cbar = new CBAR('01.05.2019'); // this will fetch rates for 01.05.2019
```

You can get currency rate by accessing it with with uppercase currency code:

```
$cbar->EUR; // returns EUR rate
```

You can change date for a new date by calling `for()` method without instantiating new class:

```
$cbar->for('25.04.2019'); // this will fetch rates for 25.04.2019
$cbar->USD; // returns USD rate for 25.04.2019
```

You can pass dates in any format that acceptable by PHP's `strtotime()` function. For example, `20.10.2019`, `10/20/2019`, `2019-10-20`, `today`, `yesterday`, `-1 week`, `-1 year`, `15 December 2015`, `last Friday`.

You can fetch currency rates for multiple dates with same class instance. Class instance fetches rates for each unique date only once and stores results for each date. If you set date to previously fetched date, stored rates will be used.

```
$cbar = new CBAR();
$cbar->for('20.04.2019'); // this will fetch rates from CBAR API
$cbar->for('23.04.2019'); // this will also fetch rates from CBAR API
$cbar->for('20.04.2019'); // since rates for 20.04.2019 fetched previously stored rates will be used instead of fetching rates for same day again
```

You can chain methods with fluent API syntax:

```
$cbar = new CBAR();
$cbar->for('yesterday')->EUR;
```

All available currencies and currency codes can be found in [CBAR website](https://www.cbar.az/currency/rates?language=en)

### Converting amount to and from AZN

[](#converting-amount-to-and-from-azn)

Library supports converting given amount in foreign currency to AZN with given date's rates:

```
$cbar = new CBAR();
$cbar->USD(13); // returns AZN equivalent of 13.00 USD with today's rates
$cbar->for('01.05.2019')->USD(57.5); // returns AZN equivalent of 57.50 USD with 01.05.2019 rates
```

You can also convert given amount in AZN to any available foreign currency:

```
$cbar = new CBAR();
$cbar->AZN()->USD; // returns USD equivalent of 1.00 AZN with today's rates
$cbar->AZN(55)->USD; // returns USD equivalent of 55.00 AZN with today's rates
$cbar->for('01.05.2019')->AZN(17.3)->USD; // returns USD equivalent of 17.30 AZN with 01.05.2019 rates
```

### Helper function

[](#helper-function)

Library ships with global helper function. You can use it like:

```
cbar()->USD // returns USD rate for today
cbar('01.05.2019')->USD; // returns USD rate for 01.05.2019
cbar()->for('01.05.2019')->EUR; // same as above
cbar()->USD(27); // returns 27.00 USD to AZN conversion
cbar()->AZN(15.8)->EUR; // returns 15.80 AZN to EUR conversion
```

**Note:** Calling `cbar()` global function always returns new instance of `Orkhanahmadov\CBARCurrency\CBAR` class.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Orkhan Ahmadov](https://github.com/orkhanahmadov)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~227 days

Recently: every ~262 days

Total

6

Last Release

1434d ago

PHP version history (4 changes)1.0.0PHP &gt;=7.2.0

1.1.0PHP &gt;=7.1.0

1.3.0PHP ^7.2

1.4PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/c82e54991e0224fdc49d34ee60d0cfce5ea0cca1cd59771155e3b372d1fa1d11?d=identicon)[orkhanahmadov](/maintainers/orkhanahmadov)

---

Top Contributors

[![orkhanahmadov](https://avatars.githubusercontent.com/u/7041590?v=4)](https://github.com/orkhanahmadov "orkhanahmadov (41 commits)")[![aytiqaqash](https://avatars.githubusercontent.com/u/80999522?v=4)](https://github.com/aytiqaqash "aytiqaqash (1 commits)")

---

Tags

azerbaijanazncbarcurrency-convertercurrency-ratescurrencyazerbaijancbarazn

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/orkhanahmadov-cbar-currency/health.svg)

```
[![Health](https://phpackages.com/badges/orkhanahmadov-cbar-currency/health.svg)](https://phpackages.com/packages/orkhanahmadov-cbar-currency)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[cartalyst/converter

A framework agnostic measurement conversion and formatting package featuring multiple types of measurements and currency conversion.

88434.4k7](/packages/cartalyst-converter)[ujjwal/currency-converter

Currency Converter Class with features of caching and identifying currency from country Code

49225.4k](/packages/ujjwal-currency-converter)[danielme85/laravel-cconverter

Laravel 5 plug-in for currency conversion

42101.1k](/packages/danielme85-laravel-cconverter)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
