Files
ladill-mini/app/Http/Controllers/Api/Concerns/CallsIdentityApi.php
T
isaaccladandClaude Opus 4.8 c39e38cbe0
Deploy Ladill Mini / deploy (push) Successful in 40s
Mini API: account settings, wallet & support endpoints for the app.
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>
2026-06-11 11:03:33 +00:00

48 lines
1.6 KiB
PHP

<?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.']],
);
}
}
}