hooks in config/services.php/.env.example, and updated wizard steps/controllers to store session payloads, attach packages, and surface localized success/error states. - Retooled payment handling for both Stripe and PayPal, adding richer status management in CheckoutController/ PayPalController, fallback flows in the wizard’s PaymentStep.tsx, and fresh feature tests for intent creation, webhooks, and the wizard CTA. - Introduced a consent-aware Matomo analytics stack: new consent context, cookie-banner UI, useAnalytics/ useCtaExperiment hooks, and MatomoTracker component, then instrumented marketing pages (Home, Packages, Checkout) with localized copy and experiment tracking. - Polished package presentation across marketing UIs by centralizing formatting in PresentsPackages, surfacing localized description tables/placeholders, tuning badges/layouts, and syncing guest/marketing translations. - Expanded docs & reference material (docs/prp/*, TODOs, public gallery overview) and added a Playwright smoke test for the hero CTA while reconciling outstanding checklist items.
87 lines
2.6 KiB
PHP
87 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Models\Event;
|
|
use App\Models\Tenant;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class PackageMiddleware
|
|
{
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
$tenant = $request->attributes->get('tenant');
|
|
if (! $tenant instanceof Tenant) {
|
|
$tenant = $this->resolveTenant($request);
|
|
$request->attributes->set('tenant', $tenant);
|
|
$request->attributes->set('tenant_id', $tenant->id);
|
|
$request->merge([
|
|
'tenant' => $tenant,
|
|
'tenant_id' => $tenant->id,
|
|
]);
|
|
}
|
|
|
|
if ($this->requiresPackageCheck($request) && ! $this->canPerformAction($request, $tenant)) {
|
|
return response()->json([
|
|
'error' => 'Package limits exceeded. Please purchase or upgrade a package.',
|
|
], 402);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
|
|
private function requiresPackageCheck(Request $request): bool
|
|
{
|
|
return $request->isMethod('post') && (
|
|
$request->routeIs('api.v1.tenant.events.store') ||
|
|
$request->routeIs('api.v1.tenant.events.photos.store')
|
|
);
|
|
}
|
|
|
|
private function canPerformAction(Request $request, Tenant $tenant): bool
|
|
{
|
|
if ($request->routeIs('api.v1.tenant.events.store')) {
|
|
return $tenant->hasEventAllowance();
|
|
}
|
|
|
|
if ($request->routeIs('api.v1.tenant.events.photos.store')) {
|
|
$eventId = $request->input('event_id');
|
|
if (! $eventId) {
|
|
return false;
|
|
}
|
|
$event = Event::query()->find($eventId);
|
|
if (! $event || $event->tenant_id !== $tenant->id) {
|
|
return false;
|
|
}
|
|
$eventPackage = $event->eventPackage;
|
|
if (! $eventPackage) {
|
|
return false;
|
|
}
|
|
return $eventPackage->used_photos < ($eventPackage->package->max_photos ?? PHP_INT_MAX);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private function resolveTenant(Request $request): Tenant
|
|
{
|
|
$user = $request->user();
|
|
if ($user && isset($user->tenant) && $user->tenant instanceof Tenant) {
|
|
return $user->tenant;
|
|
}
|
|
|
|
$tenantId = $request->attributes->get('tenant_id');
|
|
if (! $tenantId && $user && isset($user->tenant_id)) {
|
|
$tenantId = $user->tenant_id;
|
|
}
|
|
|
|
if (! $tenantId) {
|
|
abort(401, 'Unauthenticated');
|
|
}
|
|
|
|
return Tenant::findOrFail($tenantId);
|
|
}
|
|
}
|