Swap the subscription to a new Stripe plan.

@param  string  $plan
@return $this
439761
public function swap($plan)
    {
        $subscription = $this->asStripeSubscription();

        $subscription->plan = $plan;

        $subscription->prorate = $this->prorate;

        $subscription->cancel_at_period_end = false;

        if (! is_null($this->billingCycleAnchor)) {
            $subscription->billing_cycle_anchor = $this->billingCycleAnchor;
        }

        // If no specific trial end date has been set, the default behavior should be
        // to maintain the current trial state, whether that is "active" or to run
        // the swap out with the exact number of days left on this current plan.
        if ($this->onTrial()) {
            $subscription->trial_end = $this->trial_ends_at->getTimestamp();
        } else {
            $subscription->trial_end = 'now';
        }

        // Again, if no explicit quantity was set, the default behaviors should be to
        // maintain the current quantity onto the new plan. This is a sensible one
        // that should be the expected behavior for most developers with Stripe.
        if ($this->quantity) {
            $subscription->quantity = $this->quantity;
        }

        $subscription->save();

        try {
            $this->user->invoice(['subscription' => $subscription->id]);
        } catch (StripeCard $exception) {
            // When the payment for the plan swap fails, we continue to let the user swap to the
            // new plan. This is because Stripe may attempt to retry the payment later on. If
            // all attempts to collect payment fail, webhooks will handle any update to it.
        }

        $this->fill([
            'stripe_plan' => $plan,
            'ends_at' => null,
        ])->save();

        return $this;
    }
231222
function swap (callable $fn)
  {
    $this->pack ();
    $this->data = $fn ($this->data);
    return $this;
  }
91614
public function prev($offset = 1)
    {
        $prevDateTime = clone $this->startDateTime;
        $prevDateTime->modify('-'.abs($offset).' months');
        return new Month($prevDateTime);
    }
241598
public function commit($savepoint = null){
		$this->connection->getDriver()->commit($savepoint);
		$this->notifyObservers(ObserverInterface::COMMIT);
		return $this;
	}
216662
public function showAction(Plan $plan)
    {
        $deleteForm = $this->createDeleteForm($plan);
        //get plan
        $paypalPlan = $this->get('checkout_manager')->getPaypalPlan($plan);
        
        return array(
            'entity' => $plan,
            'delete_form' => $deleteForm->createView(),
            'paypalPlan' => $paypalPlan
        );
    }
980430
public function setReference($reference = null)
    {
        $reference === null && $reference = PaymentHelper::generateReference($this->getTransactionId());
        $this->params['reference'] = $reference;
        return $this;
    }
334853
public function setSuspended($isSuspended = true)
    {
        if ($this->isSuspended != $isSuspended) {
            $this->isSuspended = $isSuspended;
        }
        return $this;
    }
627018
public function postSubscribe(BillingRequest $request)
    {
        try {
            $payload = $request->all();
            $creditCardToken = $payload['stripeToken'];
            auth()->user()->meta->newSubscription(config('plans.subscription_name'), config('plans.subscription'))->create($creditCardToken);
            return redirect('user/billing/details')->with('message', 'You\'re now subscribed!');
        } catch (Exception $e) {
            Log::error($e->getMessage());
            return back()->withErrors(['Could not process the billing please try again.']);
        }

        return back()->withErrors(['Could not complete billing, please try again.']);
    }
684782
protected function getDiscountForSwitchToMonthly(Plan $currentPlan, Plan $plan)
    {
        return (object) [
            'amount' => $plan->price,
            'numberOfBillingCycles' => floor(
                $this->moneyRemainingOnYearlyPlan($currentPlan) / $plan->price
            ),
        ];
    }
493009
public function addCharge(StripeLocalCharge $charge)
    {
        // If the cards is already set
        if (false === $this->charges->contains($charge)) {
            // Add the card to the collection
            $this->charges->add($charge);
        }

        return $this;
    }
182115
public function subscribe(Subscription $subscription)
    {
        if (!$this->isConnected) {
            return new RejectedPromise(new \LogicException('The client is not connected.'));
        }

        return $this->startFlow(new OutgoingSubscribeFlow([$subscription], $this->identifierGenerator));
    }
492207
public function setTransactionMethod($method)
    {
        // check if is array
        if (!is_array($this->transactionMethods)) {
            $this->transactionMethods = [$method];

            return $this;
        }

        // check if method is already in array
        if (!in_array($method, $this->transactionMethods)) {
            $this->transactionMethods[] = $method;
        }

        return $this;
    }
711523
public function startOneTimeTransaction($amount, $email, $plan = '')
    {
        $oneTimeTransaction = OneTimeTransaction::make(
            $amount,
            $email,
            $plan instanceof Plan ? $plan->get('plan_code') : $plan
        );
        $oneTimeTransaction->setTransactionResource($this->getTransactionResource());
        $transaction = $oneTimeTransaction->initialize();

        if ($transaction instanceof \Exception) {
            throw $transaction;
        }

        return $transaction;
    }
294499
public function setPackage($package, $upgraded = null)
    {
        $this->currency = get_config_value('subscriptions.currency', 'US');
        $this->itemName = $package->name;
        $this->itemId = $package->id;
        $this->itemAmount = $package->price;
        $this->duration = $package->duration;
        $this->billingPeriod = $package->billingPeriod;
        $this->recurring = $package->recurring;

        if ($upgraded) {
            $this->duration = max(0, $package->duration - $upgraded->duration);
            $this->itemAmount = max(0, $package->price - $upgraded->price);
            $this->upgrade = true;
        }

        $this->_package = $package;

        return $this;
    }
877882
public function onPlan($plan): bool
    {
        $plan = $this->getSubscriptions()->where(['stripe_plan' => $plan])->one();

        return !is_null($plan) && $plan->valid();
    }
751310
public function unserialize($subscription): self
    {
        $data = json_decode($subscription, true);

        $this->operationName = $data['operation_name'];
        $this->channel = $data['channel'];
        $this->args = $data['args'];
        $this->context = $this->contextSerializer()->unserialize(
            $data['context']
        );
        $this->query = AST::fromArray(
            unserialize($data['query'])
        );

        return $this;
    }
485470
public function setExchangePctFee($fee)
    {
        if (!empty($fee) && ctype_print($fee)) {
            $this->exchangePercentageFee = trim($fee);
        }

        return $this;
    }