Nạp credit Gommo
Coming to Gommo platform
Recipe này gọi /vi/billing/* trên Gommo Developer self-host (localhost:3001) — không phải Gommo public API. Billing thống nhất trên site là preview của nền tảng Gommo.
Điều kiện
Chạy npm run dev hoặc npm run docs:stack với env billing. Xem Deploy.
Billing nằm ở /vi/billing/* — tách khỏi generation API.
Mode mặc định: Gommo create_payment + client poll payment_sync. Không cần cấu hình PayOS trên server.
1. Trạng thái server
powershell
Invoke-RestMethod "http://localhost:3001/billing/status"Kỳ vọng billingMode: gommo.
2. Danh sách gói
powershell
$packages = Invoke-RestMethod "http://localhost:3001/billing/packages"
$packages.data | Format-Table id, name, amountVnd, credits3. Username từ /ai/me
username trong body create phải khớp chủ Bearer token.
powershell
$domain = $env:GOMMO_API_DOMAIN; if (-not $domain) { throw 'Set GOMMO_API_DOMAIN to the user registration domain (dealer)' }
$meBody = "access_token=$env:TOKEN&domain=$domain"
$me = Invoke-RestMethod -Method POST `
-Uri "https://api.gommo.net/ai/me" `
-ContentType "application/x-www-form-urlencoded" `
-Body $meBody
$username = $me.username ?? $me.data.username
Write-Host "username=$username"4. Tạo payment
powershell
$h = @{ Authorization = "Bearer $env:TOKEN"; 'Content-Type' = 'application/json' }
$body = @{
username = $username
packageId = 'basic-member'
invoiceBuyer = @{ type = 'consumer'; name = 'Bán cho người tiêu dùng'; email = '' }
} | ConvertTo-Json -Depth 5
$payment = Invoke-RestMethod -Method POST -Uri "http://localhost:3001/billing/payment/create" -Headers $h -Body $body
$orderCode = $payment.data.content ?? $payment.data.orderCode5. Poll đến khi paid
powershell
while ($true) {
$sync = Invoke-RestMethod -Method POST -Uri "http://localhost:3001/billing/payment/sync" `
-Headers $h -Body (@{ orderCode = $orderCode } | ConvertTo-Json)
if ($sync.data.paid) { break }
Start-Sleep -Seconds 4
}6. Lịch sử
powershell
Invoke-RestMethod -Uri "http://localhost:3001/billing/topup/orders?username=$username" -Headers $hPayOS legacy
Xem PayOS nạp credit.
Portal
/vi/app/credits/ có modal checkout đầy đủ (tóm tắt → hóa đơn 3 tab → QR chuyển khoản).
