You are here

public function LicenseSubscription::onSubscriptionCancel in Commerce License 8.2

Acts on a subscription after it has been canceled.

Called before the subscription is saved.

Parameters

\Drupal\commerce_recurring\Entity\SubscriptionInterface $subscription: The subscription.

Overrides SubscriptionTypeBase::onSubscriptionCancel

File

src/Plugin/Commerce/SubscriptionType/LicenseSubscription.php, line 106

Class

LicenseSubscription
Provides a Commerce Recurring subscription type for use with licenses.

Namespace

Drupal\commerce_license\Plugin\Commerce\SubscriptionType

Code

public function onSubscriptionCancel(SubscriptionInterface $subscription) {
  $license = $subscription->license->entity;

  // Change the license's state to canceled.
  $transition = $license
    ->getState()
    ->getWorkflow()
    ->getTransition('cancel');
  $license
    ->getState()
    ->applyTransition($transition);
  $license
    ->save();
}