burtds/cash-converter

A simple cash converter package for Laravel.

v1.0.4 2024-02-29 14:58 UTC

This package is auto-updated.

Last update: 2024-10-29 22:00:29 UTC


README

Latest Version on Packagist GitHub Workflow Status Total Downloads

About cash-converter

A small and simple package that takes away the pain of communicating with ExchangeRate-API directly to convert a certain amount of money between 2 currencies. You can also get the conversion rate or an array with all known conversion rates based on a certain currency.

How to use cash-converter

Installation

Install the package via composer:

composer require burtds/cash-converter

Afterwards, publish the service provider.

php artisan vendor:publish --provider="Burtds\CashConverter\CashConverterProvider"

Usage

First of all add the API key of the ExchangeRate-API service to your .env file of your project. If you don't have an ExchangeRate-API account yet, create one at exchangerate-api.com. Once you have an account you can copy your API key from the dashboard page and put it into your .env file.

EXCHANGE_RATE_API_KEY="YOUR-API-KEY"

To use it, import the Facade of this package at the top of your file.

use Burtds\CashConverter\Facades\CashConverter;

Once that is done, you can use the conversion functions.

CashConverter::getRates('EUR'); // returns an array of the currenct conversion rates based on the given currency, in this case Euro
CashConverter::getRate('EUR','USD'); // returns the current conversion rate for Euro to US Dollars
CashConverter::convert('EUR','USD', 25); // returns the converted vanlue in US Dollars for the given 25 Euro

Test & Format

To execute the tests, run:

composer test

To format the code using pint, run:

composer format

Security Vulnerabilities

If you discover a security vulnerability within this package, please send me an email via bert@bert.gent. I'll get back to you as soon as possible.

Credits

And a huge thanks to Freek Van der Herten for the guidance.

License

This package is open-sourced software licensed under the MIT license.