Skip to main content

Applying Coupons

Coupons can be applied at the point of subscription creation, or to an existing active subscription.

Applying at checkout

Pass a coupon option to CreateSubscription:
use Pixelworxio\Subscribd\Actions\CreateSubscription;
use Pixelworxio\Subscribd\Models\Plan;

$plan = Plan::query()->where('key', 'pro')->firstOrFail();

app(CreateSubscription::class)->execute($user, $plan, ['coupon' => 'SAVE20']);

Applying to an active subscription

Use the ApplyCoupon action to attach a coupon to a subscription that already exists:
use Pixelworxio\Subscribd\Actions\ApplyCoupon;
use Pixelworxio\Subscribd\Models\Coupon;

$coupon = Coupon::query()->where('code', 'SAVE20')->firstOrFail();

app(ApplyCoupon::class)->execute($subscription, $coupon);
The coupon is pushed to the gateway (e.g., attached to the Stripe customer) and stored locally. The discount takes effect on the next invoice.

subscriber.coupon-redeem component

For custom checkout flows that don’t use subscriber.plan-picker, the subscriber.coupon-redeem Livewire component handles validation and session storage:
<livewire:subscribd::subscriber.coupon-redeem />

How it works

  1. The user enters a coupon code and submits the form.
  2. The component validates the code using Coupon::isValid() — checking expiry and maximum redemptions.
  3. On success, the code is written to session('subscribd.pending_checkout')['coupon'].
  4. When subscriber.checkout processes the subscription, it reads the session key and passes the coupon to CreateSubscription.
  5. The browser event subscribd:coupon-validated is dispatched with { code }.
document.addEventListener('subscribd:coupon-validated', (e) => {
    console.log('Coupon applied:', e.detail.code);
});

document.addEventListener('subscribd:coupon-removed', () => {
    console.log('Coupon removed');
});

Named subscription slot

Scope the component to a named slot when using multiple subscriptions:
<livewire:subscribd::subscriber.coupon-redeem subscription-name="team" />

Removing a coupon

Remove a coupon from an active subscription:
use Pixelworxio\Subscribd\Actions\RemoveCoupon;

app(RemoveCoupon::class)->execute($subscription);

Checking whether a coupon is applied

$subscription->coupon;           // Coupon model or null
$subscription->coupon?->code;    // 'SAVE20'
$subscription->hasActiveCoupon(); // bool

Next steps