PHPackages                             hipstersg-demo/laravel-user-discounts-package - 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. hipstersg-demo/laravel-user-discounts-package

ActiveLibrary

hipstersg-demo/laravel-user-discounts-package
=============================================

interview task

1.0.0(7mo ago)07PHPPHP &gt;=8.1

Since Sep 28Pushed 7mo agoCompare

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

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

🎁 Laravel User Discounts
========================

[](#-laravel-user-discounts)

A **reusable Laravel 12 package** for deterministic user-level discounts with stacking, caps, audits, and concurrency safety.

---

📦 Installation
--------------

[](#-installation)

1. **Install via Composer**

    ```
    composer require hipstersg-demo/laravel-user-discounts-package
    ```
2. **Publish Config &amp; Migrations**

    ```
    php artisan vendor:publish --provider="Vendor\\UserDiscounts\\DiscountServiceProvider" --tag=config
    php artisan migrate
    ```
3. **(Optional) Publish for Customization**

    ```
    php artisan vendor:publish --provider="Vendor\\UserDiscounts\\DiscountServiceProvider" --tag=migrations
    php artisan vendor:publish --provider="Vendor\\UserDiscounts\\DiscountServiceProvider" --tag=seeders
    ```

---

🛠 Usage
-------

[](#-usage)

### ➕ Assigning a Discount

[](#-assigning-a-discount)

```
use Vendor\UserDiscounts\Models\Discount;
use Vendor\UserDiscounts\Facades\Discounts;

$discount = Discount::create([
    'code' => 'WELCOME10',
    'type' => 'percentage',
    'value' => 10,
    'active' => true,
]);

Discounts::assign($user, $discount);
```

### 🔍 Checking Eligibility

[](#-checking-eligibility)

```
if (Discounts::eligibleFor($user, $discount)) {
    echo "User can use this discount.";
}
```

### 💰 Applying Discounts

[](#-applying-discounts)

```
$result = Discounts::apply($user, 1500.00, [
    'idempotency_key' => 'order-1001',
    'meta' => ['order_id' => 1001],
]);

echo "Final amount: {$result['amount']}";
```

### ❌ Revoking Discounts

[](#-revoking-discounts)

```
Discounts::revoke($user, $discount);
```

---

📡 Events
--------

[](#-events)

The package fires events that you can listen for in your app:

- `DiscountAssigned($user, Discount $discount, array $meta)`
- `DiscountRevoked($user, Discount $discount)`
- `DiscountApplied($user, Collection $discounts, DiscountAudit $audit)`

### Example Listener

[](#example-listener)

```
namespace App\Listeners;

use Vendor\UserDiscounts\Events\DiscountApplied;

class SendDiscountNotification
{
    public function handle(DiscountApplied $event)
    {
        // Access: $event->user, $event->discounts, $event->audit
        // Example: send email or log analytics
    }
}
```

Register in `EventServiceProvider`:

```
protected $listen = [
    DiscountApplied::class => [SendDiscountNotification::class],
];
```

---

⚙️ Configuration
----------------

[](#️-configuration)

See `config/discounts.php` for options:

- `stacking_order` → `priority | percentage_first | fixed_first`
- `max_total_percentage` → cap on total % discount
- `rounding` → precision + mode (`half_up`, `half_down`, `up`, `down`)
- `default_per_user_cap` → fallback if discount doesn’t define one
- `require_idempotency_key` → enforce unique apply calls

---

👨‍💻 Developer
-------------

[](#‍-developer)

- **Vishal Jagani**
- 📧
- 📞 +91 90995 46953

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance63

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

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

227d ago

### Community

Maintainers

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

---

Top Contributors

[![vishaljagani08](https://avatars.githubusercontent.com/u/35404397?v=4)](https://github.com/vishaljagani08 "vishaljagani08 (5 commits)")

### Embed Badge

![Health badge](/badges/hipstersg-demo-laravel-user-discounts-package/health.svg)

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

###  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)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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