order; $invoice = $order?->invoice; if (!$invoice || (int) $invoice->status !== InvoiceStatus::PAID->value || $order->orderItems()->count() !== 1) { return false; } try { $this->payments->refund($invoice, null, null, 'Tự động hoàn tiền do khởi tạo máy ảo thất bại: ' . $reason); $order->update(['status' => OrderStatus::CANCELLED->value]); return true; } catch (Throwable $e) { Log::error('VmProvisionRefund failed', ['order_item_id' => $item->id, 'error' => $e->getMessage()]); return false; } } }