public function SubscriptionActivate::process in Commerce Recurring Framework 8
Processes the given job.
Parameters
\Drupal\advancedqueue\Job $job: The job.
Return value
\Drupal\advancedqueue\JobResult The job result.
Overrides JobTypeInterface::process
File
- src/
Plugin/ AdvancedQueue/ JobType/ SubscriptionActivate.php, line 21
Class
- SubscriptionActivate
- Provides the job type for activating subscriptions.
Namespace
Drupal\commerce_recurring\Plugin\AdvancedQueue\JobTypeCode
public function process(Job $job) {
$subscription_id = $job
->getPayload()['subscription_id'];
$subscription_storage = $this->entityTypeManager
->getStorage('commerce_subscription');
/** @var \Drupal\commerce_recurring\Entity\SubscriptionInterface $subscription */
$subscription = $subscription_storage
->load($subscription_id);
if (!$subscription) {
return JobResult::failure('Subscription not found.');
}
if (!in_array($subscription
->getState()
->getId(), [
'pending',
'trial',
], TRUE)) {
return JobResult::failure(sprintf('Unsupported subscription status. Supported statuses: ("trial", "pending"), Actual: "%s").', $subscription
->getState()
->getId()));
}
$subscription
->getState()
->applyTransitionById('activate');
$subscription
->save();
$this->recurringOrderManager
->startRecurring($subscription);
return JobResult::success();
}