Add wallet balance widget to the profile menu (after Billing)
Deploy Ladill Give / deploy (push) Successful in 58s

Wallet balance peek rendered as a menu row directly under Billing, backed by
a /wallet/balance endpoint (BillingClient) and guarded by Route::has. Also
opens Afia via a direct window event for reliability.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
isaacclad
2026-06-23 12:26:10 +00:00
co-authored by Claude Opus 4.8
parent ec48ab6b33
commit d6b4a9c853
13 changed files with 200 additions and 7 deletions
@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers;
use App\Services\Billing\BillingClient;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
/**
* Lightweight wallet balance for the avatar dropdown widget.
*/
class WalletBalanceController extends Controller
{
public function balance(Request $request, BillingClient $billing): JsonResponse
{
$publicId = (string) $request->user()->public_id;
$minor = Cache::remember("wallet_balance:{$publicId}", now()->addSeconds(30), function () use ($billing, $publicId) {
try {
return $billing->balanceMinor($publicId);
} catch (\Throwable) {
return null;
}
});
if ($minor === null) {
return response()->json(['available' => false]);
}
$currency = (string) config('billing.currency', 'GHS');
return response()->json([
'available' => true,
'balance_minor' => $minor,
'currency' => $currency,
'formatted' => $currency.' '.number_format($minor / 100, 2),
]);
}
}
+5
View File
@@ -43,6 +43,11 @@ class UserProfileMenu
];
}
if (Route::has((string) config("billing.wallet_balance_route", "wallet.balance"))) {
$items[] = ["type" => "wallet"];
}
if (self::userIsAdmin($user)) {
$adminHref = self::platformUrl('account', 'admin');