Lean control center at mini.ladill.com: payment QR CRUD, Paystack checkout with 5% fee settlement via Billing API, payments feed, and payouts. QR codes use a fixed black-and-white preset only. Co-authored-by: Cursor <cursoragent@cursor.com>
61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Public;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\QrCode;
|
|
use App\Services\Mini\MiniPaymentService;
|
|
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): RedirectResponse
|
|
{
|
|
$qrCode = QrCode::query()
|
|
->where('short_code', $shortCode)
|
|
->where('type', QrCode::TYPE_PAYMENT)
|
|
->where('is_active', true)
|
|
->firstOrFail();
|
|
|
|
$validated = $request->validate([
|
|
'amount' => 'required|numeric|min:0.01',
|
|
'payer_email' => 'required|email|max:255',
|
|
'payer_name' => 'nullable|string|max:120',
|
|
'payer_phone' => 'nullable|string|max:32',
|
|
'payer_note' => 'nullable|string|max:255',
|
|
]);
|
|
|
|
try {
|
|
$result = $this->payments->initiate($qrCode, $validated);
|
|
} catch (RuntimeException $e) {
|
|
return back()->withInput()->with('error', $e->getMessage());
|
|
}
|
|
|
|
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,
|
|
]);
|
|
}
|
|
}
|