Skip to main content
ApplyCoupon connects a discount to an existing subscription. When you call it, the action stores the coupon_id on the Subscription model and pushes the coupon to the configured gateway — for Stripe, this attaches the coupon to the gateway customer record. The discount takes effect on the subscriber’s next invoice, not retroactively.

Creating a coupon

Before you can apply a coupon, you need a Coupon model. Create one with Coupon::create().
use Pixelworxio\Subscribd\Models\Coupon;

$coupon = Coupon::create([
    'code'               => 'LAUNCH20',
    'type'               => 'percent',
    'amount'             => 20,         // 20%
    'duration_in_months' => 3,
    'expires_at'         => now()->addMonths(3),
    'max_redemptions'    => 500,
]);

Applying the coupon

Pass the resolved Subscription and Coupon models to ApplyCoupon::execute().
use Pixelworxio\Subscribd\Actions\ApplyCoupon;

app(ApplyCoupon::class)->execute($subscription, $coupon);
You can also apply a coupon by code using the facade shortcut, which resolves the Coupon model for you.
use Pixelworxio\Subscribd\Facades\Subscribd;

Subscribd::for($user)->applyCoupon('LAUNCH20');

Coupon model fields

FieldTypeDescription
codestringUnique coupon code that subscribers enter
typestring'percent' or 'fixed'
amountintDiscount amount — percentage (1–100) for percent, minor currency units for fixed
duration_in_months`intnull`How many months the discount applies; null = forever
expires_at`datetimenull`After this date the coupon cannot be redeemed; null = no expiry
max_redemptions`intnull`Maximum number of times the coupon can be used; null = unlimited
applies_to_plans`arraynull`JSON array of plan keys this coupon is restricted to; null = any plan
first_payment_onlyboolIf true, the discount applies to the first invoice only
minimum_amount`intnull`Minimum invoice amount (in minor currency units) required to use this coupon
feature_grants`arraynull`Additional feature overrides to apply while the coupon is active

Coupon types

A percentage discount is applied to the invoice subtotal before tax.
Coupon::create([
    'code'   => 'HALF20',
    'type'   => 'percent',
    'amount' => 50,   // 50% off
]);

When the discount takes effect

The discount is reflected on the next invoice generated for the subscription. It does not apply retroactively to invoices that have already been issued or paid. For Stripe, the coupon is attached to the customer record and Stripe applies it automatically when the next billing cycle runs.
If duration_in_months is set, the discount expires after that many months. Subscribd records the coupon_id on the subscription and the gateway tracks the duration independently.
Calling ApplyCoupon multiple times on the same subscription replaces the previous coupon. Only one coupon can be active on a subscription at a time.