workspace instanceof Id ? $this->wrepo->ofId($cmd->workspace) : $cmd->workspace; $plan = $cmd->plan instanceof Id ? $this->prepo->ofId($cmd->plan) : $cmd->plan; $order = new OrderEntity( $ws, $plan, CurrencyCode::tryFrom($this->currency) ?? CurrencyCode::USD, new TrialPeriodDays($this->trialPeriodDays) ); if ( $this->trialWithoutPayment && $order->getTrialPeriodDays()->value > 0 ) { // Mark the order as paid $order->pay(); } if ($order->getTotalPrice()->value === 0) { $order->pay(); } $this->orepo->add($order); // Dispatch the order created event $event = new OrderCreatedEvent($order); $this->dispatcher->dispatch($event); return $order; } }