cryonighter/currency-converter

This package allows you to convert exchange rates according to the rate of the Central Bank of Russia (but you can use any other sources of exchange rates)

1.0.0 2022-02-07 15:35 UTC

This package is not auto-updated.

Last update: 2024-11-13 06:57:19 UTC


README

Latest Version on Packagist Software License Total Downloads Build Status

This package allows you to convert exchange rates according to the rate of the Central Bank of Russia (but you can use any other sources of exchange rates)

Highlights

  • Simple API
  • Framework Agnostic
  • Composer ready, PSR-2 and PSR-4 compliant

System Requirements

You need:

  • PHP >= 8.1.0 but the latest stable version of PHP is recommended

Install

Via Composer

$ composer require cryonighter/currency-converter

Usage

use Cryonighter\CurrencyConverter\CurrencyCodeConverter;
use Cryonighter\CurrencyConverter\CurrencyConverter;
use Cryonighter\CurrencyConverter\Provider\CbrCurrencyRateProvider;

// Get a list of exchange rates. By default, the package provides a service for receiving rates from the server of the Central Bank of Russia.
// However, you can use any source of currency rates, you only need to form an array of instances of the CurrencyRate class.
$currencyRates = CbrCurrencyRateProvider::getCurrencyRates();

// Build the converter object
$currencyConverter = new CurrencyConverter(new CurrencyCodeConverter(), $currencyRates);

// To convert 100 USD to EUR
$amount = $currencyConverter->convert(100, 'USD', 'EUR');

// You can also use numeric currency codes
$amount = $currencyConverter->convert(100, '840', '978');

// You can mix and match :)
$amount = $currencyConverter->convert(100, '840', 'EUR');

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ php vendor/phpunit/phpunit/phpunit tests

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

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

Credits

License

The MIT License (MIT). Please see License File for more information.