Midasbuy Trade SDK
1. SDK 描述
通过传入玩家的 “人” 的信息,拉起 midasbuy 物品列表的 “货” 和 midasbuy 交易商城的 “场”。
2. 引入 SDK
在 HTML 文件中引入 script:
<script src="https://cdn.midasbuy.com/js/trade.stable.js"></script>
3. API 说明
3.1. midas.trade(options)
创建 tradeApi 实例:
const tradeApi = midas.trade({
appid: '1460000764',
language: 'en',
region: 'us',
sandbox: 1,
from: 'xxx',
});
| 参数 | 是否必填 | 位置 | 类型 | 格式 | 说明 |
|---|---|---|---|---|---|
| appid | Yes | params | String | string.min_len: 1 | 应用 ID |
| language | Yes | params | String | string.len: 2 | 语言代码,目前 midasbuy 支持 ar,hk,tr,de,id,pu,tw,en,ja,ru,vn,es,ko,fr,my,th |
| region | Yes | params | String | string.len: 2 | 国家代码,目前 midasbuy 开放站点列表参考 [region select] |
| sandbox | No | params | Number | 0 现网,1 沙箱。默认为 0,联调时使用 1 | |
| from | No | params | String | string.min_len: 1 | 外部调用方来源,用于统计,默认为空字符串 |
3.2. tradeApi.show(playerInfo).then(paymentSuccessCallback).catch(failCallback)
展示物品列表弹窗,并抛出支付成功和失败的回调事件:
tradeApi.show({
game_openid: '1321xxx',
role_id: '186xxx',
server_id: '319',
charac_name: 'test name',
backgroundImg: 'https://example.com/bg.jpg',
})
.then((data) => {
// 支付成功回调
})
.catch((err) => {
// 支付失败回调,有多种情况,详见下面错误 码
});
玩家信息参数
| 参数 | 是否必填 | 位置 | 类型 | 格式 | 说明 |
|---|---|---|---|---|---|
| game_openid | Yes | params | String | string.min_len: 1 | 游戏用户 ID |
| role_id | Yes | params | String | string.min_len: 1 | 角色 ID |
| server_id | Yes | params | String | string.min_len: 1 | 分区 ID |
| charac_name | Yes | params | String | string.min_len: 1 | 玩家昵称 |
| balance | No | params | String | Number | |
| thirdBalance | No | params | String | Number | |
| backgroundImg | No | params | String | 弹窗背景图片 URL,为空时默认黑色背景 |
3.2.1. 支付成功回调数据
| 参数 | 类型 | 说明 |
|---|---|---|
| order_id | String | 订单号 |
| product_id | String | 物品 ID |
成功示例:
{
"product_id": "1460000764_18_coins_midasbuy_us",
"order_id": "SG2410xxxxxx"
}
3.2.2. 失败回调数据
| 参数 | 类型 | 说明 |
|---|---|---|
| name | Enum | 失败含多种情况,比如参数校验不过、用户手动触发sdk关闭、程序crash等等原因,不为空 |
| message | String | 用于描述响应错误信息,可能为空 |
| details | Array | 用于给出更详尽信息,例如:重试详情、配额错误、渠道错误等,可能为空 |
| links | Array | 当发生故障时可能返回解决该问题的文档地址,可能为空 |
| debug_id | String | 当前请求的标识,用户表示Midas的一次请求。反馈问题时可带上该标识,可能为空 |
| causes | Array | 该异常的解决方案,可能为空 |
失败示例:
{
"name": "INVALID_ARGUMENT",
"message": "invalid CreateOrderRequest.ApplicationContext: embedded message failed validation | caused by: invalid ApplicationContext.RegionCode: value does not match regex pattern \"^[A-Z]{2}$\"",
"details": [
{
"@type": "type.apis.com/rpc.BadRequest.FieldViolation",
"field": "ApplicationContext",
"description": "embedded message failed validation",
"value": ""
}
],
"links": [],
"debug_id": "247df6a6ed3ab364",
"causes": []
}
3.2.3. name 错误码枚举值
| 参数 | 说明 |
|---|---|
| INVALID_ARGUMENT | 参数校验不过 |
| USER_IS_DISTURBED | 用户手动触发sdk关闭中断了购买流程 |
| QUERY_SHELF_FAILED | 请求货架物品失败 |
| QUERY_CHANNEL_FAILED | 拉起渠道失败 |
| PAYMENT_COMP_NOT_LOADED | 支付组件加载失败 |
| ORDER_FAILED | 下单失败 |
| PAYMENT_FAILED | 支付失败 |
| UNKNOWN_CRASH | sdk程序crash |
4. 调用示例
demo 页面链接:Midasbuy Trade SDK Demo