PayOS เติมเครดิต (legacy)
Coming to Gommo platform
สูตรนี้เรียก /th/billing/* บน Gommo Developer self-host (localhost:3001) — ไม่ใช่ Gommo public API
WARNING
เส้นทาง legacy การเชื่อมต่อใหม่ควรใช้ Gommo เติมเครดิต (POST /billing/payment/create) สูตรนี้ต้องมีคีย์ PayOS และ merchant GOMMO_ACCESS_TOKEN บนเซิร์ฟเวอร์
Billing อยู่ใต้ /th/billing/* — แยกจาก API generation (jobs, chat, upload)
ต้องมี env เซิร์ฟเวอร์: คีย์ PayOS + GOMMO_ACCESS_TOKEN ตรวจความพร้อมก่อน
1. สถานะเซิร์ฟเวอร์
Invoke-RestMethod "http://localhost:3001/billing/status"คาดหวัง payosConfigured: true และ merchantReady: true ก่อนสร้าง order
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. สร้าง order เติมเครดิต
$h = @{ Authorization = "Bearer $env:TOKEN"; 'Content-Type' = 'application/json' }
$body = @{
username = $username
packageId = 'basic-member'
} | ConvertTo-Json
$order = Invoke-RestMethod -Method POST `
-Uri "http://localhost:3001/billing/topup/create" `
-Headers $h -Body $body
$checkoutUrl = $order.data.url
$orderCode = $order.data.orderCode
Write-Host "Pay: $checkoutUrl"
Write-Host "orderCode=$orderCode"เปิด url ในเบราว์เซอร์ (PayOS checkout / QR) ผู้ใช้ชำระเงินบน PayOS
5. Poll order (ทางเลือก)
Webhook PAID → gateway ส่งเครดิต Gommo อัตโนมัติ Poll ถ้า webhook ไม่ถึงใน dev:
Invoke-RestMethod "http://localhost:3001/billing/topup/orders/$orderCode"สถานะ: pending → paid → credited (หรือ failed)
Webhook (production)
ลงทะเบียนที่ my.payos.vn:
POST https://api.yourdomain.com/billing/webhook/payosตั้ง PAYOS_WEBHOOK_URL ใน env เซิร์ฟเวอร์ ดู อ้างอิง billing
