All Projects β†’ danielme85 β†’ Laravel Cconverter

danielme85 / Laravel Cconverter

Licence: mit
A simple currency converter plugin for Laravel 5. Currency providers: The European Central Bank, OpenExchange, CurrencyLayer and fixer.io

Projects that are alternatives of or similar to Laravel Cconverter

Laravel Swap
πŸ’΅ Currency exchange rates for Laravel and Lumen
Stars: ✭ 296 (+658.97%)
Mutual labels:  currency, currency-converter, laravel
Laravel Money
Currency formatting and conversion package for Laravel
Stars: ✭ 261 (+569.23%)
Mutual labels:  currency, currency-converter, laravel
historical-bank-ruby
A Ruby Bank that serves historical exchange rates
Stars: ✭ 14 (-64.1%)
Mutual labels:  currency, currency-converter
python-forex-quotes
Library to fetch and parse realtime Forex quotes and convert currencies
Stars: ✭ 25 (-35.9%)
Mutual labels:  currency, currency-converter
react-local-currency
πŸ’΅ πŸ’΄Shows the price of your services in the customer's currency πŸ’Ά πŸ’·
Stars: ✭ 21 (-46.15%)
Mutual labels:  currency, currency-converter
GoCurrency
Simple currency converter. Insert an amount, what currency to convert from and what currency to convert to.
Stars: ✭ 29 (-25.64%)
Mutual labels:  currency, currency-converter
javascript-forex-quotes
JavaScript Library for fetching realtime forex quotes.
Stars: ✭ 38 (-2.56%)
Mutual labels:  currency, currency-converter
currency-api
Free Currency Exchange Rates API with 150+ Currencies & No Rate Limits
Stars: ✭ 507 (+1200%)
Mutual labels:  currency, currency-converter
Android Money
Simple money and currency converter library for android.
Stars: ✭ 66 (+69.23%)
Mutual labels:  currency, currency-converter
Money
PHP implementation of Fowler's Money pattern.
Stars: ✭ 3,868 (+9817.95%)
Mutual labels:  currency, currency-converter
Forex Python
Foreign exchange rates, Bitcoin price index and currency conversion using ratesapi.io
Stars: ✭ 378 (+869.23%)
Mutual labels:  currency, currency-converter
Coinc
πŸ’°πŸ’±Alfred Workflow for currencies conversion
Stars: ✭ 38 (-2.56%)
Mutual labels:  currency, currency-converter
salaryconverter
Equivalent salary converter using PPP
Stars: ✭ 42 (+7.69%)
Mutual labels:  currency, currency-converter
php-currency-api
Standardized wrapper for popular currency rate APIs. Currently supports FixerIO, CurrencyLayer, Open Exchange Rates and Exchange Rates API.
Stars: ✭ 17 (-56.41%)
Mutual labels:  currency, currency-converter
Swap
πŸ’± Currency exchange rates library
Stars: ✭ 1,195 (+2964.1%)
Mutual labels:  currency, currency-converter
currency-converter
πŸ’° Easily convert between 32 currencies
Stars: ✭ 16 (-58.97%)
Mutual labels:  currency, currency-converter
Coinonline
A Cryptocurrency/Blockchain wallet app based on React Native
Stars: ✭ 59 (+51.28%)
Mutual labels:  currency, currency-converter
Php Forex Quotes
PHP Library for fetching realtime forex quotes.
Stars: ✭ 61 (+56.41%)
Mutual labels:  currency, currency-converter
Gocurrency
Simple currency converter. Insert an amount, what currency to convert from and what currency to convert to.
Stars: ✭ 26 (-33.33%)
Mutual labels:  currency, currency-converter
Laravel Money
Laravel Money.
Stars: ✭ 476 (+1120.51%)
Mutual labels:  currency, laravel

Laravel Currency Converter

GitHub PHP from Packagist GitHub release GitHub tag Travis (.org) Codecov

A simple currency conversion plug-in for Laravel 5.5+ πŸ’΅
Example usage: https://danielmellum.com/projects/currency-converter

Version testing and requirements

Version Tested with
dev-master Laravel 6.0
v0.3.* Laravel 6.0
v0.2.* Laravel 5.6
v0.1.* Laravel 5.5
v0.0.7 Laravel 5.4

If you are having composer requirement issues using the latest release and Laravel < v5.4, try the v0.0.7 release.

Please note:

  • The European Central Bank does not require any user account and is therefore set as the default 'api-source', however the number of available currencies are somewhat limited compared to the other commercial sources (37). In my experience this source is also unpredictable, and might give an empty response.
  • All the other data providers are commercial and require a user account. They all have a free tier of 1000 requests per month, let's say you theoretically cache results for 60 min and you should be covered with some margin for errors πŸ‘ Coincidentally Cache is enabled per default and set to 60 min. Now in theory one should perhaps make a simple Eloquent Model with the columns: date, from, to, rate or something similar, and then store the historical results. Please note that depending on usage this might go against the user agreements on the commercial data providers. 🀫 πŸ™ˆ

Installation

composer require danielme85/laravel-cconverter

Configuration

You can publish this vendor config file if you would like to make changes to the default config.

php artisan vendor:publish --provider="danielme85\CConverter\CConverterServiceProvider"

All config variables can also be changed in your local .env file:

CC_API_SOURCE=eurocentralbank
CC_USE_SSL=true
CC_FIXERIO_ACCESS_KEY=
CC_OPENEXCHANGE_APP_ID=
CC_CURRENCYLAYER_ACCESS_KEY=
CC_ENABLE_LOG=false
CC_ENABLE_CACHE=true
CC_CACHE_TIMEOUT=60

Usage

There are static class "shortcuts" to convert or get one-time Currency series.

//To convert a value
$valueNOK = Currency::conv($from = 'USD', $to = 'NOK', $value = 10, $decimals = 2);

//To convert a value based on historical data
$valueNOK = Currency::conv($from = 'USD', $to = 'NOK', $value = 10, $decimals = 2, $date = '2018-12-24');

//to get an array of all the rates associated to a base currency.
$rates = Currency::rates(); //defaults to USD

$rates = Currency::rates('NOK');

//Get historical rates
$rates = Currency::rates('NOK', '2018-12-24');

Working with multiple values

I would highly recommend creating a model instance and the non-static functions getRates() & convert() when doing multiple conversion or getting multiple currency series for the best performance. The currency rates are stored in the provider model by date/base-currency for quick and easy access.

$currency = new Currency();
$values = [1, 3, 4, 5...].
foreach ($values as $value) {
    $valueNOK = $currency->convert($from = 'USD', $to = 'NOK', $value = 10, $decimals = 2);
}

$rates = $currency->getRates('NOK');
foreach ($rates as $rate) {
    $value = $valueNOK * $rate;
}

You can override the settings when/if you create a new instance.

$currency = new Currency(
    $api = 'yahoo', 
    $https = false, 
    $useCache = false, 
    $cacheMin = 0);
...
$result = Currency:conv(
    $from = 'USD', 
    $to = 'NOK', 
    $value = 10, 
    $decimals = 2, 
    $date = '2018-12-24', 
    $api = 'yahoo', 
    $https = false, 
    $useCache = false, 
    $cacheMin = 0);

Use the three lettered ISO4217 code for to/from currencies: http://en.wikipedia.org/wiki/ISO_4217

Money Formatting

The package: gerardojbaez/money is included for an easier and more powerful Money Formatter, excellent alternative to money_format(). You can get the values of an conversion by setting round='money' (money formatter overrides rounding).

Currency::conv('USD', 'USD', 10, 2);
//Result: 10
Currency::conv('USD', 'USD', 10, 'money');
//Result: $10.00
$currency->convert('USD', 'USD', 10, 'money');
//Result: $10.00

You can also get the money formatter itself trough the static Currency function:

$formater = Currency::money($amount = 0, $currency = 'USD');

This Money Formatter also ships with a handy helper function.

echo moneyFormat(10, 'USD');
//Result: $10.00

See Money Formatter github page for more information and usage. https://github.com/gerardojbaez/money

Supported functions per API

Default API is: The European Central Bank

Config var API HTTPS Historical Sign-up required URL
eurocentralbank The European Central Bank yes yes no https://sdw-wsrest.ecb.europa.eu/help/
openexchange OpenExchangeRates.com non-free non-free yes https://openexchangerates.org
currencylayer *CurrencyLayer non-free yes yes https://currencylayer.com
fixer *Fixer.io yes yes yes https://fixer.io

*CurrencyLayer and Fixer.io is the same company now, and it seems like the services have become one and the same.

Disclaimer

Please take note of the Terms of Use for the different data sources.
https://policies.yahoo.com/us/en/yahoo/terms/product-atos/yql/index.htm
https://currencylayer.com/terms
https://openexchangerates.org/terms

This code is released per the MIT open source license: http://opensource.org/licenses/MIT The actual rates and conversion will vary between the data sources. In addition I am no math professor, so you should probably not use this for super serious multi-billion dollar investments. If you are gonna spend your hard earned billion dollars on the money market, you should probably use something like this: http://www.forex.com/forex.html

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].