A simple cash converter package for Laravel.
A small & simple package, but takes away the pain of communicating with an API directly to convert a certain amount of cash between 2 currencies. You can also get the conversion rate or an array with all known conversion rates based on a certain currency.
You can install the package via composer:
composer require burtds/cash-converter
Afterwords, we'll need to publish the service provider.
php artisan vendor:publish --provider="Burtds\CashConverter\CashConverterProvider"
First of all we'll add the API key of the service we're using to our
.env file of our project.
If you don't have an account yet on exchangerate-api.com, you should create one.
Once you have an account you can copy your API key from the dashboard page and put it into you
We'll need to import the Facade of this package on top of your file.
Once that is done, you'll be able to use the conversion functions.
CashConverter::getRates('EUR'); // returns an array of the currenct converison rates based on the given currency, in this case Euro's CashConverter::getRate('EUR','USD'); // returns the currenct conversion rate for Euro to US Dollars CashConverter::convert('EUR','USD', 25); // returns the converted vanlue in US Dollars for the given 25 Euros
For testing you can run:
For formatting the code using pint you can run:
If you discover a security vulnerability within this package, please send me an e-mail via firstname.lastname@example.org. I'll get back at you as soon as possible.
And u huge thanks to Freek Van der Herten for the guidance.
This package is open-sourced software licensed under the MIT license.