itmosoft / laravel-coupons
Coupon creation, validation, discount calculation, usage limits, and redemption tracking for Laravel applications.
v1.0.0
2026-11-14 15:34 UTC
Requires
- php: ^8.3
- illuminate/contracts: ^12.0 || ^13.0
- illuminate/database: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- orchestra/testbench: ^10.0 || ^11.0
- phpunit/phpunit: ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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_referenceis 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.