跳到内容
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)。

必填

参数类型说明示例
appIdstring应用 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 单独接入密钥的应用 — 见直接打开快捷支付TOSSPAY, NAVERPAY, KAKAOPAY
sessionTokenstringStagePay 会员会话令牌(仅限使用该功能的应用)
region / projectIdstring仅限 GamePot 接入应用(GamePot 区域·项目)
price, priceTs, priceSigstring价格覆盖 — 参见下文价格覆盖

仅限 /inapp:

参数说明
payment支付方式 ID 或代码。传入后跳过选择页面
tokenGamePot JWT(在 GamePot 应用中代替 userId 使用)

无需传递金额

支付金额由 productId 和 currency 对应的、登记在服务器上的商品价格决定。客户端发送的金额不予信任。

价格覆盖

如果确实需要动态价格(例如购物车合计),可以用 price 覆盖商品价格。在 v2 中,只有同时满足以下两个条件时才会生效。

  1. 应用设置 allowCustomPrice = true(通过控制台向运营方申请)
  2. 同时传入由商户服务器生成的有效签名 priceSig,且 priceTs 在当前时间 ±900 秒以内
签名原文(canonical)
price:{appId}:{productId}:{CURRENCY}:{price}:{userId}:{priceTs}
  • priceSig = hex(HMAC-SHA256(webhookSecret, canonical)) — 密钥为应用 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 method应用不可使用的 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. 向商户回调 URL 发送已签名的 payment.succeeded 回调 → Webhook/回调。
  3. 客户浏览器(或 WebView)跳转到 /return 结果页,结果会传回应用 → 应用内/WebView 接入。

本页目录