PHPackages                             unisharp/pricing - 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. unisharp/pricing

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

unisharp/pricing
================

A modularized pricing package for Buyable.

41.7k2[1 PRs](https://github.com/UniSharp/pricing/pulls)PHP

Since Jul 2Pushed 6y ago9 watchersCompare

[ Source](https://github.com/UniSharp/pricing)[ Packagist](https://packagist.org/packages/unisharp/pricing)[ RSS](/packages/unisharp-pricing/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Pricing
=======

[](#pricing)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cc7cb457886d84300e0ca9db0850ca7e92a8727a1c8df37bd5de843f3935fd0a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f556e6953686172702f70726963696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/unisharp/pricing)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a5c49eeb776ee8fb71a078efb1a2e1461d9a84fe0892695e2609d0be1ecd4666/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f556e6953686172702f70726963696e672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/UniSharp/pricing)[![Coverage Status](https://camo.githubusercontent.com/07b5791e3078830ea569b868629d2a4c9935a592376f7caf407ee202806bb42a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f556e6953686172702f70726963696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/UniSharp/pricing/code-structure)[![Quality Score](https://camo.githubusercontent.com/770f0d13543a8bd346bb3a2feac274bcaca2c820e09c94c62b581fb2c4b30f86/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f556e6953686172702f70726963696e672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/UniSharp/pricing)[![Total Downloads](https://camo.githubusercontent.com/99e90b8969411bd33679e472d157f19cbad66cbcdbc928e2a5d696d98bd8532a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f556e6953686172702f70726963696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/UniSharp/pricing)

A modularized pricing package for buyalbe.

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

[](#installation)

```
composer require unisharp/pricing dev-master

```

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

[](#configuration)

```
php artisan vendor:publish --tag pricing

```

Set available pricing modules in `config/pricing.php`

```
return [
    'modules' => [
        UniSharp\Pricing\Tests\Fixtures\TestModule::class,
    ]
];
```

Module Principles
-----------------

[](#module-principles)

- Module must implement `UniSharp\Pricing\ModuleContract` which needs `handle` and `finish` functions.
- Modules will be processed by the sequence in `config/pricing.php`, the first module will handle the pricing logic and pass pricing instance to the next module (Pipeline Pattern).
- There are some APIs a pricing module can call in the handle function:
    - $pricing-&gt;addFee(int $fee);
    - $pricing-&gt;addDeduction(int $deduction);
    - $pricing-&gt;writeModuleLog(mix $log);
    - $pricing-&gt;getModuleInfo();

> `addFee`, `addDeduction`, `writeModuleLog` will only change pricing instance's properties. `getModuleInfo` can get extra info of that module.

- Finish functions will be called after pricing execute. The logic after module successfully applied can be implemented here.

```
namespace UniSharp\Pricing\Tests\Fixtures;

use Closure;
use UniSharp\Pricing\Pricing;
use UniSharp\Pricing\ModuleContract;
use Illuminate\Contracts\Pipeline\Pipeline;

class TestModule implements ModuleContract
{
    const FEE = 99;
    const DEDUCTION = 88;
    const LOG = 'log';

    public function handle(Pricing $pricing, Closure $next)
    {
        $pricing->addFee(static::FEE);
        $pricing->addDeduction(static::DEDUCTION);
        $pricing->writeModuleLog(static::LOG);

        $info = $pricing->getModuleInfo();

        return $next($pricing);
    }

    public function finish(Pricing $pricing)
    {
        //
    }
}
```

Pricing Usages
--------------

[](#pricing-usages)

```
use UniSharp\Pricing\Facades\Pricing;

class Foo {
    // set items and get original price
    Pricing::setItems(UniSharp\Cart\CartItemCollection $items)
        ->getOriginalTotal();

    // apply some modules
    Pricing::apply(ModuleA::class)
        ->apply(ModuleB::class);

    // apply some modules with some extra info
    Pricing::apply(ModuleA::class)
        ->apply(ModuleB::class)
        ->with([
            ModuleA::class => 'extra info A',
            ModuleB::class => 'extra info B',
        ]);

    // apply modules and get final total
    Pricing::apply(ModuleA::class)
        ->apply(ModuleB::class)
        ->getTotal();

    // apply modules and execute them
    Pricing::apply(ModuleA::class)
        ->apply(ModuleB::class)
        ->execute();

    // get all applied modules
    Pricing::getAppliedModules();

    // get all fees
    Pricing::getFees();

    // get fee of a specific module
    Pricing::getFee(ModuleA::class);

    // get all deductions
    Pricing::getDeductions();

    // get deduction of a specific module
    Pricing::getDeduction(ModuleA::class);

    // get items
    Pricing::getItems();
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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.

### Community

Maintainers

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

---

Top Contributors

[![albertcht](https://avatars.githubusercontent.com/u/9117929?v=4)](https://github.com/albertcht "albertcht (13 commits)")[![FreedomKnight](https://avatars.githubusercontent.com/u/1203922?v=4)](https://github.com/FreedomKnight "FreedomKnight (1 commits)")[![youchenlee](https://avatars.githubusercontent.com/u/181350?v=4)](https://github.com/youchenlee "youchenlee (1 commits)")

### Embed Badge

![Health badge](/badges/unisharp-pricing/health.svg)

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

PHPackages © 2026

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