PHPackages                             vaened/php-price-engine - 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. vaened/php-price-engine

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

vaened/php-price-engine
=======================

A powerful pricing calculator for products and services, with comprehensive tax and discount calculations.

v4.1.0(11mo ago)4125.1k—0.6%1MITPHPPHP ^8.1CI passing

Since Jul 24Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/vaened/php-price-engine)[ Packagist](https://packagist.org/packages/vaened/php-price-engine)[ RSS](/packages/vaened-php-price-engine/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (5)Versions (17)Used By (1)

Price Engine
============

[](#price-engine)

[![Build Status](https://github.com/vaened/php-price-engine/actions/workflows/tests.yml/badge.svg)](https://github.com/vaened/php-price-engine/actions?query=workflow:Tests)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license)

The Price Calculation Library is a tool that allows you to perform complex calculations for prices, taxes, discounts, and charges in your applications. This library is based on the `Brick\Money` library to ensure precise monetary calculations.

Installation
------------

[](#installation)

You can install the library using `composer`.

```
composer require vaened/php-price-engine
```

Usage
-----

[](#usage)

### Initializing the Cashier

[](#initializing-the-cashier)

To start using the Price Engine, create an instance of the any [Cashier](#configuration) and provide an [`Amount`](./src/Money/Amount.php).

```
$cashier = new SimpleCashier(
    Amount::taxable(
        Money::of(100, 'USD'),
        TaxCodes::any()
    ),
    quantity : 1,
    taxes    : Taxes::from([
        Tax\Inclusive::proportional(21, TaxCode::IVA),
    ])
);
```

### Updating Quantity

[](#updating-quantity)

You can update the quantity using the `update()` method, that will calculate the totals in the next summary.

```
$cashier->update(10);
```

### Applying Discounts

[](#applying-discounts)

To apply discounts, use the `apply()` method, that will calculate the totals in the next summary, and receive as parameter N amount of [`Discount`](./src/Adjustments/Discount.php).

```
$cashier->apply(
    Discount::proportional(2)->named('NEW_USERS'),
    Discount::fixed(5)->named('PROMOTIONAL'),
);
```

### Adding Charges

[](#adding-charges)

To add charges, use the `add()` method, it will calculate the totals in the next summary, and received as parameter N amount of [`Charge`](./src/Adjustments/Charge.php).

```
$cashier->add(
    Charge::proportional(5)->named('POS'),
    Charge::fixed(10)->named('DELIVERY')
);
```

### Obtaining Individual Totals

[](#obtaining-individual-totals)

To obtain individual values of any price adjustment, you can use the `tax()` `charge()`, or `discount()` functions, all of which receive the code established during creation and return an instance of [`Adjustment`](./src/Modifier.php)

```
$cashier->taxes()->locate('IVA');
$cashier->charges()->locate('DELIVERY');
$cashier->discounts()->locate('NEW_USERS');
```

### Obtaining Totals

[](#obtaining-totals)

To obtain the total, you can use individual functions, each of which returns an instance of `Brick\Money`.

```
$cashier->quantity();
$cashier->unitPrice();
$cashier->subtotal();
$cashier->taxes()->total();
$cashier->charges()->total();
$cashier->discounts()->total();
$cashier->total();
```

Configuration
-------------

[](#configuration)

Currently there are 2 built-in ways to handle calculations

### Cashiers

[](#cashiers)

- [**SimpleCashier**](./src/Cashiers/SimpleCashier.php): This `cashier` operates based on the gross price concept. It means that the price provided will be cleaned to get the final price without tax. Adjustments are applied directly to the gross price and taxes are calculated separately after adjustments are applied
- [**RegularCashier**](./src/Cashiers/RegularCashier.php): This `cashier` operates based on the concept of unit price + taxes. It means that the configured taxes will be maintained or added to the indicated price, and discounts and charges will be applied to this price with taxes included.

> Choose the `cashier` that best suits your specific business needs and requirements. You can create your own cashier to fit any specific logic or rule related to your business. If you need to create additional cashiers or implement custom logic, you can do so by extending [`Cashier`](./src/Cashier.php). This library provides a flexible foundation to handle various pricing scenarios effectively.

### Amounts

[](#amounts)

There are 2 ways to create the amount.

- **Amount with applicable taxes**: these amounts are subject to taxes, whether they are `inclusive taxes` or `exclusive taxes` and can be defined as follows.

    ```
    Amount::taxable(
        Money::of(100, 'PEN'),
        TaxCodes::only(['IGV'])
    );
    ```

    > The tax codes establish what taxes are applicable for the amount

    Allow AllOnly AllowedAllow Nothing**TaxCodes**::***any()*****TaxCodes**::***only(\['IGV', ...\])*****TaxCodes**::***none()***
- **Amounts without applicable taxes**: These amounts are not subject to any tax and will not have taxes applied.

    ```
    Amount::taxexempt(
        Money::of(10, 'PEN')
    );
    ```

    > These would be the same as creating a taxable amount but passing **TaxCodes**::***none()*** as the allowed codes.

### Taxes

[](#taxes)

Taxes can be established in two ways.

- **Inclusive**: Taxes included in the unit price, and will be cleared during calculations ```
    use Vaened\PriceEngine\Adjustments\Taxation;

    $amount->impose([
      Taxation\Inclusive::proportional(18, 'IGV'); // 18%
      Taxation\Inclusive::fixed(2, 'ISC'); // 2 PEN
    ]);
    // or
    $cashier = new RegularCashier(
      ...
      taxes : Taxes::from([
        Taxation\Inclusive::proportional(18, 'IGV'); // 18%
        Taxation\Inclusive::fixed(2, 'ISC'); // 2 PEN
      ])
    );
    ```
- **Exclusive**: Taxes not included in the unit price, and will be added for the final calculations. ```
    use Vaened\PriceEngine\Adjustments\Taxation;

    $amount->impose([
      Taxation\Exclusive::proportional(18, 'IGV'); // 18%
      Taxation\Exclusive::fixed(2, 'ISC'); // 2 PEN
    ]);
    // or
    $cashier = new RegularCashier(
      ...
      taxes : Taxes::from([
        Taxation\Exclusive::proportional(18, 'IGV'); // 18%
        Taxation\Exclusive::fixed(2, 'ISC'); // 2 PEN
      ])
    );
    ```

License
-------

[](#license)

This library is licensed under the MIT License. For more information, please see the [`license`](./license) file.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance52

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~46 days

Recently: every ~72 days

Total

16

Last Release

336d ago

Major Versions

v0.6.1 → v1.02024-08-30

v1.0 → v2.0.02025-03-03

v2.0.0 → v3.0.02025-03-03

v3.0.0 → v4.0.02025-06-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebfa2dc9bcd9f9f7cea1f5473811d3c3904f60716e5605ab0d7208a9a6b81f09?d=identicon)[vaened](/maintainers/vaened)

---

Top Contributors

[![vaened](https://avatars.githubusercontent.com/u/15077850?v=4)](https://github.com/vaened "vaened (89 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vaened-php-price-engine/health.svg)

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

###  Alternatives

[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[whitecube/php-prices

A simple PHP library for complex monetary prices management

17168.4k7](/packages/whitecube-php-prices)[beacon-hq/bag

A comprehensive immutable value objects implementation

1789.1k3](/packages/beacon-hq-bag)[finller/laravel-money

Use Brick/Money in your Laravel app

1919.2k](/packages/finller-laravel-money)

PHPackages © 2026

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