with('user.qrSetting') ->where('short_code', $shortCode) ->where('type', QrCode::TYPE_PAYMENT) ->where('is_active', true) ->firstOrFail(); $validated = $request->validate([ 'amount' => 'required|numeric|min:0.01', ]); try { $result = $this->payments->initiate($qrCode, $validated); } catch (RuntimeException $e) { if ($request->expectsJson()) { return response()->json(['error' => $e->getMessage()], 422); } return back()->withInput()->with('error', $e->getMessage()); } if ($request->expectsJson()) { return response()->json(['checkout_url' => $result['checkout_url']]); } return redirect()->away($result['checkout_url']); } public function callback(Request $request, string $shortCode): RedirectResponse|View { $reference = trim((string) $request->query('reference', '')); if ($reference === '') { return redirect('/q/'.$shortCode)->with('error', 'Missing payment reference.'); } try { $payment = $this->payments->complete($reference); } catch (RuntimeException $e) { return redirect('/q/'.$shortCode)->with('error', $e->getMessage()); } return view('public.qr.payment-confirmed', [ 'payment' => $payment, 'qrCode' => $payment->qrCode, ]); } }