Deploy Ladill Merchant / deploy (push) Successful in 1m36s
Push the customer's connected domain to the central connected-domains registry so it appears under My Domains (with Transfer in if not registered with Ladill). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Merchant;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\CustomDomain;
|
|
use App\Models\QrCode;
|
|
use App\Services\CustomDomain\CustomDomainService;
|
|
use App\Services\CustomDomain\DomainsSslClient;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CustomDomainController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly CustomDomainService $service,
|
|
private readonly DomainsSslClient $domains,
|
|
) {}
|
|
|
|
public function store(Request $request, QrCode $storefront): RedirectResponse
|
|
{
|
|
abort_unless($storefront->user_id === $request->user()->id, 403);
|
|
abort_unless($this->service->enabled(), 404);
|
|
|
|
$data = $request->validate([
|
|
'host' => ['required', 'string', 'max:255', 'regex:/^(?!-)([a-z0-9-]+\.)+[a-z]{2,}$/i'],
|
|
'include_www' => ['nullable', 'boolean'],
|
|
]);
|
|
|
|
$host = strtolower(preg_replace('/^www\./', '', trim($data['host'])));
|
|
|
|
if (CustomDomain::where('host', $host)->exists()) {
|
|
return back()->withErrors(['host' => 'That domain is already connected.']);
|
|
}
|
|
|
|
$this->service->attach($storefront, $host, (bool) ($data['include_www'] ?? true));
|
|
|
|
// Surface this domain in Ladill Domains' "My Domains" (best-effort).
|
|
$this->domains->registerConnected(
|
|
$host,
|
|
(string) $request->user()->public_id,
|
|
'Storefront: '.$storefront->label,
|
|
route('merchant.storefronts.show', $storefront),
|
|
);
|
|
|
|
return back()->with('success', "Domain added. Point an A record for {$host} (and www) to ".config('customdomain.server_ip').', then click Verify.');
|
|
}
|
|
|
|
public function verify(Request $request, CustomDomain $customDomain): RedirectResponse
|
|
{
|
|
abort_unless($customDomain->user_id === $request->user()->id, 403);
|
|
|
|
[$ok, $message] = $this->service->verifyAndProvision($customDomain);
|
|
|
|
return back()->with($ok ? 'success' : 'error', $message);
|
|
}
|
|
|
|
public function destroy(Request $request, CustomDomain $customDomain): RedirectResponse
|
|
{
|
|
abort_unless($customDomain->user_id === $request->user()->id, 403);
|
|
|
|
$host = $customDomain->host;
|
|
$customDomain->delete();
|
|
$this->domains->removeConnected($host);
|
|
|
|
return back()->with('success', 'Custom domain removed.');
|
|
}
|
|
}
|