Files
ladill-events/app/Http/Controllers/Public/EventRegistrationController.php
T
isaaccladandCursor e234889f60
Deploy Ladill Events / deploy (push) Successful in 35s
Make guest event registration email-optional like Ladill Mini.
Attendees without Ladill accounts no longer need email at checkout; phone is required so organizers can reach them.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 14:18:45 +00:00

87 lines
3.0 KiB
PHP

<?php
namespace App\Http\Controllers\Public;
use App\Http\Controllers\Controller;
use App\Models\QrCode;
use App\Models\QrEventRegistration;
use App\Services\Events\EventRegistrationService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use RuntimeException;
class EventRegistrationController extends Controller
{
public function __construct(private EventRegistrationService $eventService) {}
public function register(Request $request, string $shortCode): JsonResponse
{
$qrCode = QrCode::query()
->where('short_code', $shortCode)
->where('is_active', true)
->firstOrFail();
abort_unless($qrCode->type === QrCode::TYPE_EVENT, 404);
$request->validate([
'tier' => ['required', 'string', 'max:80'],
'amount' => ['nullable', 'numeric', 'min:1', 'max:1000000'],
'attendee_name' => ['required', 'string', 'max:120'],
'attendee_email' => ['nullable', 'email', 'max:200'],
'attendee_phone' => ['required', 'string', 'max:30'],
'badge_fields' => ['nullable', 'array'],
]);
try {
$result = $this->eventService->register($qrCode, $request->all());
} catch (RuntimeException $e) {
return response()->json(['error' => $e->getMessage()], 422);
}
return response()->json([
'paid' => $result['paid'],
'checkout_url' => $result['checkout_url'],
'badge_code' => $result['registration']->badge_code,
'success_url' => route('qr.public.event.confirmed', [
'shortCode' => $qrCode->short_code,
'ref' => $result['registration']->reference,
]),
]);
}
public function callback(Request $request, string $shortCode): RedirectResponse|View
{
$reference = (string) $request->query('reference', '');
if ($reference === '') {
return redirect('/q/' . $shortCode)->with('error', 'Missing payment reference.');
}
try {
$registration = $this->eventService->complete($reference);
return redirect()->route('qr.public.event.confirmed', [
'shortCode' => $shortCode,
'ref' => $registration->reference,
]);
} catch (\Throwable $e) {
return redirect('/q/' . $shortCode)->with('order_error', 'Payment could not be verified. Reference: ' . $reference);
}
}
public function confirmed(string $shortCode, string $ref): View
{
$registration = QrEventRegistration::query()
->where('reference', $ref)
->whereHas('qrCode', fn ($q) => $q->where('short_code', $shortCode))
->firstOrFail();
return view('public.qr.event-confirmed', [
'registration' => $registration,
'qrCode' => $registration->qrCode,
]);
}
}