Route SMS voice uploads through Transfer with wallet billing.
Deploy Ladill Transfer / deploy (push) Successful in 28s
Deploy Ladill Transfer / deploy (push) Successful in 28s
Add a service API for the Ladill SMS platform to store voice recordings in Transfer and charge monthly storage from the customer wallet. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Identity;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use RuntimeException;
|
||||
|
||||
/** Resolves a Ladill Transfer user mirror from a platform account public_id. */
|
||||
class PublicIdUserResolver
|
||||
{
|
||||
public function resolve(string $publicId): User
|
||||
{
|
||||
$publicId = trim($publicId);
|
||||
if ($publicId === '') {
|
||||
throw new RuntimeException('User public_id is required.');
|
||||
}
|
||||
|
||||
$existing = User::query()->where('public_id', $publicId)->first();
|
||||
if ($existing) {
|
||||
return $existing;
|
||||
}
|
||||
|
||||
$base = rtrim((string) config('identity.api_url'), '/');
|
||||
$key = (string) config('identity.api_key');
|
||||
if ($base === '' || $key === '') {
|
||||
throw new RuntimeException('Identity API is not configured.');
|
||||
}
|
||||
|
||||
$res = Http::withToken($key)
|
||||
->acceptJson()
|
||||
->timeout(10)
|
||||
->get("{$base}/identity/profile", ['user' => $publicId]);
|
||||
|
||||
if ($res->failed()) {
|
||||
throw new RuntimeException('Could not resolve the Ladill account.');
|
||||
}
|
||||
|
||||
$data = $res->json('data');
|
||||
if (! is_array($data)) {
|
||||
throw new RuntimeException('Could not resolve the Ladill account.');
|
||||
}
|
||||
|
||||
$email = trim((string) ($data['email'] ?? ''));
|
||||
if ($email === '') {
|
||||
$email = 'sms+'.$publicId.'@accounts.ladill.local';
|
||||
}
|
||||
|
||||
return User::updateOrCreate(
|
||||
['public_id' => $publicId],
|
||||
[
|
||||
'name' => trim((string) ($data['name'] ?? '')) ?: 'Ladill user',
|
||||
'email' => $email,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user