- VmProvisionException/VmProvisionRefund xử lý lỗi cấp phát VM - QueueJobInspector + QueueMonitorController xem chi tiết job - Thêm service uuid cho ticket, thời lượng cho activity_logs - Migration chuẩn hoá RAM addon sang MB, trạng thái deleting cho snapshot Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\VirtualMachine;
|
|
|
|
use App\Enums\Invoice\InvoiceStatus;
|
|
use App\Enums\Order\OrderStatus;
|
|
use App\Models\OrderItem;
|
|
use App\Services\InvoicePaymentService;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Throwable;
|
|
|
|
class VmProvisionRefund
|
|
{
|
|
public function __construct(private readonly InvoicePaymentService $payments)
|
|
{
|
|
}
|
|
|
|
public function refund(OrderItem $item, string $reason): bool
|
|
{
|
|
$order = $item->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;
|
|
}
|
|
}
|
|
}
|