/** * Cancel the billable entity's subscription. * * @return void */ public function cancel($atPeriodEnd = true) { $customer = $this->getStripeCustomer(); if ($customer->subscription) { if ($atPeriodEnd) { $this->billable->setSubscriptionEndDate(Carbon::createFromTimestamp($this->getSubscriptionEndTimestamp($customer))); } $customer->cancelSubscription(['at_period_end' => $atPeriodEnd]); } if ($atPeriodEnd) { $this->billable->setStripeIsActive(false)->saveBillableInstance(); } else { $this->billable->setSubscriptionEndDate(Carbon::now()); $this->billable->deactivateStripe()->saveBillableInstance(); } }