Refactor order payment process and enhance invoice details

- Updated `payOrder` method in `OrderControllerRefactor` to accept `orderNum` instead of `id` for better clarity and functionality.
- Implemented `findByOrderNum` method in `OrderRepository` to retrieve orders based on order number and customer ID.
- Enhanced `InvoiceDetailResource` to include VMware details and removed unnecessary fields.
- Added `service_plan_id` to `ProductResource` and updated the `Product` model to establish a relationship with `ServicePlan`.
- Created `ServicePlan` and `ServicePlanPlesk` models along with their respective controllers and migrations for managing hosting service plans.
- Updated API routes to include endpoints for managing service plans.
- Modified email templates to standardize support phone number across various customer communications.
This commit is contained in:
baodev0
2026-08-11 10:12:25 +07:00
parent e3d3dea8aa
commit 7314313198
26 changed files with 329 additions and 32 deletions
@@ -13,7 +13,6 @@ class InvoiceDetailResource extends JsonResource
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'invoice_number' => $this->invoice_number,
'invoice_type' => $this->invoice_type,
'status' => $this->status,
@@ -28,18 +27,15 @@ class InvoiceDetailResource extends JsonResource
'due_date' => $this->due_date?->toISOString(),
'paid_at' => $this->paid_at?->toISOString(),
'customer' => $this->whenLoaded('customer', fn () => [
'id' => $this->customer->id,
'name' => $this->customer->fullname,
'email' => $this->customer->email,
'address' => $this->customer->address,
]),
'order' => $this->whenLoaded('order', fn () => [
'id' => $this->order->id,
'order_num' => $this->order->order_num,
'total' => (float) $this->order->total,
]),
'items' => $this->whenLoaded('order', fn () => $this->order->orderItems->map(fn ($item) => [
'id' => $item->id,
'product_name' => $item->product?->name,
'server_name' => $item->server_name,
'billing_cycle' => $item->billing_cycle,
@@ -48,11 +44,36 @@ class InvoiceDetailResource extends JsonResource
'os_id' => $item->os_id,
])->values()->all()),
'attachments' => $this->whenLoaded('attachments', fn () => $this->attachments->map(fn ($a) => [
'id' => $a->id,
'filename' => $a->filename,
'url' => $a->url,
'mime_type' => $a->mime_type,
])->all()),
'vmware' => $this->when(
$this->order?->relationLoaded('vmWare') && $this->order->vmWare->isNotEmpty(),
fn () => $this->resolveVmware($this->order->vmWare->first()),
),
];
}
private function resolveVmware(\App\Models\ModuleVmware $vm): array
{
return [
'id' => $vm->id,
'uuid' => $vm->service?->uuid,
'name' => $vm->name,
'hostname' => $vm->hostname,
'ip_address' => $vm->ip,
'os_name' => $vm->os?->name,
'status' => $vm->status,
'username' => $vm->user,
'port' => $vm->port,
'power_state' => match ($vm->virtualMachine?->power_state) {
'POWERED_ON' => 'poweredOn',
'POWERED_OFF' => 'poweredOff',
'SUSPENDED' => 'suspended',
default => null,
},
'next_due_date' => $vm->next_due_date ? \Illuminate\Support\Carbon::createFromTimestamp($vm->next_due_date)->toISOString() : null,
];
}
}