Files
ladill-events/app/Http/Controllers/Public/EventRegistrationController.php
T
isaaccladandCursor ab192e443f
Deploy Ladill Events / deploy (push) Successful in 1m42s
Embed event checkouts and send seller email to gateways.
Ticket/contribution payments open in a desktop modal or mobile sheet, initialize with the organizer email, and break out of the iframe after callback.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-15 08:29:13 +00:00

110 lines
3.8 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 App\Support\LadillLink;
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'],
'meet_return' => ['nullable', 'string', 'max:2048'],
]);
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' => $this->confirmedUrl($qrCode, $result['registration'], $request->input('meet_return')),
]);
}
public function callback(Request $request, string $shortCode): RedirectResponse|View
{
$reference = (string) $request->query('reference', '');
if ($reference === '') {
return view('public.payment-return', [
'redirect' => LadillLink::url($shortCode),
]);
}
try {
$registration = $this->eventService->complete($reference);
return view('public.payment-return', [
'redirect' => $this->confirmedUrl($registration->qrCode, $registration),
]);
} catch (\Throwable $e) {
return view('public.payment-return', [
'redirect' => LadillLink::url($shortCode),
]);
}
}
public function confirmed(Request $request, string $shortCode, string $ref): View
{
$registration = QrEventRegistration::query()
->where('reference', $ref)
->whereHas('qrCode', fn ($q) => $q->where('short_code', $shortCode))
->firstOrFail();
$meetReturn = (string) $request->query('meet_return', '');
if ($meetReturn === '') {
$meetReturn = (string) (($registration->metadata ?? [])['meet_return'] ?? '');
}
return view('public.qr.event-confirmed', [
'registration' => $registration,
'qrCode' => $registration->qrCode,
'meetReturn' => $meetReturn,
]);
}
private function confirmedUrl(QrCode $qrCode, QrEventRegistration $registration, ?string $meetReturn = null): string
{
$url = LadillLink::path($qrCode->short_code, 'registered/'.$registration->reference);
$meetReturn = trim((string) ($meetReturn ?? ''));
if ($meetReturn === '') {
$meetReturn = trim((string) (($registration->metadata ?? [])['meet_return'] ?? ''));
}
if ($meetReturn !== '') {
$url .= '?meet_return='.urlencode($meetReturn);
}
return $url;
}
}