PHPackages                             joegabdelsater/promo-codes - 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. joegabdelsater/promo-codes

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

joegabdelsater/promo-codes
==========================

This package is a plug and play package for adding the promo code discount features to your project

2.0.0(2y ago)025MITPHP

Since May 8Pushed 2y ago1 watchersCompare

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

READMEChangelog (2)DependenciesVersions (7)Used By (0)

Promo Codes Description
=======================

[](#promo-codes-description)

This is a simple package to add the promocode discount feature to any website. It works independently from other features.

Note: You should have the users model/table present.

Installation
============

[](#installation)

`composer require joegabdelsater/promo-codes`

Usage
=====

[](#usage)

To use the library you need to use the facade in your code by adding this line to the top of the file:

`use Joegabdelsater\PromoCodes\Facades\PromoCodes;`

Functions
=========

[](#functions)

Generate promo code
-------------------

[](#generate-promo-code)

To generate a promo code, call the generate() method. The method accepts the following parameters:

- `$length (optional)`: The length of the promo code. Default is 8.
- `$prefix (optional)`: A prefix to add to the promo code. Default is an empty string.
- `$discount (optional)`: The discount amount. Default is 0.
- `$maxUses (optional)`: The maximum number of times the promo code can be used. Default is null.
- `$validFrom (optional)`: The date and time from which the promo code is valid. Default is null.
- `$validTo (optional)`: The date and time until which the promo code is valid. Default is null.

Example:

`PromoCodes::generate(10, 'DISCOUNT', 10, 100, '2022-01-01 00:00:00', '2022-12-31 23:59:59');`

Validate promocode
------------------

[](#validate-promocode)

To validate a promo code, call the validate() method. The method accepts the promo code as a parameter and returns either the promo code object if it is valid or an array with an error message if it is invalid.

Example usage:

`PromoCodes::validate('DISCOUNT-5D8S0A5K5L')`

` // returns ['status' => false, 'message' => 'Reason why code is not valid'] `

or

`// returns ['status' => true, 'code' => 'code details']`

Apply code
==========

[](#apply-code)

To apply the promocode use the apply() method. The method accepts the promo code as a parameter and returns either the promo code object if it is valid or an array with an error message if it is invalid.

Example usage: `PromoCodes::apply('DISCOUNT-5D8S0A5K5L')`

Calculate the discounted amount
-------------------------------

[](#calculate-the-discounted-amount)

To calculate the discounted amount after applying a promo code, call the calculate() method. The method accepts the following parameters:

- `$amount`: The original amount before the discount.
- `$discount_type`: The type of discount, either 'percentage' or 'fixed'.
- `$discount_amount`: The amount of the discount.

` PromoCodes::calculate(100, 'percentage', 10)`

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Total

6

Last Release

1074d ago

Major Versions

1.7.0 → 2.0.02023-06-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b5c002fe05d2c0e956d4b6bc759d92471b191dd2a8ca33a0dfa3de8d363d0a7?d=identicon)[joegabdelsater](/maintainers/joegabdelsater)

---

Top Contributors

[![joegabdelsater](https://avatars.githubusercontent.com/u/23471249?v=4)](https://github.com/joegabdelsater "joegabdelsater (23 commits)")

### Embed Badge

![Health badge](/badges/joegabdelsater-promo-codes/health.svg)

```
[![Health](https://phpackages.com/badges/joegabdelsater-promo-codes/health.svg)](https://phpackages.com/packages/joegabdelsater-promo-codes)
```

PHPackages © 2026

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