Bootstrap Ladill Link from QR Plus extract template.

This commit is contained in:
isaacclad
2026-06-27 10:54:31 +00:00
commit 04e4f6ab51
243 changed files with 26587 additions and 0 deletions
@@ -0,0 +1,51 @@
<?php
namespace App\Http\Controllers;
use App\Services\Billing\BillingClient;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
/**
* In-app wallet top-up. Posts to the central identity API to start a Paystack
* checkout against the one Ladill wallet, then hands the user to checkout. This
* backs the two-step "Add funds" modal so users never leave for the wallet page
* when they hit an insufficient-balance action.
*/
class WalletTopupController extends Controller
{
public function store(Request $request, BillingClient $billing): JsonResponse|RedirectResponse
{
$validated = $request->validate([
'amount' => ['required', 'numeric', 'min:5', 'max:5000'],
'return_url' => ['nullable', 'url', 'max:2048'],
]);
$returnUrl = $validated['return_url'] ?? (string) (url()->previous() ?: url('/'));
try {
$checkoutUrl = $billing->topup(
(string) $request->user()->public_id,
(float) $validated['amount'],
$returnUrl,
);
} catch (\Throwable) {
$checkoutUrl = '';
}
if ($checkoutUrl === '') {
if ($request->expectsJson()) {
return response()->json(['error' => 'Unable to start payment. Please try again.'], 422);
}
return back()->with('error', 'Unable to start payment. Please try again.');
}
if ($request->expectsJson()) {
return response()->json(['checkout_url' => $checkoutUrl]);
}
return redirect()->away($checkoutUrl);
}
}