Mini API: account settings, wallet & support endpoints for the app.
Deploy Ladill Mini / deploy (push) Successful in 40s

Adds /api/v1/mini account (settings, profile, change-password), wallet (balance
+ ledger, Paystack top-up) and support (Afia chat) endpoints. Account/profile/
password/top-up proxy to the central identity API via a CallsIdentityApi trait;
notifications, wallet balance and support chat are served locally.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
isaacclad
2026-06-11 11:03:33 +00:00
co-authored by Claude Opus 4.8
parent 90d7aab547
commit c39e38cbe0
5 changed files with 285 additions and 0 deletions
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers\Api\Mini;
use App\Http\Controllers\Api\Concerns\CallsIdentityApi;
use App\Http\Controllers\Controller;
use App\Services\Billing\BillingClient;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Throwable;
class WalletController extends Controller
{
use CallsIdentityApi;
public function __construct(private BillingClient $billing) {}
public function show(): JsonResponse
{
$account = ladill_account();
$balanceMinor = 0;
$ledger = [];
try {
$balanceMinor = $this->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]]);
}
}