Search by

itmosoft / laravel-coupons

adeelrao007

Coupon creation, validation, discount calculation, usage limits, and redemption tracking for Laravel applications.

Package info

github.com/ITMOSOFT/laravel-coupons

pkg:composer/itmosoft/laravel-coupons

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-14 15:34 UTC

This package is auto-updated.

Last update: 2026-11-14 15:35:08 UTC


README

Coupon creation, validation, discount calculation, usage limits, and redemption tracking for Laravel 12 and 13.

Features

  • Create fixed-amount and percentage coupons.
  • Normalize coupon codes to uppercase by default.
  • Start and end date validation.
  • Minimum order subtotal and maximum discount.
  • Global usage and per-customer usage limits.
  • Transactional redemption with usage counter updates.
  • Polymorphic customer redemption records.
  • Configurable table names and prefix.

Requirements

  • PHP 8.3+
  • Laravel 12 or 13

Installation

composer require itmosoft/laravel-coupons
php artisan vendor:publish --tag=itmosoft-coupons-config
php artisan migrate

Publishing config is optional.

Usage

use ItmoSoft\Coupons\CouponManager;

$coupons = app(CouponManager::class);

$coupon = $coupons->create(
    code: 'SAVE10',
    discountType: 'percentage',
    value: 10,
    minimumSubtotal: 50,
    maximumDiscount: 25,
    usageLimit: 100,
    perCustomerLimit: 1,
);

$discount = $coupons->calculateDiscount($coupon, 150, $customer);

$redemption = $coupons->redeem(
    coupon: $coupon,
    subtotal: 150,
    customer: $customer,
    orderReference: 'ORDER-1001',
);

Fixed discount:

$coupon = $coupons->create('TAKE20', 'fixed', 20);

Important integration notes

  • The package calculates a discount amount; it does not modify carts, orders, taxes, shipping, or payment totals. The application must apply the returned amount to its checkout calculation.
  • Percentage discounts are calculated on the supplied subtotal before tax/shipping unless the caller chooses otherwise.
  • Amounts use decimal database columns, but public APIs accept PHP floats. For strict financial arithmetic, use integer minor units in a future version.
  • The per-customer limit is enforced only when a customer model is supplied.
  • order_reference is informational and not unique/idempotent. The consuming application must prevent duplicate order-event redemptions.
  • Redemption and usage counters run inside a database transaction and use row locking where supported. SQLite does not provide production-equivalent row-level locking.
  • This release does not support product/category restrictions, stacking rules, customer segments, coupon batches, automatic expiration jobs, or usage rollback/refund.
  • The application remains responsible for authorization and tenant scoping.

Testing

composer validate --strict
composer install
composer test

MIT License. See LICENSE.