, , .
, Subscription Laravel\Cashier\Subscription.
withCoupon():
public function withCoupon($coupon)
{
$this->coupon = $coupon;
return $this;
}
swap() . - $subscription->save();.
...
if ($this->coupon) {
$subscription->coupon = $this->coupon;
}
...
$subscription->save();
, , , - Billable subscriptions(), Subscription.
After that, you can apply your own trait Billableto the paid model and apply coupons when exchanging plans.
$user
->subscription($product)
->withCoupon($coupon)
->swap($plan);
source
share