Admin (chỉ server)
DANGER
Route /vi/admin/* dùng x-admin-key, không phải Bearer token user. GOMMO_ACCESS_TOKEN (merchant) chỉ nằm trong .env server.
| Thao tác | Gommo upstream | Gommo Developer |
|---|---|---|
| Merchant balance | POST .../ai/me + merchant token | GET /admin/merchant/balance |
| Send credits | POST .../users/sendBalances | POST /admin/credits/send |
| Register user | POST .../auth/register | POST /admin/users/register |
Server env
| Biến | Mục đích |
|---|---|
GOMMO_ACCESS_TOKEN | Merchant token |
GOMMO_API_DOMAIN | Domain merchant (xem .env.example) |
GOMMO_MANAGER_ID | manager_id cho register |
TOPUP_MERCHANT_BUFFER_CREDITS | Buffer tùy chọn (mặc định 300k); rule thực tế là Gommo > 500k sau gửi — chỉ set > 500k nếu muốn chặt hơn |
ADMIN_API_KEY | Bảo vệ /vi/admin/* |
Quy tắc Gommo: sau sendBalances, merchant phải còn > 500.000 credits.
Merchant balance
bash
curl.exe "http://localhost:3001/admin/merchant/balance" ^
-H "x-admin-key: YOUR_ADMIN_KEY"powershell
$h = @{ 'x-admin-key' = $env:ADMIN_API_KEY }
Invoke-RestMethod "http://localhost:3001/admin/merchant/balance" -Headers $hSend credits
json
{
"username": "gommo_username",
"value": 100,
"message": "Topup test",
"type": "credits_ai"
}bash
curl.exe -X POST "http://localhost:3001/admin/credits/send" ^
-H "x-admin-key: YOUR_ADMIN_KEY" -H "Content-Type: application/json" ^
-d "{\"username\":\"user1\",\"value\":100,\"message\":\"Test topup\"}"powershell
$body = @{ username = 'user1'; value = 100; message = 'Test topup' } | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri "http://localhost:3001/admin/credits/send" `
-Headers @{ 'x-admin-key' = $env:ADMIN_API_KEY; 'Content-Type' = 'application/json' } `
-Body $bodyQuyền sendBalances do Gommo cấp cho tài khoản merchant domain.
Register user
bash
curl.exe -X POST "http://localhost:3001/admin/users/register" ^
-H "x-admin-key: YOUR_ADMIN_KEY" -H "Content-Type: application/json" ^
-d "{\"email\":\"[email protected]\",\"password\":\"secret12\",\"phone\":\"0900000000\"}"powershell
$body = @{
email = '[email protected]'
password = 'secret12'
phone = '0900000000'
} | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri "http://localhost:3001/admin/users/register" `
-Headers @{ 'x-admin-key' = $env:ADMIN_API_KEY; 'Content-Type' = 'application/json' } `
-Body $bodyScript: scripts/test-admin.ps1
