@seaverse/payment-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 +156 -0
- package/dist/index.browser.js +5058 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.cjs +1177 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +1058 -0
- package/dist/index.js +1148 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1058 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for SeaVerse Payment API
|
|
3
|
+
* Generated from payment.yaml OpenAPI specification
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Credit pool type in the 4-pool system
|
|
7
|
+
* - daily: Daily credits (expires at next day 00:00 UTC)
|
|
8
|
+
* - event: Event credits (expires at event deadline)
|
|
9
|
+
* - monthly: Monthly credits (expires 30 days after last grant)
|
|
10
|
+
* - permanent: Permanent credits (never expires)
|
|
11
|
+
*/
|
|
12
|
+
type CreditPoolType = 'daily' | 'event' | 'monthly' | 'permanent';
|
|
13
|
+
/**
|
|
14
|
+
* Single credit pool detail
|
|
15
|
+
*/
|
|
16
|
+
interface CreditPoolDetail {
|
|
17
|
+
/**
|
|
18
|
+
* Pool type
|
|
19
|
+
*/
|
|
20
|
+
type: CreditPoolType;
|
|
21
|
+
/**
|
|
22
|
+
* Balance in this pool (decimal string for precision)
|
|
23
|
+
*/
|
|
24
|
+
balance: string;
|
|
25
|
+
/**
|
|
26
|
+
* Expiration timestamp in milliseconds
|
|
27
|
+
* - 0 means never expires (permanent pool only)
|
|
28
|
+
* - > 0 means specific expiration time (Unix timestamp in ms)
|
|
29
|
+
*/
|
|
30
|
+
expires_at: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Credit detail response data
|
|
34
|
+
*/
|
|
35
|
+
interface CreditDetailResponse {
|
|
36
|
+
/**
|
|
37
|
+
* Total balance across all pools
|
|
38
|
+
*/
|
|
39
|
+
total_balance: string;
|
|
40
|
+
/**
|
|
41
|
+
* Array of pool details (only includes pools with balance > 0)
|
|
42
|
+
*/
|
|
43
|
+
pools: CreditPoolDetail[];
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Credit detail success response
|
|
47
|
+
*/
|
|
48
|
+
interface CreditDetailSuccessResponse {
|
|
49
|
+
code: 0;
|
|
50
|
+
message: string;
|
|
51
|
+
data: CreditDetailResponse;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Credit account model
|
|
55
|
+
*/
|
|
56
|
+
interface CreditAccount {
|
|
57
|
+
id: string;
|
|
58
|
+
user_id: string;
|
|
59
|
+
app_id: string | null;
|
|
60
|
+
balance: number;
|
|
61
|
+
total_earned: number;
|
|
62
|
+
total_spent: number;
|
|
63
|
+
frozen_balance: number;
|
|
64
|
+
last_transaction_id?: string;
|
|
65
|
+
status: CreditAccountStatus;
|
|
66
|
+
status_reason?: string;
|
|
67
|
+
created_at: string;
|
|
68
|
+
updated_at: string;
|
|
69
|
+
last_activity_at?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Credit account status
|
|
73
|
+
*/
|
|
74
|
+
type CreditAccountStatus = 'active' | 'suspended' | 'frozen';
|
|
75
|
+
/**
|
|
76
|
+
* Credit transaction model
|
|
77
|
+
*/
|
|
78
|
+
interface CreditTransaction {
|
|
79
|
+
id: string;
|
|
80
|
+
user_id: string;
|
|
81
|
+
app_id: string | null;
|
|
82
|
+
type: TransactionType;
|
|
83
|
+
amount: number;
|
|
84
|
+
balance_before: number;
|
|
85
|
+
balance_after: number;
|
|
86
|
+
source: string;
|
|
87
|
+
source_id?: string;
|
|
88
|
+
description: string;
|
|
89
|
+
status: TransactionStatus;
|
|
90
|
+
status_reason?: string;
|
|
91
|
+
metadata?: Record<string, unknown>;
|
|
92
|
+
created_at: string;
|
|
93
|
+
completed_at?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Transaction type
|
|
97
|
+
*/
|
|
98
|
+
type TransactionType = 'spend' | 'earn' | 'refund' | 'adjust' | 'freeze' | 'unfreeze';
|
|
99
|
+
/**
|
|
100
|
+
* Transaction status
|
|
101
|
+
*/
|
|
102
|
+
type TransactionStatus = 'pending' | 'completed' | 'failed' | 'cancelled';
|
|
103
|
+
/**
|
|
104
|
+
* List transactions request parameters
|
|
105
|
+
*/
|
|
106
|
+
interface ListTransactionsRequest {
|
|
107
|
+
type?: TransactionType;
|
|
108
|
+
source?: string;
|
|
109
|
+
status?: TransactionStatus;
|
|
110
|
+
start_date?: string;
|
|
111
|
+
end_date?: string;
|
|
112
|
+
page?: number;
|
|
113
|
+
page_size?: number;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Transaction list response
|
|
117
|
+
*/
|
|
118
|
+
interface TransactionListResponse {
|
|
119
|
+
transactions: CreditTransaction[];
|
|
120
|
+
page: number;
|
|
121
|
+
page_size: number;
|
|
122
|
+
has_more: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Standard success response wrapper
|
|
126
|
+
*/
|
|
127
|
+
interface ApiSuccessResponse<T> {
|
|
128
|
+
code: 0;
|
|
129
|
+
message: string;
|
|
130
|
+
data: T;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Standard error response
|
|
134
|
+
*/
|
|
135
|
+
interface ApiErrorResponse {
|
|
136
|
+
code: number;
|
|
137
|
+
message: string;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* API response type (success or error)
|
|
141
|
+
*/
|
|
142
|
+
type ApiResponse<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Payment client configuration options
|
|
146
|
+
*/
|
|
147
|
+
interface PaymentClientOptions {
|
|
148
|
+
/**
|
|
149
|
+
* Base URL for the Payment API
|
|
150
|
+
* @default 'https://payment.sg.seaverse.dev'
|
|
151
|
+
* @example 'https://payment.sg.seaverse.dev'
|
|
152
|
+
*/
|
|
153
|
+
baseURL?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Application ID for multi-tenant isolation
|
|
156
|
+
* @example 'seaverse' for SeaVerse platform
|
|
157
|
+
* @example 'game-abc123' for third-party apps
|
|
158
|
+
*/
|
|
159
|
+
appId: string;
|
|
160
|
+
/**
|
|
161
|
+
* Bearer token for authentication
|
|
162
|
+
*/
|
|
163
|
+
token: string;
|
|
164
|
+
/**
|
|
165
|
+
* Request timeout in milliseconds
|
|
166
|
+
* @default 30000
|
|
167
|
+
*/
|
|
168
|
+
timeout?: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Payment API error
|
|
172
|
+
*/
|
|
173
|
+
declare class PaymentAPIError extends Error {
|
|
174
|
+
code: number;
|
|
175
|
+
response?: ApiErrorResponse | undefined;
|
|
176
|
+
constructor(message: string, code: number, response?: ApiErrorResponse | undefined);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* SeaVerse Payment API Client
|
|
180
|
+
*
|
|
181
|
+
* Provides query capabilities for user credit accounts and transactions with multi-tenant support.
|
|
182
|
+
* All methods are read-only - credit spending/granting is handled by platform backend.
|
|
183
|
+
*
|
|
184
|
+
* ## Multi-tenant Architecture
|
|
185
|
+
* - Each app has isolated credit accounts using `app_id`
|
|
186
|
+
* - Same user can have different credit accounts in different apps
|
|
187
|
+
* - Use `appId` to specify which app's credit pool to access
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* // SeaVerse platform usage
|
|
192
|
+
* const client = new PaymentClient({
|
|
193
|
+
* appId: 'seaverse',
|
|
194
|
+
* token: 'your-bearer-token'
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // Third-party app usage
|
|
198
|
+
* const gameClient = new PaymentClient({
|
|
199
|
+
* appId: 'game-abc123',
|
|
200
|
+
* token: 'your-bearer-token'
|
|
201
|
+
* });
|
|
202
|
+
*
|
|
203
|
+
* // Get credit account
|
|
204
|
+
* const account = await client.getCreditAccount();
|
|
205
|
+
* console.log(`Balance: ${account.balance} credits`);
|
|
206
|
+
*
|
|
207
|
+
* // List recent transactions
|
|
208
|
+
* const transactions = await client.listTransactions({ page_size: 10 });
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
declare class PaymentClient {
|
|
212
|
+
private axios;
|
|
213
|
+
constructor(options: PaymentClientOptions);
|
|
214
|
+
/**
|
|
215
|
+
* Get credit detail with 4-pool system information
|
|
216
|
+
*
|
|
217
|
+
* Returns detailed credit information across 4 pools (daily/event/monthly/permanent)
|
|
218
|
+
* with expiration timestamps. This is the recommended method for displaying user credits.
|
|
219
|
+
*
|
|
220
|
+
* **Credit Pool Types:**
|
|
221
|
+
* - `daily`: Daily credits (expires at next day 00:00 UTC)
|
|
222
|
+
* - `event`: Event credits (expires at event deadline)
|
|
223
|
+
* - `monthly`: Monthly credits (expires 30 days after last grant)
|
|
224
|
+
* - `permanent`: Permanent credits (never expires)
|
|
225
|
+
*
|
|
226
|
+
* **Consumption Priority:**
|
|
227
|
+
* Daily → Event → Monthly → Permanent
|
|
228
|
+
*
|
|
229
|
+
* **Response Features:**
|
|
230
|
+
* - Only returns pools with balance > 0
|
|
231
|
+
* - `expires_at` is millisecond timestamp (0 means permanent)
|
|
232
|
+
* - Frontend can calculate remaining time from timestamp
|
|
233
|
+
*
|
|
234
|
+
* **Recommended Refresh Rate:** 30 seconds
|
|
235
|
+
*
|
|
236
|
+
* @returns Credit detail with pool breakdown
|
|
237
|
+
* @throws {PaymentAPIError} If request fails
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const detail = await client.getCreditDetail();
|
|
242
|
+
* console.log(`Total Balance: ${detail.total_balance}`);
|
|
243
|
+
*
|
|
244
|
+
* detail.pools.forEach(pool => {
|
|
245
|
+
* const label = pool.expires_at === 0
|
|
246
|
+
* ? 'Permanent'
|
|
247
|
+
* : `Expires in ${Math.floor((pool.expires_at - Date.now()) / 86400000)} days`;
|
|
248
|
+
* console.log(`${pool.type}: ${pool.balance} (${label})`);
|
|
249
|
+
* });
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
getCreditDetail(): Promise<CreditDetailResponse>;
|
|
253
|
+
/**
|
|
254
|
+
* Get authenticated user's credit account information
|
|
255
|
+
*
|
|
256
|
+
* Returns current balance, total earned/spent, frozen balance, and account status.
|
|
257
|
+
*
|
|
258
|
+
* @deprecated Use getCreditDetail() instead for the new 4-pool credit system
|
|
259
|
+
* @returns Credit account information
|
|
260
|
+
* @throws {PaymentAPIError} If request fails
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```typescript
|
|
264
|
+
* const account = await client.getCreditAccount();
|
|
265
|
+
* console.log(`Balance: ${account.balance}`);
|
|
266
|
+
* console.log(`Status: ${account.status}`);
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
getCreditAccount(): Promise<CreditAccount>;
|
|
270
|
+
/**
|
|
271
|
+
* List credit transactions with filters and pagination
|
|
272
|
+
*
|
|
273
|
+
* Query user's transaction history with optional filters for type, source, status, and date range.
|
|
274
|
+
* Supports pagination with max 50 items per page.
|
|
275
|
+
*
|
|
276
|
+
* @param request - List transactions request parameters
|
|
277
|
+
* @returns Paginated transaction list with has_more flag
|
|
278
|
+
* @throws {PaymentAPIError} If request fails
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```typescript
|
|
282
|
+
* // Get recent transactions
|
|
283
|
+
* const result = await client.listTransactions({ page_size: 20 });
|
|
284
|
+
*
|
|
285
|
+
* // Filter by type
|
|
286
|
+
* const spending = await client.listTransactions({
|
|
287
|
+
* type: 'spend',
|
|
288
|
+
* page: 1,
|
|
289
|
+
* page_size: 10
|
|
290
|
+
* });
|
|
291
|
+
*
|
|
292
|
+
* // Filter by date range
|
|
293
|
+
* const recentTransactions = await client.listTransactions({
|
|
294
|
+
* start_date: '2024-01-01T00:00:00Z',
|
|
295
|
+
* end_date: '2024-12-31T23:59:59Z',
|
|
296
|
+
* status: 'completed'
|
|
297
|
+
* });
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
listTransactions(request?: ListTransactionsRequest): Promise<TransactionListResponse>;
|
|
301
|
+
/**
|
|
302
|
+
* Update the bearer token for authentication
|
|
303
|
+
*
|
|
304
|
+
* Use this method to update the token when it expires or needs to be refreshed.
|
|
305
|
+
*
|
|
306
|
+
* @param token - New bearer token
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* client.setToken('new-bearer-token');
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
setToken(token: string): void;
|
|
314
|
+
/**
|
|
315
|
+
* Update the base URL for the API
|
|
316
|
+
*
|
|
317
|
+
* Use this method to switch between different environments (dev/staging/prod).
|
|
318
|
+
*
|
|
319
|
+
* @param baseURL - New base URL
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* client.setBaseURL('https://payment.sg.seaverse.dev');
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
setBaseURL(baseURL: string): void;
|
|
327
|
+
/**
|
|
328
|
+
* Update the app ID for multi-tenant isolation
|
|
329
|
+
*
|
|
330
|
+
* Use this method to switch between different apps at runtime.
|
|
331
|
+
*
|
|
332
|
+
* @param appId - New app ID
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```typescript
|
|
336
|
+
* // Switch to SeaVerse platform
|
|
337
|
+
* client.setAppId('seaverse');
|
|
338
|
+
*
|
|
339
|
+
* // Switch to third-party app
|
|
340
|
+
* client.setAppId('game-abc123');
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
setAppId(appId: string): void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* SeaVerse Payment SDK - 支付弹窗类型定义
|
|
348
|
+
* 基于 OpenAPI 规范和 SeaArt Payment SDK 定义
|
|
349
|
+
*/
|
|
350
|
+
/**
|
|
351
|
+
* 支付环境
|
|
352
|
+
*/
|
|
353
|
+
type PaymentEnvironment = 'develop' | 'release';
|
|
354
|
+
/**
|
|
355
|
+
* 支付弹窗客户端配置
|
|
356
|
+
*/
|
|
357
|
+
interface CheckoutClientConfig {
|
|
358
|
+
/** 支付网关 API 地址 */
|
|
359
|
+
apiHost: string;
|
|
360
|
+
/** 运行环境 */
|
|
361
|
+
environment?: PaymentEnvironment;
|
|
362
|
+
/** 调试模式 */
|
|
363
|
+
debug?: boolean;
|
|
364
|
+
/**
|
|
365
|
+
* JWT Token(静态传入)
|
|
366
|
+
* 与 getAuthToken 二选一,authToken 优先级更高
|
|
367
|
+
*/
|
|
368
|
+
authToken?: string;
|
|
369
|
+
/**
|
|
370
|
+
* 获取 JWT Token 的函数(动态获取)
|
|
371
|
+
* 与 authToken 二选一
|
|
372
|
+
*/
|
|
373
|
+
getAuthToken?: () => string | null | Promise<string | null>;
|
|
374
|
+
/** SDK CDN 地址(可选,使用默认值) */
|
|
375
|
+
sdkCdnUrl?: string;
|
|
376
|
+
/** SDK 加载超时时间(毫秒) */
|
|
377
|
+
sdkTimeout?: number;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* SDK 初始化配置(从 API 返回)
|
|
381
|
+
*/
|
|
382
|
+
interface SDKConfig {
|
|
383
|
+
/** SeaArt App ID */
|
|
384
|
+
appId: string;
|
|
385
|
+
/** SeaArt API Host */
|
|
386
|
+
apiHost: string;
|
|
387
|
+
/** 运行环境 */
|
|
388
|
+
environment: PaymentEnvironment;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* 购买类型
|
|
392
|
+
* - 1: 一次性购买
|
|
393
|
+
* - 2: 订阅
|
|
394
|
+
*/
|
|
395
|
+
type PurchaseType = 1 | 2;
|
|
396
|
+
/**
|
|
397
|
+
* 订阅周期
|
|
398
|
+
*/
|
|
399
|
+
type SubscriptionPeriod = 'week' | 'month' | 'year';
|
|
400
|
+
/**
|
|
401
|
+
* 订阅参数
|
|
402
|
+
*/
|
|
403
|
+
interface SubscriptionParams {
|
|
404
|
+
/** 订阅周期 */
|
|
405
|
+
period: SubscriptionPeriod;
|
|
406
|
+
/** 首次计费延迟天数(0 = 立即扣费) */
|
|
407
|
+
firstDays?: number;
|
|
408
|
+
/** 每周期金额(USD) */
|
|
409
|
+
periodAmount: number;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* 基础结账选项
|
|
413
|
+
*/
|
|
414
|
+
interface BaseCheckoutOptions {
|
|
415
|
+
/** 商品 ID(推荐,自动查询价格) */
|
|
416
|
+
productId?: string;
|
|
417
|
+
/** 商品名称(仅当未提供 productId 时使用) */
|
|
418
|
+
productName?: string;
|
|
419
|
+
/** 价格 USD(仅当未提供 productId 时使用) */
|
|
420
|
+
price?: number;
|
|
421
|
+
/** 额外自定义数据 */
|
|
422
|
+
extra?: Record<string, unknown>;
|
|
423
|
+
/** 语言设置 */
|
|
424
|
+
language?: string;
|
|
425
|
+
/** 用户名(显示用) */
|
|
426
|
+
userName?: string;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* 一次性购买选项
|
|
430
|
+
*/
|
|
431
|
+
interface CheckoutOptions extends BaseCheckoutOptions {
|
|
432
|
+
/** 支付成功回调 */
|
|
433
|
+
onSuccess?: (result: PaymentResult) => void;
|
|
434
|
+
/** 支付失败/取消回调 */
|
|
435
|
+
onError?: (error: CheckoutPaymentError) => void;
|
|
436
|
+
/** 关闭支付弹窗回调 */
|
|
437
|
+
onClose?: () => void;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* 订阅购买选项
|
|
441
|
+
*/
|
|
442
|
+
interface SubscribeOptions extends CheckoutOptions {
|
|
443
|
+
/** 订阅周期 */
|
|
444
|
+
period: SubscriptionPeriod;
|
|
445
|
+
/** 每期金额 */
|
|
446
|
+
periodAmount: number;
|
|
447
|
+
/** 首次扣款延迟天数(0 = 立即扣款) */
|
|
448
|
+
firstDays?: number;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* 显示支付弹窗选项
|
|
452
|
+
*/
|
|
453
|
+
interface ShowPaymentOptions {
|
|
454
|
+
/** 交易 ID */
|
|
455
|
+
transactionId: string;
|
|
456
|
+
/** 语言 */
|
|
457
|
+
language?: string;
|
|
458
|
+
/** 用户名 */
|
|
459
|
+
userName?: string;
|
|
460
|
+
/** 商品名 */
|
|
461
|
+
productName?: string;
|
|
462
|
+
/** 来源标识 */
|
|
463
|
+
from?: string;
|
|
464
|
+
/** 成功回调 */
|
|
465
|
+
onSuccess?: (result: PaymentResult) => void;
|
|
466
|
+
/** 失败/取消回调 */
|
|
467
|
+
onUnsuccess?: (result: PaymentUnsuccessResult) => void;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* SDK 结账请求
|
|
471
|
+
*/
|
|
472
|
+
interface SDKCheckoutRequest {
|
|
473
|
+
/** 商品 ID(推荐) */
|
|
474
|
+
product_id?: string;
|
|
475
|
+
/** 商品名称 */
|
|
476
|
+
product_name?: string;
|
|
477
|
+
/** 价格(USD) */
|
|
478
|
+
price?: number;
|
|
479
|
+
/** 购买类型:1-一次性,2-订阅 */
|
|
480
|
+
purchase_type: PurchaseType;
|
|
481
|
+
/** 订阅参数(purchase_type=2 时必填) */
|
|
482
|
+
subscription?: SubscriptionParams;
|
|
483
|
+
/** 额外数据 */
|
|
484
|
+
extra?: Record<string, unknown>;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* SDK 结账响应
|
|
488
|
+
*/
|
|
489
|
+
interface SDKCheckoutResponse {
|
|
490
|
+
/** 订单 ID */
|
|
491
|
+
order_id: string;
|
|
492
|
+
/** 交易 ID(用于调起 SDK) */
|
|
493
|
+
transaction_id: string;
|
|
494
|
+
/** 实际支付金额 */
|
|
495
|
+
price: number;
|
|
496
|
+
/** 货币代码 */
|
|
497
|
+
currency: string;
|
|
498
|
+
/** SDK 初始化配置 */
|
|
499
|
+
sdk_config: {
|
|
500
|
+
app_id: string;
|
|
501
|
+
api_host: string;
|
|
502
|
+
environment: PaymentEnvironment;
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* 统一 API 响应格式
|
|
507
|
+
*/
|
|
508
|
+
interface CheckoutAPIResponse<T> {
|
|
509
|
+
/** 业务状态码:0-成功,其他-错误 */
|
|
510
|
+
code: number;
|
|
511
|
+
/** 响应消息 */
|
|
512
|
+
msg: string;
|
|
513
|
+
/** 响应数据 */
|
|
514
|
+
data: T | null;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* 结账结果
|
|
518
|
+
*/
|
|
519
|
+
interface CheckoutResult {
|
|
520
|
+
/** 订单 ID */
|
|
521
|
+
orderId: string;
|
|
522
|
+
/** 交易 ID */
|
|
523
|
+
transactionId: string;
|
|
524
|
+
/** 支付金额 */
|
|
525
|
+
price: number;
|
|
526
|
+
/** 货币代码 */
|
|
527
|
+
currency: string;
|
|
528
|
+
/** SDK 配置 */
|
|
529
|
+
sdkConfig: SDKConfig;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* 支付成功结果
|
|
533
|
+
*/
|
|
534
|
+
interface PaymentResult {
|
|
535
|
+
/** 交易 ID */
|
|
536
|
+
transactionId: string;
|
|
537
|
+
/** 状态 */
|
|
538
|
+
status: 'success';
|
|
539
|
+
/** 额外数据 */
|
|
540
|
+
data?: Record<string, unknown>;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* 支付未成功结果
|
|
544
|
+
*/
|
|
545
|
+
interface PaymentUnsuccessResult {
|
|
546
|
+
/** 原因 */
|
|
547
|
+
reason: 'cancel' | 'error' | 'timeout';
|
|
548
|
+
/** 消息 */
|
|
549
|
+
message: string;
|
|
550
|
+
/** 交易 ID */
|
|
551
|
+
transactionId: string;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* 支付错误代码
|
|
555
|
+
*/
|
|
556
|
+
type CheckoutPaymentErrorCode = 'SDK_LOAD_FAILED' | 'SDK_NOT_READY' | 'API_ERROR' | 'CHECKOUT_FAILED' | 'PAYMENT_CANCELLED' | 'PAYMENT_FAILED' | 'INVALID_PARAMS' | 'UNAUTHORIZED' | 'NETWORK_ERROR' | 'UNKNOWN_ERROR';
|
|
557
|
+
/**
|
|
558
|
+
* 支付错误
|
|
559
|
+
*/
|
|
560
|
+
interface CheckoutPaymentError {
|
|
561
|
+
/** 错误代码 */
|
|
562
|
+
code: CheckoutPaymentErrorCode;
|
|
563
|
+
/** 错误消息 */
|
|
564
|
+
message: string;
|
|
565
|
+
/** 原始错误 */
|
|
566
|
+
cause?: unknown;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* SeaArtPay SDK 实例接口
|
|
570
|
+
*/
|
|
571
|
+
interface SeaArtPaySDK {
|
|
572
|
+
/** 初始化 */
|
|
573
|
+
init(config: {
|
|
574
|
+
debug?: boolean;
|
|
575
|
+
iframeUrl?: string;
|
|
576
|
+
}): void;
|
|
577
|
+
/** 显示支付弹窗 */
|
|
578
|
+
show(options: {
|
|
579
|
+
transactionId: string;
|
|
580
|
+
language?: string;
|
|
581
|
+
userName?: string;
|
|
582
|
+
productName?: string;
|
|
583
|
+
from?: string;
|
|
584
|
+
onSuccess?: (result: unknown) => void;
|
|
585
|
+
onUnsuccess?: (result: unknown) => void;
|
|
586
|
+
}): void;
|
|
587
|
+
/** 关闭支付弹窗 */
|
|
588
|
+
close(): void;
|
|
589
|
+
/** 版本号 */
|
|
590
|
+
version?: string;
|
|
591
|
+
}
|
|
592
|
+
/**
|
|
593
|
+
* 全局 Window 扩展
|
|
594
|
+
*/
|
|
595
|
+
declare global {
|
|
596
|
+
interface Window {
|
|
597
|
+
SeaArtPay?: SeaArtPaySDK | {
|
|
598
|
+
SeaArtPay: SeaArtPaySDK;
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* PaymentCheckoutClient - 支付弹窗客户端
|
|
605
|
+
* 提供支付弹窗的初始化、结账和订阅功能
|
|
606
|
+
*/
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* 支付客户端状态
|
|
610
|
+
*/
|
|
611
|
+
type CheckoutClientStatus = 'idle' | 'initializing' | 'ready' | 'error';
|
|
612
|
+
/**
|
|
613
|
+
* 支付弹窗客户端类
|
|
614
|
+
*
|
|
615
|
+
* 提供一次性购买和订阅购买功能,自动处理:
|
|
616
|
+
* - SeaArtPay SDK 的动态加载
|
|
617
|
+
* - 创建结账订单
|
|
618
|
+
* - 显示支付弹窗
|
|
619
|
+
* - 支付结果回调
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```typescript
|
|
623
|
+
* // 创建客户端
|
|
624
|
+
* const checkoutClient = new PaymentCheckoutClient({
|
|
625
|
+
* apiHost: 'https://payment.sg.seaverse.dev',
|
|
626
|
+
* authToken: 'your-jwt-token',
|
|
627
|
+
* environment: 'develop',
|
|
628
|
+
* debug: true,
|
|
629
|
+
* });
|
|
630
|
+
*
|
|
631
|
+
* // 初始化
|
|
632
|
+
* await checkoutClient.init();
|
|
633
|
+
*
|
|
634
|
+
* // 发起购买
|
|
635
|
+
* const result = await checkoutClient.checkout({
|
|
636
|
+
* productId: 'pkg_starter',
|
|
637
|
+
* onSuccess: (res) => console.log('支付成功:', res),
|
|
638
|
+
* onError: (err) => console.error('支付失败:', err),
|
|
639
|
+
* });
|
|
640
|
+
* ```
|
|
641
|
+
*/
|
|
642
|
+
declare class PaymentCheckoutClient {
|
|
643
|
+
private config;
|
|
644
|
+
private loader;
|
|
645
|
+
private checkoutAPI;
|
|
646
|
+
private status;
|
|
647
|
+
private initPromise;
|
|
648
|
+
constructor(config: CheckoutClientConfig);
|
|
649
|
+
/**
|
|
650
|
+
* 获取客户端状态
|
|
651
|
+
*/
|
|
652
|
+
getStatus(): CheckoutClientStatus;
|
|
653
|
+
/**
|
|
654
|
+
* 检查是否已初始化
|
|
655
|
+
*/
|
|
656
|
+
isReady(): boolean;
|
|
657
|
+
/**
|
|
658
|
+
* 初始化客户端
|
|
659
|
+
* 加载 SeaArtPay SDK
|
|
660
|
+
*/
|
|
661
|
+
init(): Promise<void>;
|
|
662
|
+
private doInit;
|
|
663
|
+
/**
|
|
664
|
+
* 一次性购买
|
|
665
|
+
* @param options 购买选项
|
|
666
|
+
* @returns 结账结果(包含 transactionId)
|
|
667
|
+
*/
|
|
668
|
+
checkout(options: CheckoutOptions): Promise<CheckoutResult>;
|
|
669
|
+
/**
|
|
670
|
+
* 订阅购买
|
|
671
|
+
* @param options 订阅选项
|
|
672
|
+
* @returns 结账结果(包含 transactionId)
|
|
673
|
+
*/
|
|
674
|
+
subscribe(options: SubscribeOptions): Promise<CheckoutResult>;
|
|
675
|
+
/**
|
|
676
|
+
* 直接打开支付弹窗
|
|
677
|
+
* 使用已有的 transactionId
|
|
678
|
+
*/
|
|
679
|
+
showPayment(options: ShowPaymentOptions): void;
|
|
680
|
+
/**
|
|
681
|
+
* 关闭支付弹窗
|
|
682
|
+
*/
|
|
683
|
+
close(): void;
|
|
684
|
+
/**
|
|
685
|
+
* 获取环境配置
|
|
686
|
+
*/
|
|
687
|
+
getEnvironmentConfig(): {
|
|
688
|
+
apiHost: string;
|
|
689
|
+
iframeUrl: string;
|
|
690
|
+
};
|
|
691
|
+
/**
|
|
692
|
+
* 确保客户端已就绪
|
|
693
|
+
*/
|
|
694
|
+
private ensureReady;
|
|
695
|
+
/**
|
|
696
|
+
* 获取 SDK 实例
|
|
697
|
+
*/
|
|
698
|
+
private getSDK;
|
|
699
|
+
/**
|
|
700
|
+
* 显示支付弹窗
|
|
701
|
+
*/
|
|
702
|
+
private showPaymentModal;
|
|
703
|
+
/**
|
|
704
|
+
* 创建支付错误
|
|
705
|
+
*/
|
|
706
|
+
private createError;
|
|
707
|
+
/**
|
|
708
|
+
* 日志输出
|
|
709
|
+
*/
|
|
710
|
+
private log;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* 结账 API 模块
|
|
715
|
+
* 实现 /api/v1/payment/sdk/checkout 接口调用
|
|
716
|
+
*/
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* 结账 API 配置
|
|
720
|
+
*/
|
|
721
|
+
interface CheckoutAPIConfig {
|
|
722
|
+
/** API 基础地址 */
|
|
723
|
+
apiHost: string;
|
|
724
|
+
/** 获取 JWT Token */
|
|
725
|
+
getAuthToken: () => string | null | Promise<string | null>;
|
|
726
|
+
/** 调试模式 */
|
|
727
|
+
debug?: boolean;
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* 结账 API 客户端
|
|
731
|
+
*/
|
|
732
|
+
declare class CheckoutAPI {
|
|
733
|
+
private config;
|
|
734
|
+
constructor(config: CheckoutAPIConfig);
|
|
735
|
+
/**
|
|
736
|
+
* 创建一次性购买订单
|
|
737
|
+
*/
|
|
738
|
+
createOneTimeCheckout(params: {
|
|
739
|
+
productId?: string;
|
|
740
|
+
productName?: string;
|
|
741
|
+
price?: number;
|
|
742
|
+
extra?: Record<string, unknown>;
|
|
743
|
+
}): Promise<CheckoutResult>;
|
|
744
|
+
/**
|
|
745
|
+
* 创建订阅订单
|
|
746
|
+
*/
|
|
747
|
+
createSubscriptionCheckout(params: {
|
|
748
|
+
productId?: string;
|
|
749
|
+
productName?: string;
|
|
750
|
+
price?: number;
|
|
751
|
+
subscription: SubscriptionParams;
|
|
752
|
+
extra?: Record<string, unknown>;
|
|
753
|
+
}): Promise<CheckoutResult>;
|
|
754
|
+
/**
|
|
755
|
+
* 创建结账订单
|
|
756
|
+
*/
|
|
757
|
+
private createCheckout;
|
|
758
|
+
/**
|
|
759
|
+
* 验证请求参数
|
|
760
|
+
*/
|
|
761
|
+
private validateRequest;
|
|
762
|
+
/**
|
|
763
|
+
* 转换响应数据
|
|
764
|
+
*/
|
|
765
|
+
private transformResponse;
|
|
766
|
+
/**
|
|
767
|
+
* 映射错误代码
|
|
768
|
+
*/
|
|
769
|
+
private mapErrorCode;
|
|
770
|
+
/**
|
|
771
|
+
* 创建支付错误
|
|
772
|
+
*/
|
|
773
|
+
private createError;
|
|
774
|
+
/**
|
|
775
|
+
* 检查是否是支付错误
|
|
776
|
+
*/
|
|
777
|
+
private isPaymentError;
|
|
778
|
+
/**
|
|
779
|
+
* 日志输出
|
|
780
|
+
*/
|
|
781
|
+
private log;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* SeaArtPay SDK 加载器
|
|
786
|
+
* 负责从 CDN 动态加载 SeaArt 支付 SDK
|
|
787
|
+
*/
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* SDK 加载状态
|
|
791
|
+
*/
|
|
792
|
+
type SDKLoadStatus = 'idle' | 'loading' | 'loaded' | 'error';
|
|
793
|
+
/**
|
|
794
|
+
* 加载器配置
|
|
795
|
+
*/
|
|
796
|
+
interface LoaderConfig {
|
|
797
|
+
/** CDN 地址 */
|
|
798
|
+
cdnUrl?: string;
|
|
799
|
+
/** 加载超时时间(毫秒) */
|
|
800
|
+
timeout?: number;
|
|
801
|
+
/** 调试模式 */
|
|
802
|
+
debug?: boolean;
|
|
803
|
+
/** 运行环境 */
|
|
804
|
+
environment?: PaymentEnvironment;
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* SDK 加载器类
|
|
808
|
+
*/
|
|
809
|
+
declare class SeaArtPayLoader {
|
|
810
|
+
private status;
|
|
811
|
+
private sdk;
|
|
812
|
+
private loadPromise;
|
|
813
|
+
private config;
|
|
814
|
+
constructor(config?: LoaderConfig);
|
|
815
|
+
/**
|
|
816
|
+
* 获取当前加载状态
|
|
817
|
+
*/
|
|
818
|
+
getStatus(): SDKLoadStatus;
|
|
819
|
+
/**
|
|
820
|
+
* 检查 SDK 是否已加载
|
|
821
|
+
*/
|
|
822
|
+
isLoaded(): boolean;
|
|
823
|
+
/**
|
|
824
|
+
* 获取 SDK 实例
|
|
825
|
+
*/
|
|
826
|
+
getSDK(): SeaArtPaySDK | null;
|
|
827
|
+
/**
|
|
828
|
+
* 加载 SDK
|
|
829
|
+
*/
|
|
830
|
+
load(): Promise<SeaArtPaySDK>;
|
|
831
|
+
/**
|
|
832
|
+
* 从多个源尝试加载 SDK
|
|
833
|
+
*/
|
|
834
|
+
private loadSDKFromSources;
|
|
835
|
+
/**
|
|
836
|
+
* 动态加载脚本
|
|
837
|
+
*/
|
|
838
|
+
private loadScript;
|
|
839
|
+
/**
|
|
840
|
+
* 提取 SDK 实例
|
|
841
|
+
* 处理 UMD 包装对象的情况
|
|
842
|
+
*/
|
|
843
|
+
private extractSDKInstance;
|
|
844
|
+
/**
|
|
845
|
+
* 验证 SDK 实例是否有效
|
|
846
|
+
*/
|
|
847
|
+
private isValidSDK;
|
|
848
|
+
/**
|
|
849
|
+
* 初始化 SDK
|
|
850
|
+
*/
|
|
851
|
+
private initializeSDK;
|
|
852
|
+
/**
|
|
853
|
+
* 日志输出
|
|
854
|
+
*/
|
|
855
|
+
private log;
|
|
856
|
+
/**
|
|
857
|
+
* 重置加载器
|
|
858
|
+
*/
|
|
859
|
+
reset(): void;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* 获取或创建全局加载器
|
|
863
|
+
*/
|
|
864
|
+
declare function getGlobalLoader(config?: LoaderConfig): SeaArtPayLoader;
|
|
865
|
+
/**
|
|
866
|
+
* 重置全局加载器
|
|
867
|
+
*/
|
|
868
|
+
declare function resetGlobalLoader(): void;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* 工具函数模块
|
|
872
|
+
*/
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* 生成唯一的订单引用号
|
|
876
|
+
* @param prefix 前缀
|
|
877
|
+
* @returns 唯一引用号
|
|
878
|
+
*/
|
|
879
|
+
declare function generateOrderReference(prefix?: string): string;
|
|
880
|
+
/**
|
|
881
|
+
* 将美元金额转换为分
|
|
882
|
+
* @param dollars 美元金额
|
|
883
|
+
* @returns 分
|
|
884
|
+
*/
|
|
885
|
+
declare function dollarsToCents(dollars: number): number;
|
|
886
|
+
/**
|
|
887
|
+
* 将分转换为美元
|
|
888
|
+
* @param cents 分
|
|
889
|
+
* @returns 美元金额
|
|
890
|
+
*/
|
|
891
|
+
declare function centsToDollars(cents: number): number;
|
|
892
|
+
/**
|
|
893
|
+
* 格式化价格显示
|
|
894
|
+
* @param amount 金额(美元)
|
|
895
|
+
* @param currency 货币代码
|
|
896
|
+
* @returns 格式化的价格字符串
|
|
897
|
+
*/
|
|
898
|
+
declare function formatPrice(amount: number, currency?: string): string;
|
|
899
|
+
/**
|
|
900
|
+
* 创建支付错误对象
|
|
901
|
+
* @param code 错误代码
|
|
902
|
+
* @param message 错误消息
|
|
903
|
+
* @param cause 原始错误
|
|
904
|
+
* @returns 支付错误对象
|
|
905
|
+
*/
|
|
906
|
+
declare function createCheckoutPaymentError(code: CheckoutPaymentErrorCode, message: string, cause?: unknown): CheckoutPaymentError;
|
|
907
|
+
/**
|
|
908
|
+
* 检查是否是支付错误
|
|
909
|
+
* @param error 错误对象
|
|
910
|
+
* @returns 是否是支付错误
|
|
911
|
+
*/
|
|
912
|
+
declare function isCheckoutPaymentError(error: unknown): error is CheckoutPaymentError;
|
|
913
|
+
/**
|
|
914
|
+
* 延迟函数
|
|
915
|
+
* @param ms 毫秒
|
|
916
|
+
* @returns Promise
|
|
917
|
+
*/
|
|
918
|
+
declare function delay(ms: number): Promise<void>;
|
|
919
|
+
/**
|
|
920
|
+
* 带超时的 Promise
|
|
921
|
+
* @param promise 原始 Promise
|
|
922
|
+
* @param ms 超时毫秒数
|
|
923
|
+
* @param errorMessage 超时错误消息
|
|
924
|
+
* @returns 带超时的 Promise
|
|
925
|
+
*/
|
|
926
|
+
declare function withTimeout<T>(promise: Promise<T>, ms: number, errorMessage?: string): Promise<T>;
|
|
927
|
+
/**
|
|
928
|
+
* 安全的 JSON 解析
|
|
929
|
+
* @param json JSON 字符串
|
|
930
|
+
* @param defaultValue 默认值
|
|
931
|
+
* @returns 解析结果或默认值
|
|
932
|
+
*/
|
|
933
|
+
declare function safeJsonParse<T>(json: string, defaultValue: T): T;
|
|
934
|
+
/**
|
|
935
|
+
* 检查是否在浏览器环境
|
|
936
|
+
*/
|
|
937
|
+
declare function isBrowser(): boolean;
|
|
938
|
+
/**
|
|
939
|
+
* 获取当前页面 URL
|
|
940
|
+
*/
|
|
941
|
+
declare function getCurrentUrl(): string;
|
|
942
|
+
/**
|
|
943
|
+
* 获取 SDK 支持的 locale
|
|
944
|
+
* @param locale 项目 locale
|
|
945
|
+
* @returns SDK locale
|
|
946
|
+
*/
|
|
947
|
+
declare function getSDKLocale(locale: string): string;
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* SeaVerse Payment SDK - 常量配置
|
|
951
|
+
*/
|
|
952
|
+
|
|
953
|
+
/**
|
|
954
|
+
* 环境配置
|
|
955
|
+
*/
|
|
956
|
+
declare const ENV_CONFIG: Record<PaymentEnvironment, {
|
|
957
|
+
apiHost: string;
|
|
958
|
+
iframeUrl: string;
|
|
959
|
+
}>;
|
|
960
|
+
/**
|
|
961
|
+
* SDK CDN 地址
|
|
962
|
+
*/
|
|
963
|
+
declare const SDK_CDN_URL = "https://image.cdn2.seaart.me/seaart-payment-sdk/1.0.2/seaart-pay-sdk-umd.min.js";
|
|
964
|
+
/**
|
|
965
|
+
* SDK 加载超时时间(毫秒)
|
|
966
|
+
*/
|
|
967
|
+
declare const SDK_LOAD_TIMEOUT = 15000;
|
|
968
|
+
/**
|
|
969
|
+
* SDK 全局对象名称
|
|
970
|
+
*/
|
|
971
|
+
declare const SDK_GLOBAL_NAME = "SeaArtPay";
|
|
972
|
+
/**
|
|
973
|
+
* API 端点
|
|
974
|
+
*/
|
|
975
|
+
declare const API_ENDPOINTS: {
|
|
976
|
+
/** SDK 结账接口 */
|
|
977
|
+
readonly SDK_CHECKOUT: "/api/v1/payment/sdk/checkout";
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* 默认配置
|
|
981
|
+
*/
|
|
982
|
+
declare const DEFAULT_CHECKOUT_CONFIG: {
|
|
983
|
+
readonly environment: PaymentEnvironment;
|
|
984
|
+
readonly debug: false;
|
|
985
|
+
readonly language: "en";
|
|
986
|
+
readonly sdkTimeout: 15000;
|
|
987
|
+
};
|
|
988
|
+
/**
|
|
989
|
+
* HTTP 状态码
|
|
990
|
+
*/
|
|
991
|
+
declare const HTTP_STATUS: {
|
|
992
|
+
readonly OK: 200;
|
|
993
|
+
readonly BAD_REQUEST: 400;
|
|
994
|
+
readonly UNAUTHORIZED: 401;
|
|
995
|
+
readonly FORBIDDEN: 403;
|
|
996
|
+
readonly NOT_FOUND: 404;
|
|
997
|
+
readonly INTERNAL_ERROR: 500;
|
|
998
|
+
};
|
|
999
|
+
/**
|
|
1000
|
+
* 业务状态码
|
|
1001
|
+
*/
|
|
1002
|
+
declare const BIZ_CODE: {
|
|
1003
|
+
readonly SUCCESS: 0;
|
|
1004
|
+
readonly BAD_REQUEST: 400;
|
|
1005
|
+
readonly UNAUTHORIZED: 401;
|
|
1006
|
+
readonly SERVER_ERROR: 500;
|
|
1007
|
+
};
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* @seaverse/payment-sdk
|
|
1011
|
+
*
|
|
1012
|
+
* SeaVerse Payment SDK - Credit management and payment checkout
|
|
1013
|
+
*
|
|
1014
|
+
* This SDK provides two main features:
|
|
1015
|
+
*
|
|
1016
|
+
* ## 1. Credit Query (PaymentClient)
|
|
1017
|
+
* Query user credit accounts and transaction history.
|
|
1018
|
+
*
|
|
1019
|
+
* ```typescript
|
|
1020
|
+
* import { PaymentClient } from '@seaverse/payment-sdk';
|
|
1021
|
+
*
|
|
1022
|
+
* const client = new PaymentClient({
|
|
1023
|
+
* appId: 'seaverse',
|
|
1024
|
+
* token: 'your-bearer-token',
|
|
1025
|
+
* });
|
|
1026
|
+
*
|
|
1027
|
+
* const detail = await client.getCreditDetail();
|
|
1028
|
+
* console.log(`Total Balance: ${detail.total_balance}`);
|
|
1029
|
+
* ```
|
|
1030
|
+
*
|
|
1031
|
+
* ## 2. Payment Checkout (PaymentCheckoutClient)
|
|
1032
|
+
* Show payment modal for one-time purchases and subscriptions.
|
|
1033
|
+
*
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* import { PaymentCheckoutClient } from '@seaverse/payment-sdk';
|
|
1036
|
+
*
|
|
1037
|
+
* const checkoutClient = new PaymentCheckoutClient({
|
|
1038
|
+
* apiHost: 'https://payment.sg.seaverse.dev',
|
|
1039
|
+
* authToken: 'your-jwt-token',
|
|
1040
|
+
* environment: 'develop',
|
|
1041
|
+
* });
|
|
1042
|
+
*
|
|
1043
|
+
* await checkoutClient.init();
|
|
1044
|
+
*
|
|
1045
|
+
* await checkoutClient.checkout({
|
|
1046
|
+
* productId: 'pkg_starter',
|
|
1047
|
+
* onSuccess: (res) => console.log('Payment success:', res),
|
|
1048
|
+
* });
|
|
1049
|
+
* ```
|
|
1050
|
+
*/
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
* SDK version
|
|
1054
|
+
*/
|
|
1055
|
+
declare const VERSION = "0.1.0";
|
|
1056
|
+
|
|
1057
|
+
export { API_ENDPOINTS, BIZ_CODE, CheckoutAPI, DEFAULT_CHECKOUT_CONFIG, ENV_CONFIG, HTTP_STATUS, PaymentAPIError, PaymentCheckoutClient, PaymentClient, SDK_CDN_URL, SDK_GLOBAL_NAME, SDK_LOAD_TIMEOUT, SeaArtPayLoader, VERSION, centsToDollars, createCheckoutPaymentError, delay, dollarsToCents, formatPrice, generateOrderReference, getCurrentUrl, getGlobalLoader, getSDKLocale, isBrowser, isCheckoutPaymentError, resetGlobalLoader, safeJsonParse, withTimeout };
|
|
1058
|
+
export type { ApiErrorResponse, ApiResponse, ApiSuccessResponse, BaseCheckoutOptions, CheckoutAPIConfig, CheckoutAPIResponse, CheckoutClientConfig, CheckoutClientStatus, CheckoutOptions, CheckoutPaymentError, CheckoutPaymentErrorCode, CheckoutResult, CreditAccount, CreditAccountStatus, CreditDetailResponse, CreditDetailSuccessResponse, CreditPoolDetail, CreditPoolType, CreditTransaction, ListTransactionsRequest, LoaderConfig, PaymentClientOptions, PaymentEnvironment, PaymentResult, PaymentUnsuccessResult, PurchaseType, SDKCheckoutRequest, SDKCheckoutResponse, SDKConfig, SDKLoadStatus, SeaArtPaySDK, ShowPaymentOptions, SubscribeOptions, SubscriptionParams, SubscriptionPeriod, TransactionListResponse, TransactionStatus, TransactionType };
|