order($uuid); abort_if($order === null, 404); $this->uuid = $uuid; $this->label = $order->label(); $this->amountCents = $order->amount_cents; } public function remove(): void { $order = $this->order($this->uuid); // Gone or already paid for: say so instead of pretending it worked. if ($order === null) { $this->dispatch('notify', message: __('billing.cart.gone')); $this->closeModal(); return; } // A downgrade is booked in two places — the cart entry the customer can // see, and the date stamped on the contract that actually carries it // out. Taking the entry back out has to unbook it, or the package would // shrink at the end of the term for a request the customer had already // withdrawn, with nothing left on the page to explain why. if ($order->type === 'downgrade') { $contract = app(CustomDomainAccess::class)->contractOf($this->customer()); if ($contract?->pending_plan === $order->plan) { $contract->clearPendingPlanChange(); } } $order->delete(); $this->dispatch('order-removed'); $this->closeModal(); } /** @return Order|null the customer's own, still-pending order */ private function order(string $uuid): ?Order { $customer = $this->customer(); if ($customer === null) { return null; } return Order::query() ->where('customer_id', $customer->id) ->where('uuid', $uuid) ->where('status', 'pending') ->first(); } public function render() { return view('livewire.confirm-remove-order'); } }