Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Hosting;
|
||||
|
||||
use App\Jobs\ProvisionHostingOrderJob;
|
||||
use App\Models\CustomerHostingOrder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class HostingOrderFulfillmentService
|
||||
{
|
||||
/**
|
||||
* Approve and queue provisioning. Upstream failures (e.g. Contabo low balance)
|
||||
* are handled when {@see ProvisionHostingOrderJob} runs.
|
||||
*
|
||||
* @return array{fulfilled: bool, reasons: array<int, string>}
|
||||
*/
|
||||
public function attemptAutoFulfillment(CustomerHostingOrder $order): array
|
||||
{
|
||||
$order->refresh()->loadMissing('product');
|
||||
|
||||
if (! $this->isEligibleForAutoFulfillment($order)) {
|
||||
return ['fulfilled' => false, 'reasons' => ['Order is not eligible for automatic fulfillment.']];
|
||||
}
|
||||
|
||||
$this->approveAndQueue($order);
|
||||
|
||||
return ['fulfilled' => true, 'reasons' => []];
|
||||
}
|
||||
|
||||
public function approveAndQueue(CustomerHostingOrder $order): void
|
||||
{
|
||||
if ($order->status === CustomerHostingOrder::STATUS_APPROVED) {
|
||||
ProvisionHostingOrderJob::dispatch($order->fresh());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$meta = $order->meta ?? [];
|
||||
unset($meta['upstream_funds_hold'], $meta['upstream_funds_hold_at'], $meta['provisioning_hold']);
|
||||
|
||||
$order->update([
|
||||
'status' => CustomerHostingOrder::STATUS_APPROVED,
|
||||
'approved_at' => now(),
|
||||
'approved_by' => null,
|
||||
'meta' => $meta,
|
||||
]);
|
||||
|
||||
ProvisionHostingOrderJob::dispatch($order->fresh());
|
||||
|
||||
Log::info('Hosting order queued for provisioning', [
|
||||
'order_id' => $order->id,
|
||||
'domain_name' => $order->domain_name,
|
||||
]);
|
||||
}
|
||||
|
||||
private function isEligibleForAutoFulfillment(CustomerHostingOrder $order): bool
|
||||
{
|
||||
return in_array($order->status, [
|
||||
CustomerHostingOrder::STATUS_PENDING_APPROVAL,
|
||||
CustomerHostingOrder::STATUS_PENDING_PAYMENT,
|
||||
], true) || (
|
||||
$order->status === CustomerHostingOrder::STATUS_APPROVED
|
||||
&& $order->provisioned_at === null
|
||||
&& $order->hosting_account_id === null
|
||||
&& $order->vps_instance_id === null
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user