PHPackages                             leaphly/price - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. leaphly/price

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

leaphly/price
=============

v1.0.0-alpha2(11y ago)466.6k↓82.4%6[2 issues](https://github.com/leaphly/price/issues)MITPHP

Since Aug 29Pushed 11y ago3 watchersCompare

[ Source](https://github.com/leaphly/price)[ Packagist](https://packagist.org/packages/leaphly/price)[ RSS](/packages/leaphly-price/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Price
=====

[](#price)

[![Build Status](https://camo.githubusercontent.com/086d461470a42b1226646a3a64c6d593e4beccf51fd56454db26b4124547b96e/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6c656170686c792f70726963652e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/leaphly/price)[![Total Downloads](https://camo.githubusercontent.com/4b27a77c083463974bd29981a4f835e0ab4fdba958402966680159e354e2ddc3/68747470733a2f2f706f7365722e707567782e6f72672f6c656170686c792f70726963652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/leaphly/price)[![Latest Stable Version](https://camo.githubusercontent.com/f1bbf6f74b12f3ce8dca0f8dce2dc379333a416782e84249cd9fbff598e5e82e/68747470733a2f2f706f7365722e707567782e6f72672f6c656170686c792f70726963652f762f737461626c652e706e67)](https://packagist.org/packages/leaphly/price)

### A Price is the amount of a product in different currencies.

[](#a-price-is-the-amount-of-a-product-in-different-currencies)

```
In Dollar a t-shirt     costs 4$,
in Eur the same t-shirt costs 3€
if British Pound the cost is given by the current conversion of 0.7900

```

in PHP is:

```
$tShirtPrice = new Price(
  [
    'EUR' => 300,
    'USD' => 400
  ],
  ['EUR/GBP 0.7900'] // array of conversions
);

echo $tShirtPrice->inEUR(); // 300  same as ->getAmount('EUR')
echo $tShirtPrice->inUSD(); // 400  same as ->getAmount('USD')
echo $tShirtPrice->inGBP(); // 237  same as ->getAmount('GBP')
```

### Why?!

[](#why)

- Because is not recommended to work with the float for the money in PHP...
- Because is better to implement money as value objects.
- Because in the e-commerce domain a product has always\* a different price for different currencies.
- Because we needed :).

### Goodies:

[](#goodies)

- It helps you to work with money.
- It helps you to work with currencies.
- It helps you to work with multiple currencies, converted or explicit.
- It is shipped with some math operations: `addition`, `multiplication`, `division`, `subtraction` ...
- This library extends the [mathiasverraes/money](https://packagist.org/packages/mathiasverraes/money).
- Immutable Value Object.
- Shipped with an example of `DoctrineType`

### Simple usage

[](#simple-usage)

- The T-Shirt costs 10€ and 8£

#### Constructor

[](#constructor)

Usage with explicit currency values.

```
$ticketPrice = new Price(
  [
    'EUR' => 1000,
    'GBP' => 800
  ]
);

echo $ticketPrice->inEUR();  // return 1000

var_dump($ticketPrice->availableCurrencies()); // array with EUR, GBP
```

#### Usage with mixed explicit and converted values

[](#usage-with-mixed-explicit-and-converted-values)

```
$ticketPrice = new Price(
  [
    'EUR' => 100,
    'USD' => 130
  ],
  ['EUR/GBP 0.7901'] // this is an array of conversions with the ISO standard format.
);

echo $ticketPrice->inEUR(); // 100
echo $ticketPrice->inGBP(); // 79 is calculated

var_dump($ticketPrice->availableCurrencies()); // array with EUR, USD, GBP
```

### Do we use the same language?

[](#do-we-use-the-same-language)

- An espresso coffee costs \[2€ or 2.3$\] here and \[1€ or 1.2$\] take away.

`espresso` is a product.

`here` and `take away` are contexts (*still is a missing feature*).

`2€` `2.3$` is a Price with 2 currencies,

`1€` `1.2$` is a Price with 2 currencies,

`2€ or 2.3$ here, and 1€ or 1.2$ for take away.` is a PriceList (*still is a missing feature*).

API (still not stable)
----------------------

[](#api-still-not-stable)

### Price

[](#price-1)

```
    public function inXYZ($currency); // ZYX is a valid currency like EUR or GBP

    public function getAmount($currency);

    public function hasAmount($currency);

    public function availableCurrencies();

    public function equals(Price $other);

    public function add(Price $addend);

    public function subtract(Price $subtrahend);

    public function multiply($multiplier);

    public function divide($divisor);

    public function isZero();
```

#### Example sum two prices

[](#example-sum-two-prices)

```
$ticketPrice = new Price(
  [
    'EUR' => 100,
    'USD' => 130
  ],
  ['EUR/GBP 0.7901'] // this is an array of conversions
);

$shirtPrice = new Price(
  [
    'EUR' => 200,
    'CHF' => 300,
    'GBP' => 400
  ],
);

// sum
$sumPrice = $ticketPrice->add($shirtPrice);

$sumPrice->inEUR(); // 100+200= 400
$sumPrice->inGBP(); //  79+400= 479
$sumPrice->inUSD(); //          130
$sumPrice->inCHF(); //          300
```

#### With the \\Iterator interface

[](#with-the-iterator-interface)

Implement the `\Iterator` so Price is an array of Money.

```
$price = new Price ....
foreach ($price as $money) {
    echo $money->getAmount() . ' in '. $money->getCurrencies();
}
```

#### Use it with the Money Value Object

[](#use-it-with-the-money-value-object)

```
use Money\Money;
use Money\CurrencyPair;

$price = new Price(
    array(
        Money::EUR(5),
        Money::USD(10),
        Money::GBP(10),
        'TRY' => 120  // or mixed
    ),
    [
        CurrencyPair::createFromIso('USD/CHF 1.5'),
    ]
);
```

Note: the iteration is valid only on the explicit currencies not on the converted one.

License [![License](https://camo.githubusercontent.com/fe0829d194279f49ded2536941cf987cc2681f70e92d18ab038606de0d97b1c9/68747470733a2f2f706f7365722e707567782e6f72672f6c656170686c792f70726963652f6c6963656e73652e706e67)](https://packagist.org/packages/leaphly/price)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#license-)

This library is under the MIT license. See the complete license in the repository:

```
Resources/meta/LICENSE

```

Test
----

[](#test)

```
composer.phar create-project leaphly/price ~1`
bin/phpunit
```

About
-----

[](#about)

See also the list of [contributors](https://github.com/leaphly/price/contributors).

Reporting an issue or a feature request
---------------------------------------

[](#reporting-an-issue-or-a-feature-request)

Issues and feature requests are tracked in the [Github issue tracker](https://github.com/leaphly/price/issues).

Note: this library uses the `dev` version of the [Mathias Verraes Money](https://github.com/mathiasverraes/money/).

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 77.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~3 days

Total

2

Last Release

4323d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/446a646f719434553ab25f0f931d28ec09fbb036528126ac7e9d54a2e8132581?d=identicon)[liuggio](/maintainers/liuggio)

---

Top Contributors

[![liuggio](https://avatars.githubusercontent.com/u/530406?v=4)](https://github.com/liuggio "liuggio (17 commits)")[![simodima](https://avatars.githubusercontent.com/u/1193857?v=4)](https://github.com/simodima "simodima (3 commits)")[![albertsola](https://avatars.githubusercontent.com/u/667186?v=4)](https://github.com/albertsola "albertsola (1 commits)")[![hiddeco](https://avatars.githubusercontent.com/u/10063039?v=4)](https://github.com/hiddeco "hiddeco (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/leaphly-price/health.svg)

```
[![Health](https://phpackages.com/badges/leaphly-price/health.svg)](https://phpackages.com/packages/leaphly-price)
```

###  Alternatives

[96qbhy/agora

声网php-SDK

121.5k](/packages/96qbhy-agora)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
