/**
  * Swap this subscription to a new plan in the billing gateway.
  *
  * @param int $quantity
  *
  * @return Subscription
  */
 public function swap($quantity = null)
 {
     if (null === $quantity) {
         $quantity = $this->model->billing_quantity;
     }
     if ($this->is_free || $this->canLocalTrial()) {
         return $this->storeLocal(array('quantity' => $quantity));
     }
     if (!$this->model->billingIsActive()) {
         if ($this->model->canceled()) {
             return $this->resume($quantity);
         } else {
             return $this->create(array('quantity' => $quantity));
         }
     }
     if (($customer = $this->model->customer()) && $this->card_token) {
         $this->card = $customer->creditcards()->create($this->card_token)->id;
         $this->card_token = null;
     }
     // 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 current trial period.
     if (!$this->model->billing_trial_ends_at) {
         $this->skipTrial();
     }
     $this->subscription->update(array('plan' => $this->plan, 'quantity' => $quantity, 'trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'card_token' => $this->card_token, 'card' => $this->card));
     $this->refresh();
     return $this;
 }