Implement the provisioning API endpoints referenced in routes/api.php and add comprehensive PHPDoc to service classes missing documentation. Provisioning API (Issue #15): - ProductApiController: ping, product listing, product lookup by SKU - EntitlementApiController: create, show, suspend, unsuspend, cancel, renew - Uncomment and activate provisioning route group with commerce.api middleware - Register commerce.api and commerce.matrix middleware aliases in Boot.php Service documentation (Issue #14): - CreditNoteService: lifecycle, FIFO ordering, state machine - RefundService: gateway orchestration, eligibility, transaction safety - SubscriptionService: lifecycle, proration, fixed-day billing periods - CouponService: sanitisation, validation, Orderable polymorphism - InvoiceService: PDF generation, storage, email delivery Fixes #14 Fixes #15 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
92 lines
2.4 KiB
PHP
92 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Core\Mod\Commerce\Controllers\Api;
|
|
|
|
use Core\Front\Controller;
|
|
use Core\Mod\Commerce\Models\Product;
|
|
use Core\Mod\Commerce\Services\ProductCatalogService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Provisioning API controller for product catalogue queries.
|
|
*
|
|
* Provides read-only access to the product catalogue for internal
|
|
* services and external integrations. Authenticated via Bearer token
|
|
* through the CommerceApiAuth middleware.
|
|
*/
|
|
class ProductApiController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ProductCatalogService $catalogService,
|
|
) {}
|
|
|
|
/**
|
|
* Health-check / connectivity ping.
|
|
*
|
|
* GET /api/v1/provisioning/ping
|
|
*/
|
|
public function ping(): JsonResponse
|
|
{
|
|
return response()->json([
|
|
'status' => 'ok',
|
|
'service' => 'commerce-provisioning',
|
|
'timestamp' => now()->toIso8601String(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* List all active, visible products.
|
|
*
|
|
* GET /api/v1/provisioning/products
|
|
*
|
|
* Query parameters:
|
|
* - category: filter by product category
|
|
* - type: filter by product type (simple, virtual, subscription, etc.)
|
|
* - per_page: pagination size (default 25, max 100)
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$query = Product::query()
|
|
->active()
|
|
->visible()
|
|
->orderBy('sort_order');
|
|
|
|
if ($category = $request->get('category')) {
|
|
$query->where('category', $category);
|
|
}
|
|
|
|
if ($type = $request->get('type')) {
|
|
$query->where('type', $type);
|
|
}
|
|
|
|
$perPage = min((int) $request->get('per_page', 25), 100);
|
|
$products = $query->paginate($perPage);
|
|
|
|
return response()->json($products);
|
|
}
|
|
|
|
/**
|
|
* Show a single product by SKU code.
|
|
*
|
|
* GET /api/v1/provisioning/products/{code}
|
|
*/
|
|
public function show(string $code): JsonResponse
|
|
{
|
|
$product = Product::where('sku', strtoupper($code))
|
|
->active()
|
|
->visible()
|
|
->first();
|
|
|
|
if (! $product) {
|
|
return response()->json([
|
|
'error' => 'not_found',
|
|
'message' => "Product with SKU '{$code}' not found",
|
|
], 404);
|
|
}
|
|
|
|
return response()->json(['data' => $product]);
|
|
}
|
|
}
|