Skip to content
This repository was archived by the owner on Nov 24, 2021. It is now read-only.

indigophp-archive/money-extension

Repository files navigation

Indigo Money

Latest Version Software License Build Status Code Coverage Quality Score HHVM Status Total Downloads

This package provides some extensions for mathiasverraes/money.

Install

Via Composer

$ composer require indigophp/money

Usage

See the list of extensions bellow:

  • DBAL type
  • Exchange

The extensions are kept in the same namespace as the extended library (either Money or any third-party).

Exchange

You can use this extension to create CurrencyPairs with conversion rate from a third party source.

use Money\Exchange;
use Money\Provider\Local;
use Money\Currency;

$exchange = new Exchange(new Local(['EUR' => ['USD' => 1.25]]));

$baseCurrency = new Currency('EUR');
$currencyCurrency = new Currency('USD');

$currencyPair = $exchange->getCurrencyPair($baseCurrency, $counterCurrency);

// returns 1.25
$currencyPair->getConversionRate();

Currently (WIP) the following Providers are availaible:

Most of the providers use third party public APIs.

Local

You can store conversion rates locally and use them as an array source using this provider. The array MUST be an associative array of base currencies containing an associative array of rates indexed by counter currencies. Rates MUST be numeric (CAN be string).

use Money\Provider\Local;

$provider = new Local(['EUR' => ['USD' => 1.25]]);

General scheme for array representation:

[
    'baseCurrency' => [
        'counterCurrency1' => <rate1>,
        'counterCurrency2' => <rate2>,
    ],
]

Batch

Third party services are not always reliable. With Batch provider you can build up a stack of Providers and try getting the appropriate rate until one is returned.

use Money\Provider\Batch;
use Money\Provider\Local;

$provider = new Batch;
$provider->addProvider(new Local(['EUR' => ['USD' => 1.25]]));

Testing

$ phpspec run

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Extensions for mathiasverraes/money

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages