Deploy Ladill QR Plus / deploy (push) Successful in 2m2s
Create was making three sequential public HTTPS billing calls (~400ms each) while holding a DB transaction open for image generation. Use loopback DNS forcing, cache balances briefly, return balance from debit, regenerate images only when style changes, and keep remote work outside the DB transaction.
35 lines
977 B
PHP
35 lines
977 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\Billing\BillingClient;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* 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;
|
|
|
|
// BillingClient already short-caches balances; avoid a second long cache layer.
|
|
try {
|
|
$minor = $billing->balanceMinor($publicId);
|
|
} catch (\Throwable) {
|
|
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),
|
|
]);
|
|
}
|
|
}
|