Gommo เติมเครดิต
Coming to Gommo platform
สูตรนี้เรียก /th/billing/* บน Gommo Developer self-host (localhost:3001) — ไม่ใช่ Gommo public API UX billing รวมบนไซต์เป็น preview ของแพลตฟอร์ม Gommo
ข้อกำหนดเบื้องต้น
รัน npm run dev หรือ npm run docs:stack พร้อม env billing ดู Deploy
Billing อยู่ใต้ /th/billing/* — แยกจาก API generation (jobs, chat, upload)
โหมดค่าเริ่มต้น: Gommo create_payment + client poll payment_sync ไม่ต้องมี env PayOS บนเซิร์ฟเวอร์
1. สถานะเซิร์ฟเวอร์
Invoke-RestMethod "http://localhost:3001/billing/status"คาดหวัง billingMode: gommo และ gommoPayment: true
2. ลิสต์แพ็ก
$packages = Invoke-RestMethod "http://localhost:3001/billing/packages"
$packages.data | Format-Table id, name, amountVnd, credits, bonusPercentpackage id รวม basic-member, vip-member, ultra-member, …
3. ได้ username จาก /th/ai/me
username ใน body สร้างต้องตรงกับเจ้าของ Bearer token
$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. สร้างการชำระเงิน
$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
$qr = $payment.data.qrImage
$orderCode = $payment.data.content ?? $payment.data.orderCode
Write-Host "QR: $qr"
Write-Host "orderCode=$orderCode"ผู้ใช้โอนยอดเรียกเก็บ (ฐาน + VAT 5%) พร้อมหมายเหตุ orderCode
5. Poll จน paid
while ($true) {
$syncBody = @{ orderCode = $orderCode } | ConvertTo-Json
$sync = Invoke-RestMethod -Method POST `
-Uri "http://localhost:3001/billing/payment/sync" `
-Headers $h -Body $syncBody
if ($sync.data.paid) { Write-Host 'Paid!'; break }
Start-Sleep -Seconds 4
}6. ประวัติ order
Invoke-RestMethod `
-Uri "http://localhost:3001/billing/topup/orders?username=$username&limit=10" `
-Headers @{ Authorization = "Bearer $env:TOKEN" }PayOS legacy
หากรัน fulfillment ที่ merchant ควบคุม ดู PayOS เติมเครดิต (POST /billing/topup/create)
UI Portal
Developer portal (/th/app/credits/) ทำ checkout แบบ Gommo ครบ: สรุป → ใบแจ้งหนี้ (3 แท็บ) → QR โอนเงิน + poll
