burtds/cash-converter

A simple cash converter package for Laravel.

1.0.3 2023-10-23 22:39 UTC

This package is auto-updated.

Last update: 2024-01-31 10:13:46 UTC


README

Latest Version on Packagist GitHub Workflow Status Total Downloads

About cash-converter

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.

How to use cash-converter

Installation

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"

Usage

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 .env file.

EXCHANGE_RATE_API_KEY="YOUR-API-KEY"

We'll need to import the Facade of this package on top of your file.

use Burtds\CashConverter\Facades\CashConverter;

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

Test & Format

For testing you can run:

composer test

For formatting the code using pint you can run:

composer format

Security Vulnerabilities

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

Credits

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

License

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