Deploy Ladill Frontdesk / deploy (push) Successful in 33s
Adds a dedicated Pro page with wallet upgrade, gradient Upgrade to Pro button in the sidebar footer, and view composer for plan status. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Frontdesk;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Frontdesk\Concerns\ScopesToAccount;
|
|
use App\Services\Billing\BillingClient;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class WalletController extends Controller
|
|
{
|
|
use ScopesToAccount;
|
|
|
|
public function balance(Request $request, BillingClient $billing): JsonResponse
|
|
{
|
|
$publicId = (string) $request->user()->public_id;
|
|
|
|
$minor = Cache::remember("frontdesk_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),
|
|
]);
|
|
}
|
|
}
|