billing->balanceMinor($account->public_id); $ledger = $this->billing->serviceLedger($account->public_id, config('billing.service', 'mini')); } catch (Throwable $e) { Log::warning('Mini API wallet load failed', ['user' => $account->public_id, 'error' => $e->getMessage()]); } return response()->json([ 'data' => [ 'currency' => 'GHS', 'balance_minor' => $balanceMinor, 'spent_minor' => (int) ($ledger['spent_minor'] ?? 0), 'credited_minor' => (int) ($ledger['credited_minor'] ?? 0), ], ]); } public function topup(Request $request): JsonResponse { $account = ladill_account(); $data = $request->validate([ 'amount' => ['required', 'numeric', 'min:1', 'max:10000'], ]); $response = $this->identitySend('POST', '/api/identity/wallet-topup-account', [ 'user' => $account->public_id, 'amount' => (float) $data['amount'], // Paystack returns the customer here after payment; the app catches the deep link. 'return_url' => 'https://'.config('app.platform_domain').'/mini/wallet/topup-complete', ]); $this->rethrowValidation($response, 'amount'); $checkoutUrl = (string) $response->json('data.checkout_url', ''); if ($checkoutUrl === '') { return response()->json(['message' => 'Could not start top-up. Please try again.'], 422); } return response()->json(['data' => ['checkout_url' => $checkoutUrl]]); } }