rackbeat/php-currency-api

Wrapper for multiple currency rate APIs

dev-master 2018-06-24 23:00 UTC

This package is auto-updated.

Last update: 2024-04-08 22:07:26 UTC


README

Dont worry about your favorite service suddenly shutting down or switching plans on you. Switch away easily.

Build Status Coverage Total Downloads Latest Stable Version License

Supported APIs

Installation

You just require using composer and you're good to go!

composer require rackbeat/php-currency-api

If you're using Laravel, a service provider and facade is included to provide configuration of driver etc.

Usage

Initialize instance

$api = Rackbeat\Currency\API::make('fixerio'); // driver from supported drivers.

Set base currency (default = USD)

$api->setBase(Rackbeat\Currency\Symbol::USD);

Set symbols to return (default = all/[])

$api->setSymbols([ Rackbeat\Currency\Symbol::DKK, Rackbeat\Currency\Symbol::EUR, Rackbeat\Currency\Symbol::USD ]);

Please note, you are not required to use Rackbeat\Currency\Symbol to specify symbols. It's simply a convenience helper.

Get latest rates

$api->get(); // Get latest rates for selected symbols, using set base currency
$api->get('DKK');  // Get latest rates for selected symbols, using DKK as base currency

Convert amount from one currency to another

$api->convert($fromCurrency = 'DKK', $toCurrency = 'EUR', 10.00); // Convert 10 DKK to EUR

Get rate on specific date

$api->historical($date = '2018-01-01'); // Get currency rate for base on 1st of January 2018
$api->historical($date = '2018-01-01', 'GBP'); // Get currency rate for GBP on 1st of January 2018

Laravel

... todo

Requirements

  • PHP >= 7.1
  • Possibly a paid plan for your desired API. Check their pricing.