/** * Resume a canceled subscription in the billing gateway. * * @param int $quantity * * @return Subscription */ public function resume($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->canceled()) { return $this; } if (($customer = $this->model->customer()) && $this->card_token) { $this->card = $customer->creditcards()->create($this->card_token)->id; $this->card_token = null; } $this->subscription = Billing::subscription($this->model->billing_subscription, $customer ? $customer->gatewayCustomer() : null); if ($this->subscription->info()) { $this->subscription->update(array('plan' => $this->plan, 'trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'prorate' => false, 'quantity' => $quantity, 'card_token' => $this->card_token, 'source' => $this->card, 'billing_active' => 1)); } else { $this->subscription = Billing::subscription(null, $customer ? $customer->gatewayCustomer() : null)->create($this->plan, array('trial_ends_at' => $this->skip_trial ? date('Y-m-d H:i:s') : $this->model->billing_trial_ends_at, 'quantity' => $quantity, 'card_token' => $this->card_token, 'card' => $this->card)); } $this->refresh(); return $this; }
/** * Return the gateway subscription object for this model. * * @return LinkThrow\Billing\Gateways\SubscriptionInterface */ public function gatewaySubscription() { if (!$this->everSubscribed()) { return null; } if ($customer = $this->customer()) { $customer = $customer->gatewayCustomer(); } return Billing::subscription($this->billing_subscription, $customer); }