PHPackages                             php-junior/pricing-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. php-junior/pricing-engine

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

php-junior/pricing-engine
=========================

A dynamic pricing rule engine for Laravel.

v0.0.4(6mo ago)921MITPHPPHP ^8.2

Since Dec 18Pushed 6mo agoCompare

[ Source](https://github.com/PHPJunior/pricing-engine)[ Packagist](https://packagist.org/packages/php-junior/pricing-engine)[ Docs](https://github.com/PHPJunior/pricing-engine)[ GitHub Sponsors](https://github.com/PHPJunior)[ RSS](/packages/php-junior-pricing-engine/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Pricing Engine
==============

[](#pricing-engine)

[![Latest Version on Packagist](https://camo.githubusercontent.com/fa9b12cf4b5d3d2af09625bbd73a2ebf0b8100bfe79775f7ebe53bbde165699a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068702d6a756e696f722f70726963696e672d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-junior/pricing-engine)[![Total Downloads](https://camo.githubusercontent.com/eb50248dd7e6099406b3f5cb9fa1c615de158468b040236022b069850f700670/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7068702d6a756e696f722f70726963696e672d656e67696e652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/php-junior/pricing-engine)

A dynamic pricing rule engine for Laravel. This package allows you to define flexible pricing rules based on various conditions and apply actions like discounts or markups.

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

[](#installation)

You can install the package via composer:

```
composer require php-junior/pricing-engine
```

You can publish the config file with:

```
php artisan vendor:publish --provider="PhpJunior\PricingEngine\Providers\PricingEngineServiceProvider"
```

You can run the migrations with:

```
php artisan migrate
```

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

[](#configuration)

The configuration file `config/pricing-engine.php` allows you to customize:

- Model classes
- Table names
- Priority order (highest first or lowest first)
- Save Usage Records
- Available operators
- Available actions

Usage
-----

[](#usage)

### Creating Pricing Rules

[](#creating-pricing-rules)

You can create pricing rules using the `PricingEngine` facade or service.

```
use PhpJunior\PricingEngine\Facades\PricingEngine;
use PhpJunior\PricingEngine\Data\ConditionData;
use PhpJunior\PricingEngine\Data\ActionData;

PricingEngine::make()->savePricingRule(
    name: 'VIP Discount',
    priority: 1,
    conditions: [
        new ConditionData(
            attribute: 'customer_group',
            operator: '=',
            value: 'vip'
        ),
        new ConditionData(
            attribute: 'price_total',
            operator: '>',
            value: '100'
        )
    ],
    actions: [
        new ActionData(
            type: 'percentage_discount',
            value: 10
        )
    ]
);
```

Attributes in conditions can be any key.

To update an existing rule, provide the rulr ID in them `make` method:

```
PricingEngine::make(id: 1)->savePricingRule( ... );
```

To delete a rule, use the `deletePricingRule` method:

```
PricingEngine::make(id: 1)->deletePricingRule();
```

Fetch all pricing rules:

```
$rules = PricingEngine::make()->getAllPricingRules();
```

### Calculating Price

[](#calculating-price)

To calculate the price based on the defined rules, use the `calculatePrice` method. You need to provide the base price and a context array containing attributes used in your conditions.

```
use PhpJunior\PricingEngine\Facades\PricingEngine;

$result = PricingEngine::calculatePrice(
    basePrice: 200,
    context: [
        'customer_group' => 'vip',
        'price_total' => 200
    ]
);

// $result will contain:
// [
//     'original_price' => 200,
//     'final_price' => 180,
//     'applied_rules' => [ ... ]
// ]
```

Location-based pricing example:

```
use PhpJunior\PricingEngine\Facades\PricingEngine;
use PhpJunior\PricingEngine\Data\ConditionData;
use PhpJunior\PricingEngine\Data\ActionData;

PricingEngine::make()->savePricingRule(
    name: 'Location Based Discount',
    priority: 1,
    conditions: [
        new ConditionData(
            attribute: 'location',
            operator: 'location_in',
            value: ['US', 'CA']
        )
    ],
    actions: [
        new ActionData(
            type: 'fixed_discount',
            value: 20
        )
    ]
);

$result = PricingEngine::calculatePrice(
    basePrice: 150,
    context: [
        'location' => 'ip_address_here'
    ]
);

// $result will contain:
// [
//     'original_price' => 150,
//     'final_price' => 130,
//     'applied_rules' => [ ... ]
// ]
```

for location-based conditions, used this package `stevebauman/location` to resolve IP addresses to locations. get more info [here](https://github.com/stevebauman/location)

### Available Operators

[](#available-operators)

- `=`
- `!=`
- `>`
- `>=`
- ` [
    'custom_operator' => App\Operators\CustomOperator::class,
],
'actions' => [
    'custom_action' => App\Actions\CustomAction::class,
],
```

Then you can use them in your pricing rules.

```
use PhpJunior\PricingEngine\Facades\PricingEngine;
use PhpJunior\PricingEngine\Data\ConditionData;
use PhpJunior\PricingEngine\Data\ActionData;

PricingEngine::make()->savePricingRule(
    name: 'Custom Rule',
    priority: 2,
    conditions: [
        new ConditionData(
            attribute: 'custom_attribute',
            operator: 'custom_operator',
            value: 'some_value'
        )
    ],
    actions: [
        new ActionData(
            type: 'custom_action',
            value: 15
        )
    ]
);
```

Testing
-------

[](#testing)

```
composer test
```

Credit
------

[](#credit)

- [Steve Bauman](https://github.com/stevebauman) for his location package which is used for location-based pricing rules.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance67

Regular maintenance activity

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 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 ~0 days

Total

4

Last Release

196d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e2695272c87c7144c984ddf468d380477dc578b617e7da5502eb4e7eff1f6087?d=identicon)[Nyi Nyi Lwin](/maintainers/Nyi%20Nyi%20Lwin)

---

Top Contributors

[![PHPJunior](https://avatars.githubusercontent.com/u/13845077?v=4)](https://github.com/PHPJunior "PHPJunior (6 commits)")

---

Tags

dynamic-pricing-enginelaravelphpprice-rulespricinglaravellaravel-packageecommerceshopping cartphp-juniorpricing-ruleslaravel-dynamic-pricingpricing-engine

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/php-junior-pricing-engine/health.svg)

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

###  Alternatives

[imanghafoori/laravel-nullable

A package to help you write expressive defensive code in a functional manner

151461.3k6](/packages/imanghafoori-laravel-nullable)[realrashid/cart

Meet Cart — your ultimate solution for seamless shopping cart functionality in Laravel applications. Cart simplifies the complexities of shopping cart operations, from product additions to total calculations, ensuring a frictionless user experience.

1104.1k](/packages/realrashid-cart)[classiebit/eventmie

Run your own Events business with Eventmie Pro. Use it as event ticket selling website or event management platform on your own domain.

1892.0k](/packages/classiebit-eventmie)[paxha/laravel-reportable

This Laravel Eloquent extension provides record according to dates using models.

111.3k](/packages/paxha-laravel-reportable)

PHPackages © 2026

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