Laravel\Cashier\Subscription::swapAcrossFrequencies PHP Method

swapAcrossFrequencies() protected method

Swap the subscription to a new Braintree plan with a different frequency.
protected swapAcrossFrequencies ( string $plan )
$plan string
    protected function swapAcrossFrequencies($plan)
    {
        $currentPlan = BraintreeService::findPlan($this->braintree_plan);
        $discount = $this->switchingToMonthlyPlan($currentPlan, $plan) ? $this->getDiscountForSwitchToMonthly($currentPlan, $plan) : $this->getDiscountForSwitchToYearly();
        $options = [];
        if ($discount->amount > 0 && $discount->numberOfBillingCycles > 0) {
            $options = ['discounts' => ['add' => [['inheritedFromId' => 'plan-credit', 'amount' => (double) $discount->amount, 'numberOfBillingCycles' => $discount->numberOfBillingCycles]]]];
        }
        $this->cancelNow();
        return $this->user->newSubscription($this->name, $plan->id)->skipTrial()->create(null, [], $options);
    }