Skip to main content

Creating Coupons

Coupons let you offer discounts, promotions, and special access to subscribers. They are stored in subscribd_coupons and applied at checkout or to active subscriptions.

Creating a percentage coupon

use Pixelworxio\Subscribd\Models\Coupon;

$coupon = Coupon::create([
    'code'               => 'SAVE20',
    'type'               => 'percent',
    'amount'             => 20,           // 20% off
    'duration_in_months' => 3,            // applies for 3 billing cycles
    'max_redemptions'    => 500,          // null for unlimited
    'expires_at'         => now()->addMonths(3),
]);

Creating a fixed-amount coupon

$coupon = Coupon::create([
    'code'               => 'FLAT10',
    'type'               => 'fixed',
    'amount'             => 1000,         // $10.00 off (in minor units)
    'currency'           => 'USD',
    'duration_in_months' => null,         // applies once
    'max_redemptions'    => null,
    'expires_at'         => now()->addWeeks(2),
]);

Coupon duration options

duration_in_monthsBehaviour
nullApplied once to the first invoice only
3Applied to the next 3 billing cycles
0Applied indefinitely (every invoice)

Restricting to specific plans

$coupon = Coupon::create([
    'code'             => 'STARTERONLY',
    'type'             => 'percent',
    'amount'           => 50,
    'applies_to_plans' => ['starter'],   // only valid on the 'starter' plan
    'expires_at'       => null,
]);
When applies_to_plans is null, the coupon is valid on any plan.

Checking coupon validity

$coupon->isValid();              // bool — not expired, under max redemptions
$coupon->isValidFor($plan);      // bool — also checks applies_to_plans

Deactivating a coupon

Set expires_at to now to immediately invalidate a coupon without deleting it:
$coupon->update(['expires_at' => now()]);
The Coupon resource in the Filament plugin includes a Deactivate table action that does this in one click.

Coupon model properties

$coupon->code;               // 'SAVE20'
$coupon->type;               // 'percent' or 'fixed'
$coupon->amount;             // int — percentage or minor-unit amount
$coupon->currency;           // 'USD' (fixed coupons only)
$coupon->duration_in_months; // int|null
$coupon->max_redemptions;    // int|null
$coupon->redemptions;        // int — current count
$coupon->expires_at;         // Carbon|null
$coupon->applies_to_plans;   // array|null

Next steps