Mini API: account settings, wallet & support endpoints for the app.
Deploy Ladill Mini / deploy (push) Successful in 40s
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:
co-authored by
Claude Opus 4.8
parent
90d7aab547
commit
c39e38cbe0
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Mini;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Afia\AfiaService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SupportController extends Controller
|
||||
{
|
||||
public function chat(Request $request, AfiaService $afia): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'message' => ['required', 'string', 'max:2000'],
|
||||
'history' => ['nullable', 'array', 'max:20'],
|
||||
'history.*.role' => ['nullable', 'string'],
|
||||
'history.*.text' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
if (! $afia->enabled()) {
|
||||
return response()->json(['message' => 'Support chat is not available right now.'], 503);
|
||||
}
|
||||
|
||||
try {
|
||||
$reply = $afia->chat(trim($validated['message']), $validated['history'] ?? [], $this->context());
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
|
||||
return response()->json(['message' => 'We could not respond right now. Please try again.'], 502);
|
||||
}
|
||||
|
||||
return response()->json(['data' => ['reply' => $reply]]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function context(): array
|
||||
{
|
||||
$account = ladill_account();
|
||||
|
||||
return [
|
||||
'app' => 'Ladill Mini',
|
||||
'description' => 'Ladill Mini is a payments app: merchants create payment QR codes and links, collect payments, and track takings and payouts.',
|
||||
'account_name' => $account?->name,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user