Skip to content

Latest commit

 

History

History

05_rate_exchangers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

API rate exchangers

They are provided to get information about exchange rates online.

There are two available options:

  1. Get latest rates.
  2. Get rates for a specific day.

latest and historical modes, respectively.

Which are provided by default?

At the moment, the package supports and provides 3 different API providers:

  1. Fixer
  2. OpenExchangeRates
  3. ExchangeRate - default

You can choose whatever you like by changing it in the property rate_exchanger of the config file.

What if there is no rate exchanger I want?

In this case, you can add your own, 👀 see here for full details.

Access to RateExchanger instance

In order to get access to RateExchanger you can call the interface from Service Container like this:

use PostScripton\Money\Clients\RateExchangers\RateExchanger;

app(RateExchanger::class)->supports(['USD', 'RUB']);
app(RateExchanger::class)->rate('USD', 'RUB', now()->subYear());

Or you can use a cached variant because it implements the interface as well:

use PostScripton\Money\Cache\RateExchangerCache;
use PostScripton\Money\Currencies;

app(RateExchangerCache::class)->supports(Currencies::getCodesArray());
app(RateExchangerCache::class)->rate('USD', 'RUB', now()->subYear());

app(RateExchangerCache::class)->clear(); // deletes all cached data

📌 Back to the contents.