Files
ABSDEV/Modules/Licensing/Http/Controllers/CheckoutHandoffController.php
2026-10-12 15:27:09 +01:00

43 lines
1.5 KiB
PHP

<?php
namespace Modules\Licensing\Http\Controllers;
use Illuminate\Routing\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Contracts\View\View;
/** Checkout handoff only. Billing/webhook processing remains on the legacy service. */
final class CheckoutHandoffController extends Controller
{
public function index(): View
{
return view('licensing::checkout.index', ['enabled' => $this->destination() !== null]);
}
public function redirect(): RedirectResponse
{
$destination = $this->destination();
abort_unless($destination !== null, 503, 'Checkout is not configured.');
return redirect()->away($destination, 302);
}
private function destination(): ?string
{
if (! config('sonardesk-integration.checkout_enabled')) {
return null;
}
$url = trim((string) config('sonardesk-integration.checkout_url'));
$parts = parse_url($url);
if (! is_array($parts) || strtolower($parts['scheme'] ?? '') !== 'https'
|| ! isset($parts['host']) || isset($parts['user']) || isset($parts['pass'])
|| isset($parts['fragment']) || isset($parts['port'])) {
return null;
}
$host = strtolower(rtrim($parts['host'], '.'));
$allowed = array_map(static fn ($value) => strtolower(rtrim((string) $value, '.')), config('sonardesk-integration.allowed_checkout_hosts', []));
if (! in_array($host, $allowed, true)) {
return null;
}
return $url;
}
}