PHPackages                             phpajaxexperts/user-discounts - 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. phpajaxexperts/user-discounts

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

phpajaxexperts/user-discounts
=============================

A reusable Laravel package for user-level discounts.

v1.0.0(5mo ago)01MITPHPPHP ^8.2

Since Dec 11Pushed 5mo agoCompare

[ Source](https://github.com/phpajaxexperts/user-discounts)[ Packagist](https://packagist.org/packages/phpajaxexperts/user-discounts)[ RSS](/packages/phpajaxexperts-user-discounts/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

User Discounts for Laravel
==========================

[](#user-discounts-for-laravel)

A robust, reusable Laravel package for managing user-level discounts with deterministic stacking, usage caps, and audit logging.

Features
--------

[](#features)

- **Flexible Discount Types**: Percentage and fixed amount discounts.
- **Deterministic Stacking**: Control the order in which discounts are applied (e.g., highest value first).
- **Usage Limits**: Global and per-user usage caps.
- **Time-bound**: Start and expiration dates.
- **Audit Logging**: Tracks assignment, revocation, and application of discounts.
- **Concurrency Safe**: Atomic operations to prevent race conditions.
- **Events**: Dispatches events for easy integration with other systems.

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

[](#installation)

You can install the package via composer:

```
composer require phpajaxexperts/user-discounts
```

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

[](#configuration)

Publish the configuration file to customize stacking order, rounding, and caps:

```
php artisan vendor:publish --tag=user-discounts-config
```

**Config Options:**

- `stacking_order`: 'highest\_value', 'lowest\_value', 'created\_asc', 'created\_desc'
- `max_percentage_cap`: Maximum total percentage discount allowed (0-100)
- `rounding`: Decimal places for rounding calculations

Database Migrations
-------------------

[](#database-migrations)

Run the migrations to create the necessary tables:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Injecting the Service

[](#injecting-the-service)

```
use PhpAjaxExperts\UserDiscounts\DiscountService;

public function checkout(DiscountService $discountService)
{
    // ...
}
```

### Creating a Discount

[](#creating-a-discount)

```
use PhpAjaxExperts\UserDiscounts\Models\Discount;

$discount = Discount::create([
    'name' => 'Welcome Offer',
    'code' => 'WELCOME10',
    'type' => 'percentage', // or 'fixed'
    'value' => 10,
    'active' => true,
    'starts_at' => now(),
    'expires_at' => now()->addDays(30),
    'usage_limit' => 1000, // Global limit
    'usage_limit_per_user' => 1, // Per user limit
]);
```

### Assigning a Discount

[](#assigning-a-discount)

```
$discountService->assign($user, $discount);
```

### Checking Eligibility

[](#checking-eligibility)

```
if ($discountService->eligibleFor($user, $discount)) {
    // User can use this discount
}
```

### Applying Discounts

[](#applying-discounts)

This method calculates the final amount after applying all eligible discounts assigned to the user, respecting the stacking order and limits.

```
$result = $discountService->apply($user, $originalAmount);

// $result structure:
// [
//     'original_amount' => 100.00,
//     'final_amount' => 90.00,
//     'applied_discounts' => [
//         ['discount' => $discountModel, 'amount' => 10.00],
//         ...
//     ]
// ]
```

### Revoking a Discount

[](#revoking-a-discount)

```
$discountService->revoke($user, $discount);
```

Events
------

[](#events)

The package dispatches the following events:

- `PhpAjaxExperts\UserDiscounts\Events\DiscountAssigned`
- `PhpAjaxExperts\UserDiscounts\Events\DiscountRevoked`
- `PhpAjaxExperts\UserDiscounts\Events\DiscountApplied`

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance72

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

158d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/50c9625e0e7a0d616a531921b99d38b1e46a2beefa09d5224338cfa5ee81c1fe?d=identicon)[phpajaxexperts](/maintainers/phpajaxexperts)

---

Top Contributors

[![phpajaxexperts](https://avatars.githubusercontent.com/u/16373975?v=4)](https://github.com/phpajaxexperts "phpajaxexperts (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/phpajaxexperts-user-discounts/health.svg)

```
[![Health](https://phpackages.com/badges/phpajaxexperts-user-discounts/health.svg)](https://phpackages.com/packages/phpajaxexperts-user-discounts)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)[spatie/laravel-mix-preload

Add preload and prefetch links based your Mix manifest

169176.0k2](/packages/spatie-laravel-mix-preload)

PHPackages © 2026

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