A package for getting and saving the exchange rate in the project.
"repositories": [
...
{
"type": "vcs",
"url": "https://github.com/ShipperDev/ShipperExchangeRate.git"
},
...
],
composer require shipperdev/shipper-exchange-rate
php artisan vendor:publish --tag=shipper-exchange-rate
php artisan migrate
Require:
EXCHANGE_RATES_API_URL="https://api.apilayer.com"
EXCHANGE_RATES_API_TOKEN=
Optional:
SHIPPER_EXCHANGE_RATE_FROM="EUR,USD"
SHIPPER_EXCHANGE_RATE_TO="EUR,USD"
SHIPPER_EXCHANGE_RATE_MARKUP_PERCENT=5
use ShipperDev\ShipperExchangeRate\ShipperExchangeRate;
...
$service = new ShipperExchangeRate();
$rate = $service->getRate('EUR', 'USD');
If rate not exists will be got 0.
Or with dependency injection:
public function index(ShipperExchangeRate $service): JsonResponse
{
return response()->json($service->getRate('EUR', 'USD'));
}
php artisan shipper-exchange-rate:fetch