This is how the call currently looks with applying the coupon code:
$return['success'] = ($this->user->newSubscription('pro', $planId)
->trialDays(config('services.subscription.trial_days'))
->withCoupon($request->couponCode)
->create($request->payment_method)) ? true : false;
the newSubscription method is from the Billable trait:
public function newSubscription($subscription, $plan)
{
return new SubscriptionBuilder($this, $subscription, $plan);
}
The SubscriptionBuilder() is on SubscriptionBuilder class.
It looks like I just need to add a property on to the SubscriptionBuilder create():
public function create($paymentMethod = null, array $options = [])
{
$customer = $this->getStripeCustomer($paymentMethod, $options);
/** @var \Stripe\Subscription $stripeSubscription */
$stripeSubscription = $customer->subscriptions->create($this->buildPayload());
if ($this->skipTrial) {
$trialEndsAt = null;
} else {
$trialEndsAt = $this->trialExpires;
}
/** @var \Laravel\Cashier\Subscription $subscription */
$subscription = $this->owner->subscriptions()->create([
'name' => $this->name,
'stripe_id' => $stripeSubscription->id,
'stripe_status' => $stripeSubscription->status,
'stripe_plan' => $this->plan,
'quantity' => $this->quantity,
'trial_ends_at' => $trialEndsAt,
'ends_at' => null,
]);
if ($subscription->incomplete()) {
(new Payment(
$stripeSubscription->latest_invoice->payment_intent
))->validate();
}
return $subscription;
}
Via the stripe api docs, I just need to pass the "promotional_code" property. I'm just not sure, how I go about modifying in my app.