You are here

public function Subscription::cancel in Commerce Recurring Framework 8

Cancel the subscription.

Parameters

bool $schedule: Whether to schedule the cancellation.

Return value

$this

Overrides SubscriptionInterface::cancel

File

src/Entity/Subscription.php, line 671

Class

Subscription
Defines the subscription entity.

Namespace

Drupal\commerce_recurring\Entity

Code

public function cancel($schedule = TRUE) {
  if ($schedule) {
    $transition = $this
      ->getState()
      ->getWorkflow()
      ->getTransition('cancel');
    $state_id = $transition
      ->getToState()
      ->getId();
    $this
      ->addScheduledChange('state', $state_id);
  }
  else {
    $this
      ->getState()
      ->applyTransitionById('cancel');
  }
  return $this;
}