Files
ladill-woo-manager/app/Services/Identity/IdentityTeamClient.php
T
isaaccladandCursor 09359ca86a
Deploy Ladill Woo Manager / deploy (push) Successful in 39s
Add per-store managers for Woo Business accounts.
Agencies can invite store-scoped managers via Identity, with access limited to one WooCommerce store while owners retain full multi-store control.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-08 07:51:08 +00:00

65 lines
1.7 KiB
PHP

<?php
namespace App\Services\Identity;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
use RuntimeException;
class IdentityTeamClient
{
/**
* @param list<string> $apps
* @param array<string, mixed> $metadata
*
* @return array<string, mixed>
*/
public function inviteAppMember(
string $ownerPublicId,
string $email,
array $apps,
array $metadata = [],
string $role = 'member',
): array {
$response = $this->request('post', '/identity/team/invite', [
'owner' => $ownerPublicId,
'email' => strtolower(trim($email)),
'apps' => $apps,
'role' => $role,
'metadata' => $metadata,
]);
return (array) $response->json('data', []);
}
/** @return list<array<string, mixed>> */
public function teamAccess(string $userPublicId): array
{
$response = $this->request('get', '/identity/team/access', [
'user' => $userPublicId,
]);
return (array) $response->json('data', []);
}
private function request(string $method, string $path, array $query = []): Response
{
$url = rtrim((string) config('identity.api_url'), '/').$path;
$key = config('identity.api_key');
if ($url === '' || ! is_string($key) || $key === '') {
throw new RuntimeException('Identity API is not configured.');
}
$response = Http::withToken($key)
->timeout(10)
->{$method}($url, $query);
if (! $response->successful()) {
throw new RuntimeException($response->json('message') ?: 'Identity API request failed.');
}
return $response;
}
}