示例#1
0
 /**
  * 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)));
         } else {
             $this->billable->setSubscriptionEndDate(Carbon::now());
         }
     }
     $customer->cancelSubscription(['at_period_end' => $atPeriodEnd]);
     if ($atPeriodEnd) {
         $this->billable->setStripeIsActive(false)->saveBillableInstance();
     } else {
         $this->billable->deactivateStripe()->saveBillableInstance();
     }
 }