调用收银台
说明 /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 | 应用 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 单独接入密钥的应用 — 见直接打开快捷支付 | TOSSPAY, NAVERPAY, KAKAOPAY |
sessionToken | string | StagePay 会员会话令牌(仅限使用该功能的应用) | |
region / projectId | string | 仅限 GamePot 接入应用(GamePot 区域·项目) | |
price, priceTs, priceSig | string | 价格覆盖 — 参见下文价格覆盖 |
仅限 /inapp:
| 参数 | 说明 |
|---|---|
payment | 支付方式 ID 或代码。传入后跳过选择页面 |
token | GamePot JWT(在 GamePot 应用中代替 userId 使用) |
无需传递金额
支付金额由 productId 和 currency 对应的、登记在服务器上的商品价格决定。客户端发送的金额不予信任。
价格覆盖
如果确实需要动态价格(例如购物车合计),可以用 price 覆盖商品价格。在 v2 中,只有同时满足以下两个条件时才会生效。
- 应用设置
allowCustomPrice = true(通过控制台向运营方申请) - 同时传入由商户服务器生成的有效签名
priceSig,且priceTs在当前时间 ±900 秒以内
price:{appId}:{productId}:{CURRENCY}:{price}:{userId}:{priceTs}priceSig = hex(HMAC-SHA256(webhookSecret, canonical))— 密钥为应用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 | 应用不可使用的 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。 - 向商户回调 URL 发送已签名的
payment.succeeded回调 → Webhook/回调。 - 客户浏览器(或 WebView)跳转到
/return结果页,结果会传回应用 → 应用内/WebView 接入。