roundly-consulting / coupons-for-laravel
Create, manage, and apply discount coupons in Laravel.
Package info
github.com/roundly-consulting/coupons-for-laravel
pkg:composer/roundly-consulting/coupons-for-laravel
Fund package maintenance!
Requires
- php: ^8.4
- ext-bcmath: *
- illuminate/contracts: ^12.0|^13.0
- roundly-consulting/money-for-laravel: ^1.0
- roundly-consulting/package-toolkit-for-laravel: ^1.0
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- roundly-consulting/testing-for-laravel: ^1.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Coupons for Laravel
Create, validate and redeem discount coupons in Laravel: fixed, percentage (optionally capped)
and free-shipping discounts with currency locks, minimum spends, activation windows and global
or per-customer usage limits. Redemption is atomic, and every amount is an exact
money-for-laravel Money.
Installation
Requires PHP 8.4 (ext-bcmath), Laravel 12 or 13, and MySQL/MariaDB, PostgreSQL or SQLite.
composer require roundly-consulting/coupons-for-laravel
php artisan vendor:publish --tag="coupons-migrations"
php artisan migrate
If the models that redeem coupons have UUID/ULID keys, set COUPONS_KEY_TYPE before
migrating.
Usage
Create a coupon through the facade. New coupons start inactive, so activate it:
use RoundlyConsulting\Coupons\Enums\DiscountType; use RoundlyConsulting\Coupons\Facades\Coupons; $coupon = Coupons::generate(DiscountType::Percentage, value: 2000, code: 'SUMMER', maxUsage: 100); // 20 % off $coupon->activate()->save();
At checkout, check it, preview the discount and redeem it against the cart total:
use RoundlyConsulting\Money\Money; $cart = Money::ofMinor(5000, 'EUR'); // €50.00 Coupons::code('SUMMER')->check($cart, $user); // null, or why not: Expired, AtMaxUsage, … Coupons::code('SUMMER')->preview($cart); // 10.00 EUR, without redeeming $result = Coupons::code('SUMMER')->redeem($cart, $user); // atomic; throws a CouponException if refused $result->discount; // 10.00 EUR $result->total; // 40.00 EUR
Documentation
The full documentation — configuration, every feature and its API, and testing — lives on our website: roundly-consulting.com/open-source/docs/coupons-for-laravel
Release notes are in CHANGELOG.md. To contribute, see the contributing guide.
Support our work
This package is free and open source, built and maintained by Roundly Consulting. If it saves you time, please consider supporting our open-source work — a one-time donation, a monthly pledge on Patreon or a crypto donation helps fund maintenance, new features and new packages.
License
The MIT License (MIT). See LICENSE.md for details.