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\Concerns;
|
||||
|
||||
use Illuminate\Http\Client\ConnectionException;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Http\Client\Response as HttpResponse;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
/**
|
||||
* Shared helper for talking to the central Ladill identity API
|
||||
* (auth.ladill.com /api/identity/*) with the first-party service key.
|
||||
*/
|
||||
trait CallsIdentityApi
|
||||
{
|
||||
protected function identity(): PendingRequest
|
||||
{
|
||||
return Http::baseUrl(rtrim((string) config('services.ladill_identity.url'), '/'))
|
||||
->withToken((string) config('services.ladill_identity.key'))
|
||||
->connectTimeout(10)
|
||||
->timeout(20)
|
||||
->acceptJson()
|
||||
->asJson();
|
||||
}
|
||||
|
||||
protected function identitySend(string $method, string $path, array $payload): HttpResponse
|
||||
{
|
||||
try {
|
||||
return $this->identity()->send($method, $path, ['json' => $payload]);
|
||||
} catch (ConnectionException) {
|
||||
throw ValidationException::withMessages([
|
||||
'base' => ['Could not reach Ladill. Please try again in a moment.'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/** Re-throw a 422 from the identity API as local validation errors. */
|
||||
protected function rethrowValidation(HttpResponse $response, string $fallbackField = 'base'): void
|
||||
{
|
||||
if ($response->status() === 422) {
|
||||
throw ValidationException::withMessages(
|
||||
$response->json('errors') ?: [$fallbackField => [$response->json('message') ?: 'Request failed.']],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user