Download the PHP package amrshawky/laravel-currency without Composer
On this page you can find all versions of the php package amrshawky/laravel-currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amrshawky/laravel-currency
More information about amrshawky/laravel-currency
Files in amrshawky/laravel-currency
Package laravel-currency
Short Description A Laravel package for current and historical currency exchange rates & crypto exchange rates based on the free API provided by exchangerate.host
License MIT
Informations about the package laravel-currency
Laravel Currency
Update: exchangerate.host now requires API key, This package is not maintained anymore.
Laravel currency is a simple package for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host - no API keys needed!
Note: This package is an integration for the Currency library
Requirements
- PHP >= 7.2
- Laravel >= 6.0
- guzzlehttp >= 6.0
Installation
Usage
1. Currency Conversion
To convert from one currency to another you may chain the methods:
This will return the converted amount or null
on failure.
The amount to be converted is default to 1
, you may specify the amount:
Available Methods
-
Convert currency using historical exchange rates
YYYY-MM-DD
: -
Round the converted amount to decimal places:
- You may also switch data source between forex
default
, bank view or crypto currencies:
2. Latest Rates
To get latest rates you may chain the methods:
This will return an array
of all available currencies or null
on failure.
Available Methods
- Just like currency conversion you may chain any of the available methods:
3. Historical Rates
Historical rates are available for most currencies all the way back to the year of 1999.
Same as latest rates you may chain any of the available methods:
4. Timeseries Rates
Timeseries are for daily historical rates between two dates of your choice, with a maximum time frame of 365 days.
This will return an array
or null
on failure.
5. Fluctuations
Retrieve information about how currencies fluctuate on a day-to-day basis, with a maximum time frame of 365 days.
This will return an array
or null
on failure.
Throwing Exceptions
The default behavior is to return null
for errors that occur during the request (connection timeout, DNS errors, client or server error status code, missing API success parameter, etc.).
If you would like to throw an exception instead, you may use the throw
method, The throw
method returns the currency instance, allowing you to chain other methods:
If you would like to perform some additional logic before the exception is thrown, you may pass a closure to the throw method:
Other Methods
-
You may use the
withoutVerifying
method to indicate that TLS certificates should not be verified when sending the request: -
You may specify additional Guzzle request options using the
withOptions
method. ThewithOptions
method accepts an array of key / value pairs: - The
when
method will execute the given callback when the first argument given to the method evaluates to true:
Testing
Currency uses Laravel facades which makes it easy to mock so it's not actually executed during the test:
More information regarding list of bank sources here
For a list of all supported symbols here and list of crypto currencies here
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of laravel-currency with dependencies
guzzlehttp/guzzle Version >=6.0
ext-json Version *
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0
amrshawky/currency Version ^1.0