呼叫收銀台
說明 /request / /inapp 收銀台 URL 參數、價格覆寫簽章與錯誤回應。
收銀台只需透過 URL 參數即可呼叫。建議由商戶伺服器產生收銀台 URL 後再傳給用戶端(防止使用者識別值遭偽造、價格簽章等)。
| 端點 | 說明 |
|---|---|
GET /request | 以指定的 PG(pg)・付款方式(method)直接開始付款。 |
GET /inapp | 先顯示付款方式選擇畫面,再開始付款。若提供 pg・method 或 payment,則會略過選擇畫面。 |
| 環境 | 基本網址 |
|---|---|
| beta | https://beta-pay.stagepay.io |
| real | https://pay.stagepay.io |
請求範例
https://pay.stagepay.io/request?appId=6650f0c2a1b2c3d4e5f60718&pg=KCP&method=card&productId=gem_100¤cy=KRW&userId=user_42&language=kohttps://pay.stagepay.io/inapp?appId=6650f0c2a1b2c3d4e5f60718&productId=gem_100¤cy=KRW&userId=user_42&language=ko參數
所有值都必須經過 URL 編碼(建議使用 URLSearchParams、http_build_query、urllib.parse.urlencode)。
必填
| 參數 | 型別 | 說明 | 範例 |
|---|---|---|---|
appId | string | App ID | 6650f0c2a1b2c3d4e5f60718 |
pg | string | PG 代碼。在 /request 中為必填 | KCP, STRIPE, USDT |
productId | string | 在控制台登錄的商品 ID | gem_100 |
currency | string | 付款幣別(ISO 4217 或 USDT)。商品必須有該幣別的價格 | KRW |
userId | string | 商戶的使用者識別值。會原樣傳到回呼 | user_42 |
選填
| 參數 | 型別 | 說明 | 範例 |
|---|---|---|---|
method | string | PG 的付款方式代碼。省略時使用 PG 預設收銀台 | card, TRC20 |
language (lang) | string | 收銀台語言 | ko, en, ja, zh-CN, zh-TW, th, id, es, ms |
email | string | 接收收據的電子郵件(僅在格式正確時使用) | user@example.com |
serverId | string | 遊戲伺服器 ID | s1 |
playerId | string | 遊戲角色/玩家 ID | hero42 |
userdata | string | 商戶自由資料。會原樣傳到回呼(建議使用 JSON 字串,建議 2KB 以下) | {"orderNo":"A-1001"} |
etc | string | 商戶自由資料(輔助) | promo=summer |
uniqueId | string | 商戶端訂單唯一值。用於將商戶訂單編號與交易連結 | A-1001 |
returnUrl | string | 結果畫面「返回商家」的網址。只接受在後台應用程式付款後返回網址中登錄的 origin(https://…)或應用程式 scheme(mygame://)。返回時會附加 stagepay_tid、stagepay_status | https://shop.example.com/orders/A-1001 |
directPay | string | 直接開啟行動支付(KCP、TOSS)。TOSS 僅限已設定 API 個別串接金鑰的 App — 見直接開啟行動支付 | TOSSPAY, NAVERPAY, KAKAOPAY |
sessionToken | string | StagePay 會員工作階段權杖(僅限有使用的 App) | |
region / projectId | string | GamePot 串接 App 專用(GamePot 區域・專案) | |
price, priceTs, priceSig | string | 價格覆寫 — 請參閱下方價格覆寫 |
/inapp 專用:
| 參數 | 說明 |
|---|---|
payment | 付款方式 ID 或代碼。提供時會略過選擇畫面 |
token | GamePot JWT(GamePot App 中用以取代 userId) |
不傳送金額
付款金額由 productId 與 currency 從伺服器上登錄的商品價格決定。用戶端傳送的金額不予採信。
價格覆寫
若確實需要動態價格(例如:購物車合計),可以用 price 覆寫商品價格。在 v2 中,只有在同時滿足以下兩個條件時才會套用。
- App 設定
allowCustomPrice = true(透過控制台向營運人員申請) - 一併傳送由商戶伺服器產生的有效簽章
priceSig,且priceTs在目前時間 ±900 秒以內
price:{appId}:{productId}:{CURRENCY}:{price}:{userId}:{priceTs}priceSig = hex(HMAC-SHA256(webhookSecret, canonical))— 金鑰為 App 的webhookSecret完整字串(whsec_...)。{CURRENCY}為大寫,{price}必須與實際在 URL 中傳送的字串完全相同(5000與5000.00是不同的值)。priceTs為 Unix 秒數。
import crypto from 'node:crypto';
export function signPrice(p: { appId: string; productId: string; currency: string; price: string; userId: string }) {
const priceTs = Math.floor(Date.now() / 1000).toString();
const canonical = ['price', p.appId, p.productId, p.currency.toUpperCase(), p.price, p.userId, priceTs].join(':');
const priceSig = crypto.createHmac('sha256', process.env.STAGEPAY_WEBHOOK_SECRET!).update(canonical).digest('hex');
return { price: p.price, priceTs, priceSig };
}若沒有簽章或簽章錯誤,price 會被忽略並改用商品價格(若商品價格為 0,則請求會被拒絕)。
回應與錯誤
收銀台會回傳 HTML。若請求有誤,會回傳錯誤頁面與 HTTP 狀態碼,拒絕原因會記錄為 request_rejected 日誌,可在控制台 日誌 中確認。
| HTTP | 訊息 | 原因 |
|---|---|---|
| 400 | PG code is required | 缺少 pg |
| 400 | Currency is required | 缺少 currency |
| 400 | Product ID is required | 缺少 productId |
| 400 | 購買限制訊息 | 違反商品購買條件(限購一次、限期等) |
| 400 | Unsupported payment method | App 無法使用的 PG |
| 404 | Payment company not found | 未知的 PG 代碼 |
| 404 | Payment method not found | 該 PG 沒有此付款方式代碼 |
| 404 | Product information not found | 商品不存在,或沒有該幣別的價格 |
| 500 | Error processing payment | PG 請求失敗等內部錯誤 — 請附上 requestId 詢問 |
付款之後
- 客戶完成付款後,PG 會將結果通知 StagePay,StagePay 經 PG 伺服器驗證後將交易確定為
success。 - 已簽章的
payment.succeeded回呼會傳送至商戶回呼 URL → Webhook/回呼。 - 客戶瀏覽器(或 WebView)會移至
/return結果頁面,並將結果傳給 App → App 內 / WebView 串接。