Coder Social home page Coder Social logo

shipsaas / currency-fx Goto Github PK

View Code? Open in Web Editor NEW
29.0 0.0 0.0 59 KB

PHP (Laravel's portable) library to handle Currency FX (Rates, Conversions,...). Drivers for multiple online services.

License: MIT License

PHP 100.00%
currency-exchange currency-rates laravel laravel-library php php-library

currency-fx's Introduction

PHP Currency FX Library

codecov Unit Test (PHP 8.1, 8.2) Integration Test E2E Test

A PHP Library handles Currency FX (rates & conversions) with ease. Battery-included ๐Ÿ”‹๐Ÿ”‹๐Ÿ”‹.

Available for Laravel too.

Tired of implementing these and integrate with 3rd services? Let's CurrencyFX help you to do that. Covered by Unit Testing & battle-tested!

Available Services / Batteries

Supports

  • PHP 8.1+

Dependencies

  • Guzzle for API Requests
  • NeverThrow for straightforward OK/Error response.

Usage

Simply initialize the class with the required params. And it is ready to use in no time.

$service = new CurrencyCloudService($host, $loginId, $apiKey);
$rateResponse = $service->getRates('USD', 'SGD');

if (!$rateResponse->isOk()) {
    // failed to get the rate from third party service
    // do something here
}

$rate = $rateResponse->getOkResult()->rate; // float (1.4xxx)

Laravel Integration

Requirement: Laravel 10+

Just simply install the package and lets Laravel discovery magic happens ๐Ÿฅฐ

Since we already bind the services in Laravel Container, all you have to do is update the ENVs and that's all.

Export the configuration

php artisan vendor:publish --tag=currency-fx-configs

Update ENVs

After published the config, checkout the configs/currency-fx.php.

We already defined some ENVs key for you to add ๐Ÿ˜œ.

Usage

use CurrencyFX\Services\CurrencyLayerService;
use CurrencyFX\Services\ExchangerRatesApiIoService;

// global access
app(CurrencyLayerService::class)->getRates('USD', 'EUR');

// DI
class TransferService
{
    public function __construct(
        private ExchangerRatesApiIoService $rateService
    ) {
    }
    
    public function transfer(): TransferResult
    {
        $rateRes = $this->rateService->getRates('EUR', 'GBP');
        if ($rateRes->isError()) {
            return TransferResult::error(...);
        }

        $rate = $rateRes->getOkResult()->rate;
    }
}

Tests

We love tests, always. We have 3 kind of test cases:

  • Unit Tests
  • Integration Tests
  • E2E Tests

Check out the TEST-README.md to learn more!

Contribute to the project

  • All changes must follow PSR-1 / PSR-12 coding conventions.
  • Unit testing is a must, cover things as much as you can.

Feel free to add more driver and share it to the whole PHP community ๐Ÿ˜†

This library is useful?

Thank you, please give it a โญ๏ธโญ๏ธโญ๏ธ to support the project.

Don't forget to share with your friends & colleagues, so they can also build their own SaaS products as well ๐Ÿš€

License

MIT LICENSE

Contributors

ShipSaas, Seth Phat & Contributors

currency-fx's People

Contributors

sethsandaru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.