dostrog/larate

Small library to access to currency exchange rates API of CBRF (Bank of Russia) and NBU (National Bank of Ukraine) from Laravel

Fund package maintenance!
dostrog

v1.0.5 2021-03-29 18:46 UTC

This package is auto-updated.

Last update: 2024-12-01 00:08:18 UTC


README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Overview

A simple Laravel package used for interacting with the Bank of Russia and National Bank of Ukraine API. 'Larate' allow you to get the latest or historical converted monetary values between RUB (UAH) and other currencies.

Installation

You can install the package via composer:

composer require dostrog/larate

You can publish the config file with:

php artisan vendor:publish --provider="Dostrog\Larate\Providers\LarateServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    'default_base_currency' => 'RUB',
    'service' => [
        'RUB' => Dostrog\Larate\Services\RussianCentralBank::class,
        'UAH' => Dostrog\Larate\Services\NationalBankOfUkraine::class,
    ],
];

Usage

// instantiate from Laravel IoC for inject provider
// according to config it maybe RUB (converted) rates from Central Bank OF Russia
$provider = app()->make(Larate::class);
$pair = new CurrencyPair('RUB', 'USD');
$date = Carbon::parse('2020-01-16');
$rate = $provider->getExchangeRate($pair, $date);
$value = $rate->getValue(); // 61.4328

// ...or using factory method, i.e. for getting UAH (converted) rates from National Bank of Ukraine
$provider = Larate::createForBaseCurrency('UAH');
$pair = new CurrencyPair('UAH', 'USD');
$date = Carbon::parse('2020-01-16');
$rate = $provider->getExchangeRate($pair, $date);
$value = $rate->getValue(); // 23.9821

// ...or using Laravel's Facades
$rate = LarateFacade::getExchangeRate($pair, $date);
$value = $rate->getValue();

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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