@seayoo-io/combo-sdk-node 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -4
- package/dist/const.d.ts +1 -1
- package/dist/index.cjs +1 -19
- package/dist/index.js +1 -19
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -52,13 +52,21 @@ const client = new ApiClient({
|
|
|
52
52
|
### 创建订单 CreateOrder
|
|
53
53
|
|
|
54
54
|
```js
|
|
55
|
+
// 导入枚举变量
|
|
56
|
+
import { Platform } from "@seayoo-io/combo-sdk-node"
|
|
57
|
+
|
|
55
58
|
// 创建订单
|
|
56
59
|
const createOrderResult = await client.createOrder({
|
|
57
60
|
/** 用于标识创建订单请求的唯一 ID */
|
|
58
61
|
reference_id: "<游戏订单ID>",
|
|
59
62
|
/** 发起购买的用户的唯一标识 */
|
|
60
63
|
combo_id: "<ComboID>",
|
|
61
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* 要购买的商品 ID
|
|
66
|
+
* 这里指的是在世游发行平台管理的商品 ID,其中重要的两个约定是:
|
|
67
|
+
* - 商品价格是正整数
|
|
68
|
+
* - 商品价格单位为 分 或 美分,即商品币种所支持的最小流通单位
|
|
69
|
+
*/
|
|
62
70
|
product_id: "<ProductID>",
|
|
63
71
|
/** 平台,支持类型见源码类型定义 Platform */
|
|
64
72
|
platform: Platform.iOS,
|
|
@@ -67,7 +75,7 @@ const createOrderResult = await client.createOrder({
|
|
|
67
75
|
* 这个地址对应的服务端应该通过 Notify 模块实现路由处理
|
|
68
76
|
*/
|
|
69
77
|
notify_url: "https://<YourSite>/<YourPath>"
|
|
70
|
-
/** 要购买的商品的数量,最小为 1 */
|
|
78
|
+
/** 要购买的商品的数量,最小为 1,必须为正整数 */
|
|
71
79
|
quantity: 1,
|
|
72
80
|
/** [可选]订单上下文,在发货通知中透传回游戏 */
|
|
73
81
|
context: "",
|
|
@@ -126,7 +134,7 @@ await client.leaveGame("<ComboID>", "<SessionID>");
|
|
|
126
134
|
import { genSessionID } from "@seayoo-io/combo-sdk-node"
|
|
127
135
|
|
|
128
136
|
// genSessionID 接受唯一参数 comboId 作为输入,返回一个 32 位固定长度的不重复字符串
|
|
129
|
-
const userSessionID = genSessionID("
|
|
137
|
+
const userSessionID = genSessionID("<ComboID>")
|
|
130
138
|
|
|
131
139
|
```
|
|
132
140
|
|
|
@@ -141,11 +149,31 @@ import { NotificationType, Endpoint } from "@seayoo-io/combo-sdk-node"
|
|
|
141
149
|
function notificationHandler(type, payload) {
|
|
142
150
|
switch(type) {
|
|
143
151
|
case NotificationType.ShipOrder:
|
|
144
|
-
// Do your work with payload
|
|
152
|
+
// Do your work with payload:定义见 ShipOrderNotification
|
|
145
153
|
break;
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
156
|
|
|
157
|
+
/** ShipOrderNotification 是订单发货通知的数据结构,包含了订单的详细信息 */
|
|
158
|
+
interface ShipOrderNotification {
|
|
159
|
+
/** 世游服务端创建的,标识订单的唯一 ID */
|
|
160
|
+
order_id: string
|
|
161
|
+
/** 游戏侧用于标识创建订单请求的唯一 ID */
|
|
162
|
+
reference_id: string
|
|
163
|
+
/** 发起购买的用户的唯一标识 */
|
|
164
|
+
combo_id: string
|
|
165
|
+
/** 购买的商品 ID,指的是在世游发行平台管理的商品 ID */
|
|
166
|
+
product_id: string
|
|
167
|
+
/** 购买的商品的数量 */
|
|
168
|
+
quantity: number
|
|
169
|
+
/** 订单币种代码。例如 USD CNY */
|
|
170
|
+
currency: string
|
|
171
|
+
/** 订单金额,单位为分,如果币种为美元,则单位为美分。 */
|
|
172
|
+
amount: number
|
|
173
|
+
/** 游戏侧创建订单时提供的订单上下文,透传回游戏 */
|
|
174
|
+
context?: string
|
|
175
|
+
}
|
|
176
|
+
|
|
149
177
|
// 1.2 创建配置,类型定义参见源码 SDKBaseConfig
|
|
150
178
|
const config = {
|
|
151
179
|
game: "<GameId>",
|
package/dist/const.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,7 @@ var https__default = /*#__PURE__*/_interopDefaultLegacy(https);
|
|
|
12
12
|
/** SDK 名称 */
|
|
13
13
|
const SDKName = "combo-sdk-node";
|
|
14
14
|
/** SDK 版本,在编译前会被动态替换 */
|
|
15
|
-
const SDKVersion = "0.1.
|
|
15
|
+
const SDKVersion = "0.1.11";
|
|
16
16
|
/**
|
|
17
17
|
* 世游支持的服务端点列表
|
|
18
18
|
*/
|
|
@@ -972,18 +972,6 @@ class ApiClient {
|
|
|
972
972
|
* 创建订单
|
|
973
973
|
*/
|
|
974
974
|
async createOrder(option) {
|
|
975
|
-
if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
|
|
976
|
-
throw new Error("createOrder: 必要参数缺失");
|
|
977
|
-
}
|
|
978
|
-
// 检查通知回调地址
|
|
979
|
-
if (!isFullURL(option.notify_url)) {
|
|
980
|
-
throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
|
|
981
|
-
}
|
|
982
|
-
// 检查购买数量
|
|
983
|
-
const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
|
|
984
|
-
if (quantity !== option.quantity) {
|
|
985
|
-
throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
|
|
986
|
-
}
|
|
987
975
|
const {
|
|
988
976
|
ok,
|
|
989
977
|
data,
|
|
@@ -1013,9 +1001,6 @@ class ApiClient {
|
|
|
1013
1001
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1014
1002
|
*/
|
|
1015
1003
|
async enterGame(comboId, sessionId) {
|
|
1016
|
-
if (!comboId || !sessionId) {
|
|
1017
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1018
|
-
}
|
|
1019
1004
|
const {
|
|
1020
1005
|
ok,
|
|
1021
1006
|
status,
|
|
@@ -1046,9 +1031,6 @@ class ApiClient {
|
|
|
1046
1031
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1047
1032
|
*/
|
|
1048
1033
|
async leaveGame(comboId, sessionId) {
|
|
1049
|
-
if (!comboId || !sessionId) {
|
|
1050
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1051
|
-
}
|
|
1052
1034
|
const {
|
|
1053
1035
|
ok,
|
|
1054
1036
|
status,
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { verify } from 'jsonwebtoken';
|
|
|
7
7
|
/** SDK 名称 */
|
|
8
8
|
const SDKName = "combo-sdk-node";
|
|
9
9
|
/** SDK 版本,在编译前会被动态替换 */
|
|
10
|
-
const SDKVersion = "0.1.
|
|
10
|
+
const SDKVersion = "0.1.11";
|
|
11
11
|
/**
|
|
12
12
|
* 世游支持的服务端点列表
|
|
13
13
|
*/
|
|
@@ -967,18 +967,6 @@ class ApiClient {
|
|
|
967
967
|
* 创建订单
|
|
968
968
|
*/
|
|
969
969
|
async createOrder(option) {
|
|
970
|
-
if (!option.combo_id || !option.notify_url || !option.product_id || !option.reference_id) {
|
|
971
|
-
throw new Error("createOrder: 必要参数缺失");
|
|
972
|
-
}
|
|
973
|
-
// 检查通知回调地址
|
|
974
|
-
if (!isFullURL(option.notify_url)) {
|
|
975
|
-
throw new Error("createOrder: notify_url 需要是一个完整的 url 地址");
|
|
976
|
-
}
|
|
977
|
-
// 检查购买数量
|
|
978
|
-
const quantity = Math.min(Math.max(1, Math.ceil(option.quantity)), Number.MAX_SAFE_INTEGER);
|
|
979
|
-
if (quantity !== option.quantity) {
|
|
980
|
-
throw new Error("createOrder: 购买数量 quantity 必须是一个有限的正整数,且不能小于 1");
|
|
981
|
-
}
|
|
982
970
|
const {
|
|
983
971
|
ok,
|
|
984
972
|
data,
|
|
@@ -1008,9 +996,6 @@ class ApiClient {
|
|
|
1008
996
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1009
997
|
*/
|
|
1010
998
|
async enterGame(comboId, sessionId) {
|
|
1011
|
-
if (!comboId || !sessionId) {
|
|
1012
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1013
|
-
}
|
|
1014
999
|
const {
|
|
1015
1000
|
ok,
|
|
1016
1001
|
status,
|
|
@@ -1041,9 +1026,6 @@ class ApiClient {
|
|
|
1041
1026
|
* @param sessionId 游戏会话标识,单次游戏会话的上下线动作必须使用同一会话标识上报
|
|
1042
1027
|
*/
|
|
1043
1028
|
async leaveGame(comboId, sessionId) {
|
|
1044
|
-
if (!comboId || !sessionId) {
|
|
1045
|
-
throw new Error("enterGame: 必要参数缺失");
|
|
1046
|
-
}
|
|
1047
1029
|
const {
|
|
1048
1030
|
ok,
|
|
1049
1031
|
status,
|