跳至內容
StagePayDocs v2

呼叫收銀台

說明 /request / /inapp 收銀台 URL 參數、價格覆寫簽章與錯誤回應。

收銀台只需透過 URL 參數即可呼叫。建議由商戶伺服器產生收銀台 URL 後再傳給用戶端(防止使用者識別值遭偽造、價格簽章等)。

端點說明
GET /request以指定的 PG(pg)・付款方式(method)直接開始付款。
GET /inapp先顯示付款方式選擇畫面,再開始付款。若提供 pg・method 或 payment,則會略過選擇畫面。
環境基本網址
betahttps://beta-pay.stagepay.io
realhttps://pay.stagepay.io

請求範例

直接開始 KCP 信用卡付款
https://pay.stagepay.io/request?appId=6650f0c2a1b2c3d4e5f60718&pg=KCP&method=card&productId=gem_100&currency=KRW&userId=user_42&language=ko
付款方式選擇畫面
https://pay.stagepay.io/inapp?appId=6650f0c2a1b2c3d4e5f60718&productId=gem_100&currency=KRW&userId=user_42&language=ko

參數

所有值都必須經過 URL 編碼(建議使用 URLSearchParams、http_build_query、urllib.parse.urlencode)。

必填

參數型別說明範例
appIdstringApp ID6650f0c2a1b2c3d4e5f60718
pgstringPG 代碼。在 /request 中為必填KCP, STRIPE, USDT
productIdstring在控制台登錄的商品 IDgem_100
currencystring付款幣別(ISO 4217 或 USDT)。商品必須有該幣別的價格KRW
userIdstring商戶的使用者識別值。會原樣傳到回呼user_42

選填

參數型別說明範例
methodstringPG 的付款方式代碼。省略時使用 PG 預設收銀台card, TRC20
language (lang)string收銀台語言ko, en, ja, zh-CN, zh-TW, th, id, es, ms
emailstring接收收據的電子郵件(僅在格式正確時使用)user@example.com
serverIdstring遊戲伺服器 IDs1
playerIdstring遊戲角色/玩家 IDhero42
userdatastring商戶自由資料。會原樣傳到回呼(建議使用 JSON 字串,建議 2KB 以下){"orderNo":"A-1001"}
etcstring商戶自由資料(輔助)promo=summer
uniqueIdstring商戶端訂單唯一值。用於將商戶訂單編號與交易連結A-1001
returnUrlstring結果畫面「返回商家」的網址。只接受在後台應用程式付款後返回網址中登錄的 origin(https://…)或應用程式 scheme(mygame://)。返回時會附加 stagepay_tid、stagepay_statushttps://shop.example.com/orders/A-1001
directPaystring直接開啟行動支付(KCP、TOSS)。TOSS 僅限已設定 API 個別串接金鑰的 App — 見直接開啟行動支付TOSSPAY, NAVERPAY, KAKAOPAY
sessionTokenstringStagePay 會員工作階段權杖(僅限有使用的 App)
region / projectIdstringGamePot 串接 App 專用(GamePot 區域・專案)
price, priceTs, priceSigstring價格覆寫 — 請參閱下方價格覆寫

/inapp 專用:

參數說明
payment付款方式 ID 或代碼。提供時會略過選擇畫面
tokenGamePot JWT(GamePot App 中用以取代 userId)

不傳送金額

付款金額由 productId 與 currency 從伺服器上登錄的商品價格決定。用戶端傳送的金額不予採信。

價格覆寫

若確實需要動態價格(例如:購物車合計),可以用 price 覆寫商品價格。在 v2 中,只有在同時滿足以下兩個條件時才會套用。

  1. App 設定 allowCustomPrice = true(透過控制台向營運人員申請)
  2. 一併傳送由商戶伺服器產生的有效簽章 priceSig,且 priceTs 在目前時間 ±900 秒以內
簽章對象字串(canonical)
price:{appId}:{productId}:{CURRENCY}:{price}:{userId}:{priceTs}
  • priceSig = hex(HMAC-SHA256(webhookSecret, canonical)) — 金鑰為 App 的 webhookSecret 完整字串(whsec_...)。
  • {CURRENCY} 為大寫,{price} 必須與實際在 URL 中傳送的字串完全相同(5000 與 5000.00 是不同的值)。
  • priceTs 為 Unix 秒數。
價格簽章(Node.js)
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訊息原因
400PG code is required缺少 pg
400Currency is required缺少 currency
400Product ID is required缺少 productId
400購買限制訊息違反商品購買條件(限購一次、限期等)
400Unsupported payment methodApp 無法使用的 PG
404Payment company not found未知的 PG 代碼
404Payment method not found該 PG 沒有此付款方式代碼
404Product information not found商品不存在,或沒有該幣別的價格
500Error processing paymentPG 請求失敗等內部錯誤 — 請附上 requestId 詢問

付款之後

  1. 客戶完成付款後,PG 會將結果通知 StagePay,StagePay 經 PG 伺服器驗證後將交易確定為 success。
  2. 已簽章的 payment.succeeded 回呼會傳送至商戶回呼 URL → Webhook/回呼。
  3. 客戶瀏覽器(或 WebView)會移至 /return 結果頁面,並將結果傳給 App → App 內 / WebView 串接。

本頁目錄