order instanceof Id ? $this->repo->ofId($cmd->order) : $cmd->order; $plan = $order->getPlan(); $ws = $order->getWorkspace(); if ($plan->getBillingCycle()->isRenewable()) { $subs = SubscriptionEntity::createFromOrder($order); $ws->subscribe($subs); $order->fulfill(); // Dispatch event $event = new OrderFulfilledEvent($order); $this->dispatcher->dispatch($event); if ( $this->trialWithoutPayment && $order->getTrialPeriodDays()->value > 0 ) { $subs->cancel(); } // Dispatch event $event = new SubscriptionCreatedEvent($subs); $this->dispatcher->dispatch($event); return $subs; } $ws->addCredits($plan->getCreditCount()); $order->fulfill(); // Dispatch event $event = new OrderFulfilledEvent($order); $this->dispatcher->dispatch($event); return $ws; } }