protected function swapAcrossFrequencies($plan): self
    {
        $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' => (float) $discount->amount,
                    'numberOfBillingCycles' => $discount->numberOfBillingCycles,
                ],
            ]]];
        }

        $this->cancelNow();

        return $this->owner->newSubscription($this->name, $plan->id)
            ->skipTrial()
            ->create(null, [], $options);
    }
protected function swapAcrossFrequencies($plan): self
    {
        $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' => (float) $discount->amount,
                    'numberOfBillingCycles' => $discount->numberOfBillingCycles,
                ],
            ]]];
        }

        $this->cancelNow();

        return $this->owner->newSubscription($this->name, $plan->id)
            ->skipTrial()
            ->create(null, [], $options);
    }
protected function swapAcrossFrequencies ( $ plan ) : self { $ 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' => ( float ) $ discount -> amount , 'numberOfBillingCycles' => $ discount -> numberOfBillingCycles , ] , ] ] ] ; } $ this -> cancelNow ( ) ; return $ this -> owner -> newSubscription ( $ this -> name , $ plan -> id ) -> skipTrial ( ) -> create ( null , [ ] , $ options ) ; }
Swap the subscription to a new Braintree plan with a different frequency.

@param  \Braintree\Plan  $plan
@return \Laravel\Cashier\Subscription
@throws \Exception
Swap the subscription to a new Braintree plan with a different frequency .