flexmind-software/currency-rate

Library download currency rate and save in database, It's designed to be extended by any available data source.


README

Laravel Version Support Packagist PHP Version Support Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require flexmind-software/currency-rate

You can publish and run the migrations with:

php artisan vendor:publish --provider="FlexMindSoftware\CurrencyRate\CurrencyRateProvider" --tag="currency-rate-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="FlexMindSoftware\CurrencyRate\CurrencyRateProvider" --tag="currency-rate-config"

This is the contents of the published config file:

return [
    'driver' => env('FLEXMIND_CURRENCY_RATE_DRIVER', 'european-central-bank'),
    'drivers' => [
        'albania',
        'armenia',
        'australia',
        'azerbaijan',
        'bceao',
        'belarus',
        'bosnia-and-herzegovina',
        'botswana',
        'bulgaria',
        'canada',
        'china',
        'croatia',
        'czech-republic',
        'denmark',
        'england',
        'european-central-bank',
        'fiji',
        'georgia',
        'hungary',
        'iceland',
        'israel',
        'macedonia',
        'moldavia',
        'norway',
        'poland',
        'romania',
        'russia',
        'serbia',
        'sweden',
        'switzerland',
        'turkey',
        'ukraine',
    ],
    'table-name' => env('FLEXMIND_CURRENCY_RATE_TABLENAME', 'currency_rates'),
    'cache-ttl' => env('FLEXMIND_CURRENCY_RATE_CACHE_TTL', 3600),
];

The drivers array defines which currency rate providers are available when running the command with --driver=all. Add or remove entries from this list to customise the drivers used in your application. See config/currency-rate.php for additional configuration options, including the cache TTL for HTTP requests.

Available Drivers

Country / Source Driver
Albania albania
Armenia armenia
Australia australia
Azerbaijan azerbaijan
BCEAO bceao
Belarus belarus
Bosnia and Herzegovina bosnia-and-herzegovina
Botswana botswana
Bulgaria bulgaria
Canada canada
China china
Croatia croatia
Czech Republic czech-republic
Denmark denmark
England england
European Central Bank european-central-bank
Fiji fiji
Georgia georgia
Hungary hungary
Iceland iceland
Israel israel
Macedonia macedonia
Moldavia moldavia
Norway norway
Poland poland
Romania romania
Russia russia
Serbia serbia
Sweden sweden
Switzerland switzerland
Turkey turkey
Ukraine ukraine

Usage

php artisan flexmind:currency-rate [options] [--] [<date>]

Arguments:
  date               Date to download currency rate, if empty is today
  
Options:
  --queue[=QUEUE]    Queue name, if set "none" cmd run without add job to queue [default: "none"]
  --driver[=DRIVER]  Driver to download rate [default: "all"]

Events

The CurrencyRate::saveIn method dispatches a CurrencyRateSaved event once rates are persisted. Consumers may listen for this event to trigger downstream actions:

use FlexMindSoftware\CurrencyRate\Events\CurrencyRateSaved;
use Illuminate\Support\Facades\Event;

Event::listen(CurrencyRateSaved::class, function (CurrencyRateSaved $event) {
    // $event->rates contains the saved records
});

### Examples

Run for today's rates using all configured drivers:

```bash
php artisan flexmind:currency-rate

Fetch rates for a specific date:

php artisan flexmind:currency-rate 2023-09-15

Use a specific driver:

php artisan flexmind:currency-rate --driver=canada

Dispatch the job to a queue:

php artisan flexmind:currency-rate --queue=default

Execute immediately without queueing:

php artisan flexmind:currency-rate --queue=none

Testing

composer test

Sources

Country name Central Bank Driver name
Europe
European Central Bank european-central-bank
Albania Bankës së Shqipërisë albania
Armenia Hayastani Hanrapetut’yan Kentronakan Bank armenia
Azerbaijan Azərbaycan Mərkəzi Bankı azerbaijan
Belarus Нацыянальны банк Рэспублікі Беларусь belarus
Bosnia and Herzegovina Централна банка Босне и Херцеговине bosnia-and-herzegovina
Bulgaria Bŭlgarska narodna banka bulgaria
Croatia Hrvatska Narodna Banka croatia
Czech Republic Česká národní banka czech-republic
Danmark Danmarks Nationalbanks denmark
Georgia Sakartvelos Erovnuli Bank’i georgia
United Kingdom Bank of England england
Hungary Magyar Nemzeti Bank hungary
Iceland Seðlabanki Íslands iceland
Macedonia Narodna Banka na Republika Severna Makedonija macedonia
Moldavia Banca Naţională a Moldovei moldavia
Norway Norges Bank norway
Poland Narodowy Bank Polski poland
Russia Tsentral'nyy bank Rossiyskoy Federatsii russia
Romania Banca Națională a României romania
Serbia Narodna banka Srbije serbia
Switzerland Banca naziunala svizra switzerland
Sweden Sveriges Riksbank sweden
Turkey Türkiye Cumhuriyet Merkez Bankası turkey
Ukraine Natsionalʹnyy bank Ukrayiny ukraine
Africa
Benin Central Bank of West African States (BCEAO) bceao
Botswana Bank of Botswana botswana
Burkina Faso Central Bank of West African States (BCEAO) bceao
Guinea-Bissau Central Bank of West African States (BCEAO) bceao
Ivory Coast Central Bank of West African States (BCEAO) bceao
Mali Central Bank of West African States (BCEAO) bceao
Niger Central Bank of West African States (BCEAO) bceao
Senegal Central Bank of West African States (BCEAO) bceao
Togo Central Bank of West African States (BCEAO) bceao
Asia
China CFETS - China Foreign Exchange Trade System china
Israel בנק ישראל israel
North America
Canada Banqueu du Canada canada
Oceania
Australia Reserve Bank of Australia australia
Fiji Reserve Bank of Fiji fiji

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Adding new locales

Translations for driver descriptions live in resources/langs/{locale}/description.php. To contribute a new locale:

  1. Create a new directory for the locale under resources/langs (for example es for Spanish).
  2. Copy resources/langs/en/description.php into that directory and translate the strings.
  3. Submit a pull request with the new translation file.

Credits

License

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