public function cancel()
{
$subscription = $this->asBraintreeSubscription();
if ($this->onTrial()) {
BraintreeSubscription::cancel($subscription->id);
$this->markAsCancelled();
} else {
BraintreeSubscription::update($subscription->id, ['numberOfBillingCycles' => $subscription->currentBillingCycle]);
$this->ends_at = $subscription->billingPeriodEndDate;
$this->save();
}
return $this;
}