Files
ladill-pos/app/Http/Controllers/Api/Concerns/CallsIdentityApi.php
T
isaaccladandCursor e5d2b84388
Deploy Ladill Mini / deploy (push) Successful in 23s
Add Ladill POS v1 — register, Pay checkout, and commerce links.
Staff-facing counter register at pos.ladill.com with catalog cart, cash and
MoMo/card checkout via Ladill Pay, CRM timeline/import, invoice prefill, and
Merchant catalog import.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 22:52:24 +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.']],
);
}
}
}