Files
ladill-woo-manager/app/Http/Controllers/WooWebhookController.php
T
isaaccladandCursor ffe0b9d877
Deploy Ladill Woo Manager / deploy (push) Failing after 2s
Scaffold Ladill Woo Manager for WooCommerce order fulfillment.
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>
2026-07-06 22:39:38 +00:00

52 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\WooStore;
use App\Services\Woo\OrderIngestService;
use App\Services\Woo\WooWebhookVerifier;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class WooWebhookController extends Controller
{
public function __construct(
private WooWebhookVerifier $verifier,
private OrderIngestService $ingest,
) {}
public function __invoke(Request $request, string $storePublicId): JsonResponse
{
$store = WooStore::query()
->where('public_id', $storePublicId)
->where('status', WooStore::STATUS_ACTIVE)
->first();
if (! $store) {
return response()->json(['message' => 'Store not found.'], 404);
}
if (! $this->verifier->verify($request, $store)) {
return response()->json(['message' => 'Invalid signature.'], 401);
}
$topic = (string) $request->header('X-WC-Webhook-Topic', '');
if (! in_array($topic, (array) config('woo.webhook_topics', []), true)) {
return response()->json(['ignored' => true]);
}
/** @var array<string, mixed> $payload */
$payload = $request->json()->all();
if ($payload === []) {
return response()->json(['ignored' => true]);
}
$order = $this->ingest->ingest($store, $payload);
return response()->json([
'ok' => true,
'order_id' => $order->id,
]);
}
}