Files
ladill-mini/app/Http/Controllers/Public/PaymentController.php
T
isaaccladandCursor 3fd5d785e3
Deploy Ladill Mini / deploy (push) Successful in 39s
Use ladl.link URLs for all front-facing QR and short-link surfaces.
Public landing pages, asset paths, payment callbacks, and redirects now go through QrCode::publicPath() / LadillLink instead of ladill.com/q/* routes.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-27 15:46:22 +00:00

68 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers\Public;
use App\Http\Controllers\Controller;
use App\Models\QrCode;
use App\Services\Mini\MiniPaymentService;
use App\Support\LadillLink;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use RuntimeException;
class PaymentController extends Controller
{
public function __construct(private MiniPaymentService $payments) {}
public function pay(Request $request, string $shortCode): JsonResponse|RedirectResponse
{
$qrCode = QrCode::query()
->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()->away(LadillLink::url($shortCode))->with('error', 'Missing payment reference.');
}
try {
$payment = $this->payments->complete($reference);
} catch (RuntimeException $e) {
return redirect()->away(LadillLink::url($shortCode))->with('error', $e->getMessage());
}
return view('public.qr.payment-confirmed', [
'payment' => $payment,
'qrCode' => $payment->qrCode,
]);
}
}