Deploy Ladill Woo Manager / deploy (push) Failing after 2s
Standalone app with SSO shell, WordPress plugin connect flow, webhook ingest, fulfillment inbox, and plugin activation API — no payment processing. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.5 KiB
PHP
81 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\WooStore;
|
|
use App\Services\Woo\InstallTokenService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use RuntimeException;
|
|
|
|
class StoreActivationController extends Controller
|
|
{
|
|
public function __construct(private InstallTokenService $tokens) {}
|
|
|
|
public function activate(Request $request): JsonResponse
|
|
{
|
|
$validated = $request->validate([
|
|
'install_token' => ['required', 'string'],
|
|
'site_url' => ['required', 'url', 'max:500'],
|
|
]);
|
|
|
|
try {
|
|
$store = $this->tokens->consume($validated['install_token']);
|
|
} catch (RuntimeException $e) {
|
|
return response()->json(['message' => $e->getMessage()], 422);
|
|
}
|
|
|
|
$parsed = parse_url($validated['site_url']);
|
|
$scheme = $parsed['scheme'] ?? 'https';
|
|
$host = strtolower((string) ($parsed['host'] ?? ''));
|
|
$siteUrl = rtrim($scheme.'://'.$host, '/');
|
|
if ($store->site_url !== $siteUrl) {
|
|
return response()->json(['message' => 'Site URL does not match the connection request.'], 422);
|
|
}
|
|
|
|
$pluginToken = $this->tokens->issuePluginToken($store);
|
|
$store = $store->fresh();
|
|
|
|
return response()->json([
|
|
'store_id' => $store->public_id,
|
|
'webhook_url' => $store->webhookUrl(),
|
|
'webhook_secret' => $store->webhook_secret,
|
|
'plugin_token' => $pluginToken,
|
|
'webhook_topics' => config('woo.webhook_topics'),
|
|
]);
|
|
}
|
|
|
|
public function show(Request $request): JsonResponse
|
|
{
|
|
$store = $this->storeFromRequest($request);
|
|
if (! $store) {
|
|
return response()->json(['message' => 'Unauthorized.'], 401);
|
|
}
|
|
|
|
return response()->json([
|
|
'store_id' => $store->public_id,
|
|
'site_url' => $store->site_url,
|
|
'site_name' => $store->site_name,
|
|
'status' => $store->status,
|
|
'webhook_url' => $store->webhookUrl(),
|
|
]);
|
|
}
|
|
|
|
private function storeFromRequest(Request $request): ?WooStore
|
|
{
|
|
$storeId = (string) $request->header('X-Ladill-Store', '');
|
|
$token = (string) $request->bearerToken();
|
|
if ($storeId === '' || $token === '') {
|
|
return null;
|
|
}
|
|
|
|
$store = WooStore::query()->where('public_id', $storeId)->first();
|
|
if (! $store || ! $this->tokens->verifyPluginToken($store, $token)) {
|
|
return null;
|
|
}
|
|
|
|
return $store;
|
|
}
|
|
}
|