Files
ladill-hosting/app/Services/Domains/LadillDomainsClient.php
T
isaaccladandCursor 2c9877a87c
Deploy Ladill Hosting / deploy (push) Successful in 1m29s
Add platform admin hosting API for Ladill account provisioning.
Expose authenticated service endpoints for assigning, listing, renewing, and managing hosting accounts from the platform, with tests and deploy docs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-03 22:54:00 +00:00

85 lines
2.8 KiB
PHP

<?php
namespace App\Services\Domains;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
/** Read-only client for domains purchased on Ladill (storefront + platform registry). */
class LadillDomainsClient
{
/** @return list<string> Active domain names owned by the account (lowercase). */
public function ownedForUser(string $publicId): array
{
[$storefront, $platform] = $this->fetchOwnedDomainsInParallel($publicId);
return collect()
->merge($storefront)
->merge($platform)
->map(fn ($d) => strtolower(trim((string) $d)))
->filter()
->unique()
->sort()
->values()
->all();
}
/**
* @return array{0: list<string>, 1: list<string>}
*/
private function fetchOwnedDomainsInParallel(string $publicId): array
{
$storefront = [];
$platform = [];
try {
$responses = Http::pool(function ($pool) use ($publicId) {
$requests = [];
$storefrontKey = (string) (config('domains.api_key') ?? '');
if ($storefrontKey !== '') {
$requests['storefront'] = $pool->as('storefront')
->withToken($storefrontKey)
->acceptJson()
->timeout(10)
->get(rtrim((string) config('domains.api_url'), '/').'/owned-domains', [
'user' => $publicId,
]);
}
$platformKey = (string) (config('domains.platform_api_key') ?? '');
if ($platformKey !== '') {
$requests['platform'] = $pool->as('platform')
->withToken($platformKey)
->acceptJson()
->timeout(10)
->get(rtrim((string) config('domains.platform_api_url'), '/').'/owned-domains', [
'user' => $publicId,
]);
}
return $requests;
});
foreach ($responses as $name => $response) {
if (! $response instanceof Response || ! $response->successful()) {
continue;
}
$data = (array) $response->json('data', []);
if ($name === 'storefront') {
$storefront = $data;
} elseif ($name === 'platform') {
$platform = $data;
}
}
} catch (\Throwable $e) {
Log::warning('LadillDomainsClient: owned domains lookup failed', [
'user' => $publicId,
'error' => $e->getMessage(),
]);
}
return [$storefront, $platform];
}
}