> ## Documentation Index
> Fetch the complete documentation index at: https://docs.subscribd.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Creating Coupons

> Define and manage discount codes

# 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

```php theme={null}
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

```php theme={null}
$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_months` | Behaviour                              |
| -------------------- | -------------------------------------- |
| `null`               | Applied once to the first invoice only |
| `3`                  | Applied to the next 3 billing cycles   |
| `0`                  | Applied indefinitely (every invoice)   |

## Restricting to specific plans

```php theme={null}
$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

```php theme={null}
$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:

```php theme={null}
$coupon->update(['expires_at' => now()]);
```

The `Coupon` resource in the [Filament plugin](/advanced/filament) includes a **Deactivate** table action that does this in one click.

## Coupon model properties

```php theme={null}
$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

* **[Applying Coupons](/coupons/applying)** — Apply coupons at checkout or to active subscriptions
* **[Feature Grants](/coupons/feature-grants)** — Grant additional feature access via coupon
