test-gstable-sdk 0.1.0
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 +166 -0
- package/dist/index.cjs +604 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +737 -0
- package/dist/index.d.ts +737 -0
- package/dist/index.js +573 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,737 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default private API origin for this SDK (see `GStableHttpOptions.baseUrl` to override).
|
|
3
|
+
* Trailing slashes are normalized when building request URLs.
|
|
4
|
+
*/
|
|
5
|
+
declare const DEFAULT_BASE_URL = "https://api.gstable.io/api/v1/";
|
|
6
|
+
/**
|
|
7
|
+
* Default public API origin (no `Authorization`; see `GStableHttpOptions.publicBaseUrl`).
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_PUBLIC_BASE_URL = "https://api.gstable.io/public/api/v1";
|
|
10
|
+
type HttpMethod = 'GET' | 'POST';
|
|
11
|
+
interface GStableHttpOptions {
|
|
12
|
+
/** API Key,无需带 `Bearer ` 前缀 */
|
|
13
|
+
apiKey: string;
|
|
14
|
+
/** 未设置时使用 {@link DEFAULT_BASE_URL} */
|
|
15
|
+
baseUrl?: string;
|
|
16
|
+
/** 公共 API 根路径,未设置时使用 {@link DEFAULT_PUBLIC_BASE_URL} */
|
|
17
|
+
publicBaseUrl?: string;
|
|
18
|
+
/** 可注入 fetch(测试或自定义环境) */
|
|
19
|
+
fetchImpl?: typeof fetch;
|
|
20
|
+
}
|
|
21
|
+
declare class GStableHttp {
|
|
22
|
+
private readonly baseUrl;
|
|
23
|
+
private readonly publicBaseUrl;
|
|
24
|
+
private readonly authHeader;
|
|
25
|
+
private readonly fetchFn;
|
|
26
|
+
constructor(options: GStableHttpOptions);
|
|
27
|
+
private extractEnvelopeData;
|
|
28
|
+
/**
|
|
29
|
+
* 调用公共 API(不携带 Authorization),响应格式与私有 API 相同。
|
|
30
|
+
*/
|
|
31
|
+
requestPublicJson<T>(method: HttpMethod, path: string, body?: unknown): Promise<T>;
|
|
32
|
+
requestJson<T>(method: HttpMethod, path: string, body?: unknown): Promise<T>;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 账户类型(文档当前仅支持 EVM 地址) */
|
|
36
|
+
type AccountType = 'EVM::ADDR';
|
|
37
|
+
/** 账户状态 */
|
|
38
|
+
type AccountStatus = 'normal';
|
|
39
|
+
/**
|
|
40
|
+
* 收款账户对象(文档字段)
|
|
41
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/account
|
|
42
|
+
*/
|
|
43
|
+
interface Account {
|
|
44
|
+
accountId: string;
|
|
45
|
+
accountName: string;
|
|
46
|
+
accountAddress: string;
|
|
47
|
+
accountType: AccountType;
|
|
48
|
+
settlementCurrencies: string[];
|
|
49
|
+
version: string;
|
|
50
|
+
status: AccountStatus;
|
|
51
|
+
createAt?: string;
|
|
52
|
+
updateAt?: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 账户模块 API(只读;创建/修改须在 Dashboard 完成)
|
|
57
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/account
|
|
58
|
+
*/
|
|
59
|
+
declare class AccountResource {
|
|
60
|
+
private readonly http;
|
|
61
|
+
constructor(http: GStableHttp);
|
|
62
|
+
/** GET /account/detail/:accountId */
|
|
63
|
+
detail(accountId: string): Promise<Account>;
|
|
64
|
+
/** GET /account/list — 全量返回,无分页(单商户最多 20 个账户) */
|
|
65
|
+
list(): Promise<Account[]>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 支持的结算/支付代币条目
|
|
70
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/supported-assets#%E6%9F%A5%E8%AF%A2%E8%83%BD%E5%8A%9B-api
|
|
71
|
+
*/
|
|
72
|
+
interface SupportedToken {
|
|
73
|
+
tokenId: string;
|
|
74
|
+
symbol: string;
|
|
75
|
+
chainId: string;
|
|
76
|
+
decimals: number;
|
|
77
|
+
}
|
|
78
|
+
/** 单条支付路径(费率与限额) */
|
|
79
|
+
interface PaymentCapabilityRoute {
|
|
80
|
+
tokenId: string;
|
|
81
|
+
crosschain: boolean;
|
|
82
|
+
feeRatePPM: number;
|
|
83
|
+
minPaymentValue: number;
|
|
84
|
+
maxPaymentValue: number;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* 支付能力矩阵:结算 tokenId -> 路由分组键(如 POL、ARB、ETH)-> 可选支付路径
|
|
88
|
+
*/
|
|
89
|
+
type PaymentCapabilitiesMatrix = Record<string, Record<string, PaymentCapabilityRoute[]>>;
|
|
90
|
+
/** GET /capabilities/all 返回的 data */
|
|
91
|
+
interface PaymentCapabilities {
|
|
92
|
+
supportedTokens: SupportedToken[];
|
|
93
|
+
paymentCapabilities: PaymentCapabilitiesMatrix;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 公共「支付能力」查询(无需鉴权,使用 public Base URL)
|
|
98
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/supported-assets#%E6%9F%A5%E8%AF%A2%E8%83%BD%E5%8A%9B-api
|
|
99
|
+
*/
|
|
100
|
+
declare class CapabilityResource {
|
|
101
|
+
private readonly http;
|
|
102
|
+
constructor(http: GStableHttp);
|
|
103
|
+
/** GET /capabilities/all */
|
|
104
|
+
all(): Promise<PaymentCapabilities>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 商品状态 */
|
|
108
|
+
type ProductStatus = 'active' | 'archived';
|
|
109
|
+
/** 自定义属性(如尺码、颜色) */
|
|
110
|
+
interface ProductAttribute {
|
|
111
|
+
name: string;
|
|
112
|
+
value: string;
|
|
113
|
+
}
|
|
114
|
+
/** 商品对象(文档字段) */
|
|
115
|
+
interface Product {
|
|
116
|
+
productId: string;
|
|
117
|
+
name: string;
|
|
118
|
+
description?: string;
|
|
119
|
+
imageUrl?: string;
|
|
120
|
+
status: ProductStatus;
|
|
121
|
+
/** Micro-USD,如 1000000 = $1.00 */
|
|
122
|
+
commonPrices: number[];
|
|
123
|
+
attributes?: ProductAttribute[];
|
|
124
|
+
/** 列表接口可能返回 */
|
|
125
|
+
createAt?: string;
|
|
126
|
+
}
|
|
127
|
+
/** POST /product/create */
|
|
128
|
+
interface CreateProductBody {
|
|
129
|
+
name: string;
|
|
130
|
+
commonPrices: number[];
|
|
131
|
+
description?: string;
|
|
132
|
+
imageUrl?: string;
|
|
133
|
+
attributes?: ProductAttribute[];
|
|
134
|
+
}
|
|
135
|
+
/** POST /product/update(全量替换) */
|
|
136
|
+
interface UpdateProductBody {
|
|
137
|
+
productId: string;
|
|
138
|
+
name: string;
|
|
139
|
+
description?: string;
|
|
140
|
+
imageUrl?: string;
|
|
141
|
+
attributes?: ProductAttribute[];
|
|
142
|
+
commonPrices: number[];
|
|
143
|
+
}
|
|
144
|
+
/** GET /product/list/:page/:size */
|
|
145
|
+
interface ProductListData {
|
|
146
|
+
total: number;
|
|
147
|
+
page: string;
|
|
148
|
+
size: string;
|
|
149
|
+
products: Product[];
|
|
150
|
+
}
|
|
151
|
+
/** POST /product/list/by/ids */
|
|
152
|
+
interface ProductListByIdsBody {
|
|
153
|
+
productIds: string[];
|
|
154
|
+
}
|
|
155
|
+
/** 仅含 success 的 data */
|
|
156
|
+
interface OperationSuccess {
|
|
157
|
+
success: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** 链接类型:固定金额 / 自定义金额(捐赠等) */
|
|
161
|
+
type PaymentLinkType = 'fixed' | 'custom';
|
|
162
|
+
/** 手续费模型:1 收款方承担,2 付款方承担 */
|
|
163
|
+
type PaymentLinkFeeModel = 1 | 2;
|
|
164
|
+
/** 链接状态(文档示例含 active) */
|
|
165
|
+
type PaymentLinkStatus = 'active' | string;
|
|
166
|
+
/** 请求体中的行项目 */
|
|
167
|
+
type PaymentLinkLineItemInput = {
|
|
168
|
+
itemType: 'product';
|
|
169
|
+
productId: string;
|
|
170
|
+
quantity: number;
|
|
171
|
+
/** Micro 单位,须 > 0 */
|
|
172
|
+
unitPrice: number;
|
|
173
|
+
} | {
|
|
174
|
+
itemType: 'user_priced';
|
|
175
|
+
productId: string;
|
|
176
|
+
quantity: number;
|
|
177
|
+
/** 可不传或 0 */
|
|
178
|
+
unitPrice?: number;
|
|
179
|
+
};
|
|
180
|
+
/** POST /payment/link/create */
|
|
181
|
+
interface CreatePaymentLinkBody {
|
|
182
|
+
linkType: PaymentLinkType;
|
|
183
|
+
linkName: string;
|
|
184
|
+
accountId: string;
|
|
185
|
+
settlementToken: string;
|
|
186
|
+
feeModel: PaymentLinkFeeModel;
|
|
187
|
+
lineItems: PaymentLinkLineItemInput[];
|
|
188
|
+
/** 1 需要邮箱,0 不需要 */
|
|
189
|
+
payerEmailRequired?: number;
|
|
190
|
+
successUrl?: string;
|
|
191
|
+
customSuccessText?: string;
|
|
192
|
+
customDisabledText?: string;
|
|
193
|
+
}
|
|
194
|
+
/** POST /payment/link/update(全量替换) */
|
|
195
|
+
interface UpdatePaymentLinkBody extends CreatePaymentLinkBody {
|
|
196
|
+
linkId: string;
|
|
197
|
+
}
|
|
198
|
+
/** 行项目中的商品快照(详情/创建响应;列表不含 productData) */
|
|
199
|
+
interface PaymentLinkLineItemProductData {
|
|
200
|
+
productName: string;
|
|
201
|
+
productDescription?: string;
|
|
202
|
+
imageUrl?: string;
|
|
203
|
+
attributes?: ProductAttribute[];
|
|
204
|
+
status?: ProductStatus | string;
|
|
205
|
+
}
|
|
206
|
+
/** 响应中的单行项目 */
|
|
207
|
+
interface PaymentLinkLineItem {
|
|
208
|
+
lineItemId?: string;
|
|
209
|
+
itemType: string;
|
|
210
|
+
productId: string;
|
|
211
|
+
quantity: number;
|
|
212
|
+
unitPrice?: number;
|
|
213
|
+
productData?: PaymentLinkLineItemProductData;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 响应中的 lineItems 区块。
|
|
217
|
+
* 列表/详情多为 `{ items }`;创建接口文档示例为外层含 `lineItems.items` 与 amount。
|
|
218
|
+
*/
|
|
219
|
+
interface PaymentLinkLineItemsSection {
|
|
220
|
+
items?: PaymentLinkLineItem[];
|
|
221
|
+
lineItems?: {
|
|
222
|
+
items?: PaymentLinkLineItem[];
|
|
223
|
+
};
|
|
224
|
+
amount?: number;
|
|
225
|
+
}
|
|
226
|
+
interface SettlementTokenInfo {
|
|
227
|
+
tokenId: string;
|
|
228
|
+
contractAddress: string;
|
|
229
|
+
name: string;
|
|
230
|
+
symbol: string;
|
|
231
|
+
decimals: number;
|
|
232
|
+
chainId: string;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 支付链接对象
|
|
236
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/payment-link
|
|
237
|
+
*/
|
|
238
|
+
interface PaymentLink {
|
|
239
|
+
linkId: string;
|
|
240
|
+
linkType: PaymentLinkType;
|
|
241
|
+
linkName: string;
|
|
242
|
+
lineItems: PaymentLinkLineItemsSection;
|
|
243
|
+
accountId: string;
|
|
244
|
+
settlementToken: string;
|
|
245
|
+
feeModel: PaymentLinkFeeModel;
|
|
246
|
+
amount: number;
|
|
247
|
+
payerEmailRequired?: number;
|
|
248
|
+
successUrl?: string;
|
|
249
|
+
customSuccessText?: string;
|
|
250
|
+
customDisabledText?: string;
|
|
251
|
+
linkUrl: string;
|
|
252
|
+
status: PaymentLinkStatus;
|
|
253
|
+
versionCode: string;
|
|
254
|
+
createAt?: string;
|
|
255
|
+
updateAt?: string;
|
|
256
|
+
accountName?: string;
|
|
257
|
+
accountAddress?: string;
|
|
258
|
+
settlementTokenInfo?: SettlementTokenInfo;
|
|
259
|
+
}
|
|
260
|
+
/** GET /payment/link/list/:page/:size */
|
|
261
|
+
interface PaymentLinkListData {
|
|
262
|
+
links: PaymentLink[];
|
|
263
|
+
total: number;
|
|
264
|
+
page: string;
|
|
265
|
+
size: string;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** 手续费:1 商户承担(默认),2 用户承担 */
|
|
269
|
+
type CheckoutSessionFeeModel = 1 | 2;
|
|
270
|
+
/** 会话生命周期状态 */
|
|
271
|
+
type CheckoutSessionStatus = 'initialized' | 'paid' | 'settling' | 'completed' | 'settlement_pending' | 'expired' | 'cancelled' | string;
|
|
272
|
+
/** one_time 行项目在请求中的商品描述 */
|
|
273
|
+
interface OneTimeProductDataInput {
|
|
274
|
+
productName: string;
|
|
275
|
+
productDescription?: string;
|
|
276
|
+
imageUrl?: string;
|
|
277
|
+
attributes?: ProductAttribute[];
|
|
278
|
+
}
|
|
279
|
+
/** POST /session/checkout/create 的 lineItems 元素 */
|
|
280
|
+
type CheckoutLineItemInput = {
|
|
281
|
+
itemType: 'product';
|
|
282
|
+
productId: string;
|
|
283
|
+
quantity: number;
|
|
284
|
+
unitPrice: number;
|
|
285
|
+
} | {
|
|
286
|
+
itemType: 'one_time';
|
|
287
|
+
quantity: number;
|
|
288
|
+
unitPrice: number;
|
|
289
|
+
productData: OneTimeProductDataInput;
|
|
290
|
+
};
|
|
291
|
+
/** POST /session/checkout/create */
|
|
292
|
+
interface CreateCheckoutSessionBody {
|
|
293
|
+
accountId: string;
|
|
294
|
+
settlementToken: string;
|
|
295
|
+
lineItems: CheckoutLineItemInput[];
|
|
296
|
+
successUrl?: string;
|
|
297
|
+
/** 1 必填邮箱,0 选填 */
|
|
298
|
+
payerEmailRequired?: number;
|
|
299
|
+
feeModel?: CheckoutSessionFeeModel;
|
|
300
|
+
/** 过期 Unix 时间戳(秒);默认约当前 +30 分钟,最小间隔 1800 秒 */
|
|
301
|
+
expirationTime?: number;
|
|
302
|
+
metadata?: Record<string, unknown>;
|
|
303
|
+
}
|
|
304
|
+
/** 响应中的单行项目 */
|
|
305
|
+
interface CheckoutLineItem {
|
|
306
|
+
lineItemId?: string;
|
|
307
|
+
itemType: string;
|
|
308
|
+
productId: string;
|
|
309
|
+
quantity: number;
|
|
310
|
+
unitPrice: number;
|
|
311
|
+
productData?: PaymentLinkLineItemProductData;
|
|
312
|
+
}
|
|
313
|
+
interface CheckoutLineItemsSection {
|
|
314
|
+
items: CheckoutLineItem[];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Checkout Session(创建接口返回或嵌于查询结果 session 内)
|
|
318
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/checkout-session
|
|
319
|
+
*/
|
|
320
|
+
interface CheckoutSession {
|
|
321
|
+
sessionId: string;
|
|
322
|
+
sessionType: string;
|
|
323
|
+
businessId: string;
|
|
324
|
+
businessType: string;
|
|
325
|
+
clientCode: string;
|
|
326
|
+
payer: string;
|
|
327
|
+
payerEmail: string;
|
|
328
|
+
payerEmailRequired: number;
|
|
329
|
+
paidToken: string;
|
|
330
|
+
receiptId: string;
|
|
331
|
+
recipient: string;
|
|
332
|
+
settlementToken: string;
|
|
333
|
+
feeModel: CheckoutSessionFeeModel;
|
|
334
|
+
amount: number;
|
|
335
|
+
lineItems: CheckoutLineItemsSection;
|
|
336
|
+
expirationTime: number;
|
|
337
|
+
successUrl?: string;
|
|
338
|
+
paymentUrl: string;
|
|
339
|
+
signedOnce: number;
|
|
340
|
+
initiateTx: string;
|
|
341
|
+
completeTx: string;
|
|
342
|
+
paymentSucceededTime: string | null;
|
|
343
|
+
settlementSucceededTime: string | null;
|
|
344
|
+
createAt: string;
|
|
345
|
+
status: CheckoutSessionStatus;
|
|
346
|
+
metadata?: Record<string, unknown>;
|
|
347
|
+
}
|
|
348
|
+
/** GET /session/:sessionId 等接口中的链上交易摘要 */
|
|
349
|
+
interface SessionTransaction {
|
|
350
|
+
orderId: string;
|
|
351
|
+
channelId: string;
|
|
352
|
+
orderType: number;
|
|
353
|
+
from: string;
|
|
354
|
+
to: string;
|
|
355
|
+
metaData: string;
|
|
356
|
+
totalValue: number;
|
|
357
|
+
paymentValue: number;
|
|
358
|
+
feeValue: number;
|
|
359
|
+
netValue: number;
|
|
360
|
+
sourceTx: string;
|
|
361
|
+
targetTx: string;
|
|
362
|
+
executeTime: string;
|
|
363
|
+
finalizeTime: string;
|
|
364
|
+
}
|
|
365
|
+
/** GET /session/:sessionId 的 data */
|
|
366
|
+
interface SessionDetail {
|
|
367
|
+
session: CheckoutSession;
|
|
368
|
+
transaction?: SessionTransaction;
|
|
369
|
+
}
|
|
370
|
+
/** 会话列表单项 */
|
|
371
|
+
interface SessionListEntry {
|
|
372
|
+
session: CheckoutSession;
|
|
373
|
+
transaction?: SessionTransaction;
|
|
374
|
+
}
|
|
375
|
+
/** GET /session/list/... 的 data(文档示例中 page/size 为数字) */
|
|
376
|
+
interface CheckoutSessionListData {
|
|
377
|
+
total: number;
|
|
378
|
+
page: number;
|
|
379
|
+
size: number;
|
|
380
|
+
sessions: SessionListEntry[];
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* 支付会话(Checkout Session)API
|
|
385
|
+
*/
|
|
386
|
+
declare class CheckoutSessionResource {
|
|
387
|
+
private readonly http;
|
|
388
|
+
constructor(http: GStableHttp);
|
|
389
|
+
/** POST /session/checkout/create */
|
|
390
|
+
create(body: CreateCheckoutSessionBody): Promise<CheckoutSession>;
|
|
391
|
+
/** POST /session/checkout/cancel(仅 initialized 且 signedOnce = 0) */
|
|
392
|
+
cancel(sessionId: string): Promise<OperationSuccess>;
|
|
393
|
+
/** GET /session/:sessionId — Checkout 与 Payment Link 会话均可查 */
|
|
394
|
+
detail(sessionId: string): Promise<SessionDetail>;
|
|
395
|
+
private listByPath;
|
|
396
|
+
/** GET /session/list/all/:page/:size */
|
|
397
|
+
listAll(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
398
|
+
/** GET /session/list/paid/:page/:size */
|
|
399
|
+
listPaid(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
400
|
+
/** GET /session/list/settling/:page/:size */
|
|
401
|
+
listSettling(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
402
|
+
/** GET /session/list/completed/:page/:size */
|
|
403
|
+
listCompleted(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
404
|
+
/** GET /session/list/cancelled/:page/:size */
|
|
405
|
+
listCancelled(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
406
|
+
/** GET /session/list/settlement/pending/:page/:size */
|
|
407
|
+
listSettlementPending(page: number, size: number): Promise<CheckoutSessionListData>;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* 支付链接模块 API
|
|
412
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/payment-link
|
|
413
|
+
*/
|
|
414
|
+
declare class PaymentLinkResource {
|
|
415
|
+
private readonly http;
|
|
416
|
+
constructor(http: GStableHttp);
|
|
417
|
+
/** POST /payment/link/create */
|
|
418
|
+
create(body: CreatePaymentLinkBody): Promise<PaymentLink>;
|
|
419
|
+
/** POST /payment/link/update(全量替换) */
|
|
420
|
+
update(body: UpdatePaymentLinkBody): Promise<OperationSuccess>;
|
|
421
|
+
/** POST /payment/link/disable */
|
|
422
|
+
disable(linkId: string): Promise<OperationSuccess>;
|
|
423
|
+
/** POST /payment/link/enable */
|
|
424
|
+
enable(linkId: string): Promise<OperationSuccess>;
|
|
425
|
+
/** GET /payment/link/:linkId */
|
|
426
|
+
detail(linkId: string): Promise<PaymentLink>;
|
|
427
|
+
/**
|
|
428
|
+
* GET /payment/link/list/:page/:size
|
|
429
|
+
* @param page 从 1 开始
|
|
430
|
+
*/
|
|
431
|
+
list(page: number, size: number): Promise<PaymentLinkListData>;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* 商品模块 API
|
|
436
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/product
|
|
437
|
+
*
|
|
438
|
+
* 商品业务错误码 100301–100306 会抛出 `GStableProductError`(仍为 `GStableError` 子类),
|
|
439
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86-1003xx
|
|
440
|
+
*/
|
|
441
|
+
declare class ProductResource {
|
|
442
|
+
private readonly http;
|
|
443
|
+
constructor(http: GStableHttp);
|
|
444
|
+
private invoke;
|
|
445
|
+
/** POST /product/create */
|
|
446
|
+
create(body: CreateProductBody): Promise<Product>;
|
|
447
|
+
/** POST /product/update(全量替换) */
|
|
448
|
+
update(body: UpdateProductBody): Promise<OperationSuccess>;
|
|
449
|
+
/**
|
|
450
|
+
* GET /product/list/:page/:size
|
|
451
|
+
* @param page 从 1 开始
|
|
452
|
+
* @param size 每页条数,最大 100
|
|
453
|
+
*/
|
|
454
|
+
list(page: number, size: number): Promise<ProductListData>;
|
|
455
|
+
/** POST /product/list/by/ids — 不存在的 id 会被静默忽略 */
|
|
456
|
+
listByIds(body: ProductListByIdsBody): Promise<Product[]>;
|
|
457
|
+
/** POST /product/archive */
|
|
458
|
+
archive(productId: string): Promise<OperationSuccess>;
|
|
459
|
+
/** POST /product/unarchive */
|
|
460
|
+
unarchive(productId: string): Promise<OperationSuccess>;
|
|
461
|
+
/** POST /product/remove — 仅未被任何 Payment Link 引用过的商品可删 */
|
|
462
|
+
remove(productId: string): Promise<OperationSuccess>;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** Webhook 状态:活跃 / 用户禁用 / 投递失败自动暂停 */
|
|
466
|
+
type WebhookStatus = 'active' | 'inactive' | 'paused' | string;
|
|
467
|
+
/**
|
|
468
|
+
* Webhook 对象
|
|
469
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/core-api/webhook-management
|
|
470
|
+
*/
|
|
471
|
+
interface Webhook {
|
|
472
|
+
webhookId: string;
|
|
473
|
+
webhookName: string;
|
|
474
|
+
webhookUrl: string;
|
|
475
|
+
webhookDescription?: string;
|
|
476
|
+
subscribedEvents: string[];
|
|
477
|
+
/** 签名密钥,创建后返回;验签见 Webhook 事件文档 */
|
|
478
|
+
key: string;
|
|
479
|
+
status: WebhookStatus;
|
|
480
|
+
createAt?: string;
|
|
481
|
+
updateAt?: string;
|
|
482
|
+
}
|
|
483
|
+
/** POST /webhook/create */
|
|
484
|
+
interface CreateWebhookBody {
|
|
485
|
+
webhookName: string;
|
|
486
|
+
webhookUrl: string;
|
|
487
|
+
subscribedEvents: string[];
|
|
488
|
+
webhookDescription?: string;
|
|
489
|
+
}
|
|
490
|
+
/** POST /webhook/update(全量替换) */
|
|
491
|
+
interface UpdateWebhookBody {
|
|
492
|
+
webhookId: string;
|
|
493
|
+
webhookName: string;
|
|
494
|
+
webhookUrl: string;
|
|
495
|
+
subscribedEvents: string[];
|
|
496
|
+
webhookDescription?: string;
|
|
497
|
+
}
|
|
498
|
+
/** GET /webhook/list 的 data */
|
|
499
|
+
interface WebhookListData {
|
|
500
|
+
webhooks: Webhook[];
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Webhook 管理 API(单账户最多 10 个端点)
|
|
505
|
+
*/
|
|
506
|
+
declare class WebhookResource {
|
|
507
|
+
private readonly http;
|
|
508
|
+
constructor(http: GStableHttp);
|
|
509
|
+
/** POST /webhook/create */
|
|
510
|
+
create(body: CreateWebhookBody): Promise<Webhook>;
|
|
511
|
+
/** POST /webhook/update(全量替换) */
|
|
512
|
+
update(body: UpdateWebhookBody): Promise<OperationSuccess>;
|
|
513
|
+
/** GET /webhook/list — 全量,无分页 */
|
|
514
|
+
list(): Promise<WebhookListData>;
|
|
515
|
+
/** GET /webhook/detail/:webhookId */
|
|
516
|
+
detail(webhookId: string): Promise<Webhook>;
|
|
517
|
+
/** POST /webhook/disable */
|
|
518
|
+
disable(webhookId: string): Promise<OperationSuccess>;
|
|
519
|
+
/** POST /webhook/enable(含从 paused 恢复) */
|
|
520
|
+
enable(webhookId: string): Promise<OperationSuccess>;
|
|
521
|
+
/** POST /webhook/key/refresh — 旧 key 立即失效 */
|
|
522
|
+
refreshKey(webhookId: string): Promise<OperationSuccess>;
|
|
523
|
+
/** POST /webhook/remove */
|
|
524
|
+
remove(webhookId: string): Promise<OperationSuccess>;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
interface GStableClientOptions extends GStableHttpOptions {
|
|
528
|
+
}
|
|
529
|
+
declare class GStableClient {
|
|
530
|
+
private readonly http;
|
|
531
|
+
readonly product: ProductResource;
|
|
532
|
+
readonly account: AccountResource;
|
|
533
|
+
readonly paymentLink: PaymentLinkResource;
|
|
534
|
+
readonly capability: CapabilityResource;
|
|
535
|
+
readonly checkoutSession: CheckoutSessionResource;
|
|
536
|
+
/** AI Payment Protocol(创建会话 / 查询 / 准备支付) */
|
|
537
|
+
readonly webhook: WebhookResource;
|
|
538
|
+
constructor(options: GStableClientOptions);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
declare class GStableError extends Error {
|
|
542
|
+
readonly code: number;
|
|
543
|
+
constructor(code: number, message: string);
|
|
544
|
+
}
|
|
545
|
+
declare function isGStableError(e: unknown): e is GStableError;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* 根据官方错误码构造对应的 {@link GStableError} 子类(商品 / 通用与验证 / 平台),供 HTTP 层与各资源统一使用。
|
|
549
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors
|
|
550
|
+
*/
|
|
551
|
+
declare function createTypedApiError(code: number, message: string): GStableError;
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* 通用与验证错误(400XXX)
|
|
555
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#4-%E9%80%9A%E7%94%A8%E4%B8%8E%E9%AA%8C%E8%AF%81%E9%94%99%E8%AF%AF-common
|
|
556
|
+
*/
|
|
557
|
+
declare const CommonErrorCodes: {
|
|
558
|
+
readonly INVALID_FIELD_FORMAT: 400101;
|
|
559
|
+
readonly UNSUPPORTED_CURRENCY: 400201;
|
|
560
|
+
readonly UNSUPPORTED_CHANNEL: 400202;
|
|
561
|
+
readonly SETTLEMENT_CAPABILITIES_NOT_FOUND: 400203;
|
|
562
|
+
readonly STAT_NOT_FOUND: 400301;
|
|
563
|
+
};
|
|
564
|
+
type CommonErrorCode = (typeof CommonErrorCodes)[keyof typeof CommonErrorCodes];
|
|
565
|
+
declare const CommonErrorMessages: Record<CommonErrorCode, string>;
|
|
566
|
+
declare function isCommonErrorCode(code: number): code is CommonErrorCode;
|
|
567
|
+
declare class GStableCommonError extends GStableError {
|
|
568
|
+
readonly commonErrorCode: CommonErrorCode;
|
|
569
|
+
constructor(code: CommonErrorCode, message: string);
|
|
570
|
+
}
|
|
571
|
+
declare function isGStableCommonError(e: unknown): e is GStableCommonError;
|
|
572
|
+
/**
|
|
573
|
+
* 平台系统错误(900XXX / 999999)
|
|
574
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#5-%E5%B9%B3%E5%8F%B0%E7%B3%BB%E7%BB%9F%E9%94%99%E8%AF%AF-platform
|
|
575
|
+
*/
|
|
576
|
+
declare const PlatformErrorCodes: {
|
|
577
|
+
readonly TOO_MANY_REQUESTS: 900101;
|
|
578
|
+
readonly FAILED_TO_CREATE_RECORD: 900201;
|
|
579
|
+
readonly FAILED_TO_UPDATE_RECORD: 900202;
|
|
580
|
+
readonly FAILED_TO_QUERY_RECORD: 900203;
|
|
581
|
+
readonly IMAGE_PROCESSING_FAILED: 900301;
|
|
582
|
+
readonly INTERNAL_SYSTEM_ERROR: 999999;
|
|
583
|
+
};
|
|
584
|
+
type PlatformErrorCode = (typeof PlatformErrorCodes)[keyof typeof PlatformErrorCodes];
|
|
585
|
+
declare const PlatformErrorMessages: Record<PlatformErrorCode, string>;
|
|
586
|
+
declare function isPlatformErrorCode(code: number): code is PlatformErrorCode;
|
|
587
|
+
declare class GStablePlatformError extends GStableError {
|
|
588
|
+
readonly platformErrorCode: PlatformErrorCode;
|
|
589
|
+
constructor(code: PlatformErrorCode, message: string);
|
|
590
|
+
}
|
|
591
|
+
declare function isGStablePlatformError(e: unknown): e is GStablePlatformError;
|
|
592
|
+
|
|
593
|
+
/**
|
|
594
|
+
* 商品管理业务错误码(1003XX)
|
|
595
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/overview/errors#%E5%95%86%E5%93%81%E7%AE%A1%E7%90%86-1003xx
|
|
596
|
+
*/
|
|
597
|
+
declare const ProductErrorCodes: {
|
|
598
|
+
/** 指定的 Product ID 不存在 */
|
|
599
|
+
readonly NOT_FOUND: 100301;
|
|
600
|
+
/** 批量操作中部分商品 ID 不存在 */
|
|
601
|
+
readonly PARTIAL_MISSING: 100302;
|
|
602
|
+
/** 批量操作中部分商品状态不可用 */
|
|
603
|
+
readonly PARTIALLY_UNAVAILABLE: 100303;
|
|
604
|
+
/** 商品未处于激活状态,无法用于创建链接或会话 */
|
|
605
|
+
readonly NOT_ACTIVE: 100304;
|
|
606
|
+
/** 商品已被关联使用,无法执行某些特定修改 */
|
|
607
|
+
readonly HAS_BEEN_USED: 100305;
|
|
608
|
+
/** 商品已被逻辑删除 */
|
|
609
|
+
readonly HAS_BEEN_REMOVED: 100306;
|
|
610
|
+
};
|
|
611
|
+
type ProductErrorCode = (typeof ProductErrorCodes)[keyof typeof ProductErrorCodes];
|
|
612
|
+
/** 文档中的英文 message,仅作展示参考;业务判断请使用 {@link ProductErrorCodes} */
|
|
613
|
+
declare const ProductErrorMessages: Record<ProductErrorCode, string>;
|
|
614
|
+
declare function isProductErrorCode(code: number): code is ProductErrorCode;
|
|
615
|
+
/**
|
|
616
|
+
* 商品模块 API 返回 1003XX 时的专用异常,可通过 `instanceof` 与 `productErrorCode` 分支处理。
|
|
617
|
+
* 请依据 `code` / `productErrorCode` 编写逻辑,勿依赖 `message` 文案。
|
|
618
|
+
*/
|
|
619
|
+
declare class GStableProductError extends GStableError {
|
|
620
|
+
readonly productErrorCode: ProductErrorCode;
|
|
621
|
+
constructor(code: ProductErrorCode, message: string);
|
|
622
|
+
}
|
|
623
|
+
declare function isGStableProductError(e: unknown): e is GStableProductError;
|
|
624
|
+
/** 将 {@link GStableError} 中属于商品业务码的异常转为 {@link GStableProductError},其它值原样返回 */
|
|
625
|
+
declare function rewriteProductBusinessError(error: unknown): unknown;
|
|
626
|
+
|
|
627
|
+
/**
|
|
628
|
+
* 与 GStable API 标准响应包络一致:https://docs.gstable.io/zh-Hans/docs/api/overview/introduction/
|
|
629
|
+
*/
|
|
630
|
+
interface ApiEnvelope<T> {
|
|
631
|
+
code: number;
|
|
632
|
+
message: string;
|
|
633
|
+
data: T;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* AI Payment Protocol — 支付会话 / 准备支付
|
|
638
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/create-session
|
|
639
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/get-session
|
|
640
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/prepare-payment
|
|
641
|
+
*/
|
|
642
|
+
/** EIP-712 消息:创建支付会话 */
|
|
643
|
+
interface CreatePaymentSessionMessage {
|
|
644
|
+
purpose: 'create_payment_session';
|
|
645
|
+
linkId: string;
|
|
646
|
+
linkVersion: string;
|
|
647
|
+
merchantId: string;
|
|
648
|
+
payer: string;
|
|
649
|
+
paymentChainId: string;
|
|
650
|
+
paymentToken: string;
|
|
651
|
+
amount: string;
|
|
652
|
+
authorizationNonce: string;
|
|
653
|
+
authorizationExpiresAt: string;
|
|
654
|
+
}
|
|
655
|
+
/** POST /payment/session/create */
|
|
656
|
+
interface CreatePaymentSessionBody {
|
|
657
|
+
message: CreatePaymentSessionMessage;
|
|
658
|
+
signature: string;
|
|
659
|
+
}
|
|
660
|
+
/** AI 视图(文档结构可能随协议扩展,字段按需收窄) */
|
|
661
|
+
interface AiPaymentView {
|
|
662
|
+
pricingModel?: {
|
|
663
|
+
type: string;
|
|
664
|
+
};
|
|
665
|
+
workflow?: {
|
|
666
|
+
stage: string;
|
|
667
|
+
nextAction?: {
|
|
668
|
+
action: string;
|
|
669
|
+
authorizationRequired?: boolean;
|
|
670
|
+
description?: string;
|
|
671
|
+
};
|
|
672
|
+
};
|
|
673
|
+
preparePaymentRequirement?: unknown;
|
|
674
|
+
paymentExecutionGuide?: unknown;
|
|
675
|
+
completePaymentSessionGuide?: unknown;
|
|
676
|
+
}
|
|
677
|
+
/** POST /payment/session/create 返回的 data */
|
|
678
|
+
interface CreatePaymentSessionResult {
|
|
679
|
+
sessionId: string;
|
|
680
|
+
sessionType: string;
|
|
681
|
+
sessionExpiresAt: number;
|
|
682
|
+
aiView: AiPaymentView;
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* GET /session/:sessionId — AI 流程下的会话详情(扁平结构,含 aiView)。
|
|
686
|
+
* 与核心 API 会话查询共用路径;若需 `session`/`transaction` 对账结构请使用 `checkoutSession.detail`。
|
|
687
|
+
*/
|
|
688
|
+
interface AiPaymentSession {
|
|
689
|
+
sessionId: string;
|
|
690
|
+
sessionType: string;
|
|
691
|
+
lineItems?: unknown[];
|
|
692
|
+
aiView: AiPaymentView;
|
|
693
|
+
}
|
|
694
|
+
/** EIP-712 消息:准备支付 */
|
|
695
|
+
interface PreparePaymentMessage {
|
|
696
|
+
purpose: 'prepare_payment';
|
|
697
|
+
sessionId: string;
|
|
698
|
+
merchantId: string;
|
|
699
|
+
payer: string;
|
|
700
|
+
payerEmail: string;
|
|
701
|
+
paymentChainId: string;
|
|
702
|
+
paymentToken: string;
|
|
703
|
+
authorizationNonce: string;
|
|
704
|
+
authorizationExpiresAt: string;
|
|
705
|
+
}
|
|
706
|
+
/** POST /payment/prepare */
|
|
707
|
+
interface PreparePaymentBody {
|
|
708
|
+
message: PreparePaymentMessage;
|
|
709
|
+
signature: string;
|
|
710
|
+
}
|
|
711
|
+
/** POST /payment/prepare 返回的 data */
|
|
712
|
+
interface PreparePaymentResult {
|
|
713
|
+
calldata: string;
|
|
714
|
+
aiView: AiPaymentView;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* AI Payment Protocol(EIP-712 签名由调用方生成后传入)
|
|
719
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/create-session
|
|
720
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/get-session
|
|
721
|
+
* @see https://docs.gstable.io/zh-Hans/docs/api/ai-payment/prepare-payment
|
|
722
|
+
*/
|
|
723
|
+
declare class AiPaymentResource {
|
|
724
|
+
private readonly http;
|
|
725
|
+
constructor(http: GStableHttp);
|
|
726
|
+
/** POST /payment/session/create */
|
|
727
|
+
createSession(body: CreatePaymentSessionBody): Promise<CreatePaymentSessionResult>;
|
|
728
|
+
/**
|
|
729
|
+
* GET /session/:sessionId
|
|
730
|
+
* 与核心 `checkoutSession.detail` 同路径;本方法按 AI 文档将 data 解析为含 `aiView` 的扁平结构。
|
|
731
|
+
*/
|
|
732
|
+
getSession(sessionId: string): Promise<AiPaymentSession>;
|
|
733
|
+
/** POST /payment/prepare */
|
|
734
|
+
preparePayment(body: PreparePaymentBody): Promise<PreparePaymentResult>;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
export { type Account, AccountResource, type AccountStatus, type AccountType, AiPaymentResource, type AiPaymentSession, type AiPaymentView, type ApiEnvelope, CapabilityResource, type CheckoutLineItem, type CheckoutLineItemInput, type CheckoutLineItemsSection, type CheckoutSession, type CheckoutSessionFeeModel, type CheckoutSessionListData, CheckoutSessionResource, type CheckoutSessionStatus, type CommonErrorCode, CommonErrorCodes, CommonErrorMessages, type CreateCheckoutSessionBody, type CreatePaymentLinkBody, type CreatePaymentSessionBody, type CreatePaymentSessionMessage, type CreatePaymentSessionResult, type CreateProductBody, type CreateWebhookBody, DEFAULT_BASE_URL, DEFAULT_PUBLIC_BASE_URL, GStableClient, type GStableClientOptions, GStableCommonError, GStableError, GStableHttp, type GStableHttpOptions, GStablePlatformError, GStableProductError, type HttpMethod, type OneTimeProductDataInput, type OperationSuccess, type PaymentCapabilities, type PaymentCapabilitiesMatrix, type PaymentCapabilityRoute, type PaymentLink, type PaymentLinkFeeModel, type PaymentLinkLineItem, type PaymentLinkLineItemInput, type PaymentLinkLineItemProductData, type PaymentLinkLineItemsSection, type PaymentLinkListData, PaymentLinkResource, type PaymentLinkStatus, type PaymentLinkType, type PlatformErrorCode, PlatformErrorCodes, PlatformErrorMessages, type PreparePaymentBody, type PreparePaymentMessage, type PreparePaymentResult, type Product, type ProductAttribute, type ProductErrorCode, ProductErrorCodes, ProductErrorMessages, type ProductListByIdsBody, type ProductListData, ProductResource, type ProductStatus, type SessionDetail, type SessionListEntry, type SessionTransaction, type SettlementTokenInfo, type SupportedToken, type UpdatePaymentLinkBody, type UpdateProductBody, type UpdateWebhookBody, type Webhook, type WebhookListData, WebhookResource, type WebhookStatus, createTypedApiError, isCommonErrorCode, isGStableCommonError, isGStableError, isGStablePlatformError, isGStableProductError, isPlatformErrorCode, isProductErrorCode, rewriteProductBusinessError };
|