@seaverse/payment-sdk 0.3.1 → 0.4.1
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 +72 -13
- package/dist/index.browser.js +84 -3956
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +58 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +29 -7
- package/dist/index.js +58 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -349,10 +349,10 @@ declare class PaymentClient {
|
|
|
349
349
|
*/
|
|
350
350
|
/**
|
|
351
351
|
* 支付环境
|
|
352
|
-
* -
|
|
353
|
-
* -
|
|
352
|
+
* - develop: 开发/测试环境
|
|
353
|
+
* - release: 生产环境
|
|
354
354
|
*/
|
|
355
|
-
type PaymentEnvironment = '
|
|
355
|
+
type PaymentEnvironment = 'develop' | 'release';
|
|
356
356
|
/**
|
|
357
357
|
* 支付弹窗客户端配置
|
|
358
358
|
*/
|
|
@@ -425,6 +425,8 @@ interface BaseCheckoutOptions {
|
|
|
425
425
|
language?: string;
|
|
426
426
|
/** 用户名(显示用) */
|
|
427
427
|
userName?: string;
|
|
428
|
+
/** 支付完成后的重定向 URL(可选,用于支付成功后跳转) */
|
|
429
|
+
redirectUrl?: string;
|
|
428
430
|
}
|
|
429
431
|
/**
|
|
430
432
|
* 一次性购买选项
|
|
@@ -483,6 +485,8 @@ interface SDKCheckoutRequest {
|
|
|
483
485
|
subscription?: SubscriptionParams;
|
|
484
486
|
/** 额外数据 */
|
|
485
487
|
extra?: Record<string, unknown>;
|
|
488
|
+
/** 支付完成后的重定向 URL(可选) */
|
|
489
|
+
redirect_url?: string;
|
|
486
490
|
}
|
|
487
491
|
/**
|
|
488
492
|
* SDK 结账响应
|
|
@@ -496,6 +500,8 @@ interface SDKCheckoutResponse {
|
|
|
496
500
|
price: number;
|
|
497
501
|
/** 货币代码 */
|
|
498
502
|
currency: string;
|
|
503
|
+
/** 支付完成后的跳转 URL(SDK 调用方应在支付完成后跳转到此 URL) */
|
|
504
|
+
redirect_url: string;
|
|
499
505
|
/** SDK 初始化配置 */
|
|
500
506
|
sdk_config: {
|
|
501
507
|
app_id: string;
|
|
@@ -526,6 +532,8 @@ interface CheckoutResult {
|
|
|
526
532
|
price: number;
|
|
527
533
|
/** 货币代码 */
|
|
528
534
|
currency: string;
|
|
535
|
+
/** 支付完成后的跳转 URL */
|
|
536
|
+
redirectUrl: string;
|
|
529
537
|
/** SDK 配置 */
|
|
530
538
|
sdkConfig: SDKConfig;
|
|
531
539
|
}
|
|
@@ -563,6 +571,8 @@ interface CheckoutPaymentError {
|
|
|
563
571
|
code: CheckoutPaymentErrorCode;
|
|
564
572
|
/** 错误消息 */
|
|
565
573
|
message: string;
|
|
574
|
+
/** 业务错误码(来自后端 API) */
|
|
575
|
+
bizCode?: number;
|
|
566
576
|
/** 原始错误 */
|
|
567
577
|
cause?: unknown;
|
|
568
578
|
}
|
|
@@ -642,7 +652,7 @@ type CheckoutClientStatus = 'idle' | 'initializing' | 'ready' | 'error';
|
|
|
642
652
|
* const checkoutClient = new PaymentCheckoutClient({
|
|
643
653
|
* apiHost: 'https://payment.sg.seaverse.dev',
|
|
644
654
|
* authToken: 'your-jwt-token',
|
|
645
|
-
* environment: '
|
|
655
|
+
* environment: 'develop',
|
|
646
656
|
* debug: true,
|
|
647
657
|
* });
|
|
648
658
|
*
|
|
@@ -706,6 +716,7 @@ declare class PaymentCheckoutClient {
|
|
|
706
716
|
*/
|
|
707
717
|
getEnvironmentConfig(): {
|
|
708
718
|
apiHost: string;
|
|
719
|
+
iframeUrl: string;
|
|
709
720
|
};
|
|
710
721
|
/**
|
|
711
722
|
* 确保客户端已就绪
|
|
@@ -760,6 +771,8 @@ declare class CheckoutAPI {
|
|
|
760
771
|
productName?: string;
|
|
761
772
|
price?: number;
|
|
762
773
|
extra?: Record<string, unknown>;
|
|
774
|
+
/** 支付完成后的重定向 URL */
|
|
775
|
+
redirectUrl?: string;
|
|
763
776
|
}): Promise<CheckoutResult>;
|
|
764
777
|
/**
|
|
765
778
|
* 创建订阅订单
|
|
@@ -770,6 +783,8 @@ declare class CheckoutAPI {
|
|
|
770
783
|
price?: number;
|
|
771
784
|
subscription: SubscriptionParams;
|
|
772
785
|
extra?: Record<string, unknown>;
|
|
786
|
+
/** 支付完成后的重定向 URL */
|
|
787
|
+
redirectUrl?: string;
|
|
773
788
|
}): Promise<CheckoutResult>;
|
|
774
789
|
/**
|
|
775
790
|
* 创建结账订单
|
|
@@ -973,18 +988,17 @@ declare function getSDKLocale(locale: string): string;
|
|
|
973
988
|
|
|
974
989
|
/**
|
|
975
990
|
* 环境配置
|
|
976
|
-
* - development: 开发/测试环境
|
|
977
|
-
* - production: 生产环境
|
|
978
991
|
*/
|
|
979
992
|
declare const ENV_CONFIG: Record<PaymentEnvironment, {
|
|
980
993
|
apiHost: string;
|
|
994
|
+
iframeUrl: string;
|
|
981
995
|
}>;
|
|
982
996
|
/**
|
|
983
997
|
* Web Component 加载超时时间(毫秒)
|
|
984
998
|
*/
|
|
985
999
|
declare const COMPONENT_LOAD_TIMEOUT = 15000;
|
|
986
1000
|
/**
|
|
987
|
-
* Web Component
|
|
1001
|
+
* Web Component 元素名称
|
|
988
1002
|
*/
|
|
989
1003
|
declare const PAYMENT_ELEMENT_NAME = "seaart-payment";
|
|
990
1004
|
/**
|
|
@@ -1001,6 +1015,8 @@ declare const DEFAULT_CHECKOUT_CONFIG: {
|
|
|
1001
1015
|
readonly environment: PaymentEnvironment;
|
|
1002
1016
|
readonly debug: false;
|
|
1003
1017
|
readonly language: "en";
|
|
1018
|
+
/** @deprecated 使用 componentTimeout 替代 */
|
|
1019
|
+
readonly sdkTimeout: 15000;
|
|
1004
1020
|
readonly componentTimeout: 15000;
|
|
1005
1021
|
};
|
|
1006
1022
|
/**
|
|
@@ -1022,6 +1038,12 @@ declare const BIZ_CODE: {
|
|
|
1022
1038
|
readonly BAD_REQUEST: 400;
|
|
1023
1039
|
readonly UNAUTHORIZED: 401;
|
|
1024
1040
|
readonly SERVER_ERROR: 500;
|
|
1041
|
+
readonly DAILY_LIMIT_EXCEEDED: 4001;
|
|
1042
|
+
readonly PRODUCT_NOT_FOUND: 4002;
|
|
1043
|
+
readonly PRODUCT_DISABLED: 4003;
|
|
1044
|
+
readonly INSUFFICIENT_BALANCE: 4004;
|
|
1045
|
+
readonly ORDER_NOT_FOUND: 4005;
|
|
1046
|
+
readonly INVALID_ORDER_STATUS: 4006;
|
|
1025
1047
|
};
|
|
1026
1048
|
|
|
1027
1049
|
/**
|
package/dist/index.js
CHANGED
|
@@ -231,23 +231,28 @@ class PaymentClient {
|
|
|
231
231
|
*/
|
|
232
232
|
/**
|
|
233
233
|
* 环境配置
|
|
234
|
-
* - development: 开发/测试环境
|
|
235
|
-
* - production: 生产环境
|
|
236
234
|
*/
|
|
237
235
|
const ENV_CONFIG = {
|
|
238
|
-
|
|
236
|
+
develop: {
|
|
239
237
|
apiHost: 'https://aiart-openresty.dev.seaart.dev',
|
|
238
|
+
iframeUrl: 'https://aiart-payment-page.dev.seaart.dev',
|
|
240
239
|
},
|
|
241
|
-
|
|
240
|
+
release: {
|
|
242
241
|
apiHost: 'https://www.seaart.ai',
|
|
242
|
+
iframeUrl: 'https://pay.seaart.ai',
|
|
243
243
|
},
|
|
244
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* SDK 加载超时时间(毫秒)
|
|
247
|
+
* @deprecated 使用 COMPONENT_LOAD_TIMEOUT 替代
|
|
248
|
+
*/
|
|
249
|
+
const SDK_LOAD_TIMEOUT = 15000;
|
|
245
250
|
/**
|
|
246
251
|
* Web Component 加载超时时间(毫秒)
|
|
247
252
|
*/
|
|
248
253
|
const COMPONENT_LOAD_TIMEOUT = 15000;
|
|
249
254
|
/**
|
|
250
|
-
* Web Component
|
|
255
|
+
* Web Component 元素名称
|
|
251
256
|
*/
|
|
252
257
|
const PAYMENT_ELEMENT_NAME = 'seaart-payment';
|
|
253
258
|
/**
|
|
@@ -261,9 +266,11 @@ const API_ENDPOINTS$1 = {
|
|
|
261
266
|
* 默认配置
|
|
262
267
|
*/
|
|
263
268
|
const DEFAULT_CHECKOUT_CONFIG = {
|
|
264
|
-
environment: '
|
|
269
|
+
environment: 'develop',
|
|
265
270
|
debug: false,
|
|
266
271
|
language: 'en',
|
|
272
|
+
/** @deprecated 使用 componentTimeout 替代 */
|
|
273
|
+
sdkTimeout: SDK_LOAD_TIMEOUT,
|
|
267
274
|
componentTimeout: COMPONENT_LOAD_TIMEOUT,
|
|
268
275
|
};
|
|
269
276
|
/**
|
|
@@ -285,6 +292,13 @@ const BIZ_CODE = {
|
|
|
285
292
|
BAD_REQUEST: 400,
|
|
286
293
|
UNAUTHORIZED: 401,
|
|
287
294
|
SERVER_ERROR: 500,
|
|
295
|
+
// 业务错误码 (4001-4006)
|
|
296
|
+
DAILY_LIMIT_EXCEEDED: 4001,
|
|
297
|
+
PRODUCT_NOT_FOUND: 4002,
|
|
298
|
+
PRODUCT_DISABLED: 4003,
|
|
299
|
+
INSUFFICIENT_BALANCE: 4004,
|
|
300
|
+
ORDER_NOT_FOUND: 4005,
|
|
301
|
+
INVALID_ORDER_STATUS: 4006,
|
|
288
302
|
};
|
|
289
303
|
|
|
290
304
|
/**
|
|
@@ -306,7 +320,7 @@ class SeaArtPayLoader {
|
|
|
306
320
|
this.config = {
|
|
307
321
|
timeout: config.timeout ?? COMPONENT_LOAD_TIMEOUT,
|
|
308
322
|
debug: config.debug ?? false,
|
|
309
|
-
environment: config.environment ?? '
|
|
323
|
+
environment: config.environment ?? 'develop',
|
|
310
324
|
};
|
|
311
325
|
}
|
|
312
326
|
/**
|
|
@@ -395,19 +409,17 @@ class SeaArtPayLoader {
|
|
|
395
409
|
*/
|
|
396
410
|
async loadComponent() {
|
|
397
411
|
try {
|
|
398
|
-
//
|
|
399
|
-
//
|
|
400
|
-
await Promise.resolve().then(function () { return
|
|
412
|
+
// 动态导入内部打包的 Web Component
|
|
413
|
+
// Web Component 已经打包在 SDK 中,用户无需单独安装
|
|
414
|
+
await Promise.resolve().then(function () { return componentBundle; });
|
|
401
415
|
this.log('模块导入成功');
|
|
402
416
|
// 等待自定义元素注册完成
|
|
403
417
|
await this.waitForElementDefined();
|
|
404
418
|
this.log('自定义元素注册完成');
|
|
405
419
|
}
|
|
406
420
|
catch (error) {
|
|
407
|
-
// 如果动态导入失败,可能是消费方没有安装依赖
|
|
408
421
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
409
|
-
throw new Error(`无法加载
|
|
410
|
-
'请确保已安装依赖: npm install @seaart/payment-component');
|
|
422
|
+
throw new Error(`无法加载 Web Component: ${errorMessage}`);
|
|
411
423
|
}
|
|
412
424
|
}
|
|
413
425
|
/**
|
|
@@ -487,6 +499,7 @@ class CheckoutAPI {
|
|
|
487
499
|
price: params.price,
|
|
488
500
|
purchase_type: 1,
|
|
489
501
|
extra: params.extra,
|
|
502
|
+
redirect_url: params.redirectUrl,
|
|
490
503
|
});
|
|
491
504
|
}
|
|
492
505
|
/**
|
|
@@ -500,6 +513,7 @@ class CheckoutAPI {
|
|
|
500
513
|
purchase_type: 2,
|
|
501
514
|
subscription: params.subscription,
|
|
502
515
|
extra: params.extra,
|
|
516
|
+
redirect_url: params.redirectUrl,
|
|
503
517
|
});
|
|
504
518
|
}
|
|
505
519
|
/**
|
|
@@ -525,7 +539,8 @@ class CheckoutAPI {
|
|
|
525
539
|
const data = await response.json();
|
|
526
540
|
this.log('结账响应:', data);
|
|
527
541
|
if (data.code !== BIZ_CODE.SUCCESS) {
|
|
528
|
-
throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败'
|
|
542
|
+
throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败', undefined, data.code // 传递原始业务错误码
|
|
543
|
+
);
|
|
529
544
|
}
|
|
530
545
|
if (!data.data) {
|
|
531
546
|
throw this.createError('CHECKOUT_FAILED', '结账响应数据为空');
|
|
@@ -575,6 +590,7 @@ class CheckoutAPI {
|
|
|
575
590
|
transactionId: response.transaction_id,
|
|
576
591
|
price: response.price,
|
|
577
592
|
currency: response.currency,
|
|
593
|
+
redirectUrl: response.redirect_url,
|
|
578
594
|
sdkConfig: {
|
|
579
595
|
appId: response.sdk_config.app_id,
|
|
580
596
|
apiHost: response.sdk_config.api_host,
|
|
@@ -593,6 +609,14 @@ class CheckoutAPI {
|
|
|
593
609
|
return 'UNAUTHORIZED';
|
|
594
610
|
case BIZ_CODE.SERVER_ERROR:
|
|
595
611
|
return 'API_ERROR';
|
|
612
|
+
// 业务错误码统一映射为 CHECKOUT_FAILED,通过 bizCode 区分具体原因
|
|
613
|
+
case BIZ_CODE.DAILY_LIMIT_EXCEEDED:
|
|
614
|
+
case BIZ_CODE.PRODUCT_NOT_FOUND:
|
|
615
|
+
case BIZ_CODE.PRODUCT_DISABLED:
|
|
616
|
+
case BIZ_CODE.INSUFFICIENT_BALANCE:
|
|
617
|
+
case BIZ_CODE.ORDER_NOT_FOUND:
|
|
618
|
+
case BIZ_CODE.INVALID_ORDER_STATUS:
|
|
619
|
+
return 'CHECKOUT_FAILED';
|
|
596
620
|
default:
|
|
597
621
|
return 'CHECKOUT_FAILED';
|
|
598
622
|
}
|
|
@@ -600,8 +624,8 @@ class CheckoutAPI {
|
|
|
600
624
|
/**
|
|
601
625
|
* 创建支付错误
|
|
602
626
|
*/
|
|
603
|
-
createError(code, message, cause) {
|
|
604
|
-
return { code, message, cause };
|
|
627
|
+
createError(code, message, cause, bizCode) {
|
|
628
|
+
return { code, message, cause, bizCode };
|
|
605
629
|
}
|
|
606
630
|
/**
|
|
607
631
|
* 检查是否是支付错误
|
|
@@ -643,7 +667,7 @@ class CheckoutAPI {
|
|
|
643
667
|
* const checkoutClient = new PaymentCheckoutClient({
|
|
644
668
|
* apiHost: 'https://payment.sg.seaverse.dev',
|
|
645
669
|
* authToken: 'your-jwt-token',
|
|
646
|
-
* environment: '
|
|
670
|
+
* environment: 'develop',
|
|
647
671
|
* debug: true,
|
|
648
672
|
* });
|
|
649
673
|
*
|
|
@@ -749,6 +773,7 @@ class PaymentCheckoutClient {
|
|
|
749
773
|
productName: options.productName,
|
|
750
774
|
price: options.price,
|
|
751
775
|
extra: options.extra,
|
|
776
|
+
redirectUrl: options.redirectUrl,
|
|
752
777
|
});
|
|
753
778
|
// 自动打开支付弹窗
|
|
754
779
|
this.showPaymentModal({
|
|
@@ -790,6 +815,7 @@ class PaymentCheckoutClient {
|
|
|
790
815
|
firstDays: options.firstDays ?? 0,
|
|
791
816
|
},
|
|
792
817
|
extra: options.extra,
|
|
818
|
+
redirectUrl: options.redirectUrl,
|
|
793
819
|
});
|
|
794
820
|
// 自动打开支付弹窗
|
|
795
821
|
this.showPaymentModal({
|
|
@@ -866,6 +892,7 @@ class PaymentCheckoutClient {
|
|
|
866
892
|
payment.setAttribute('transaction-id', options.transactionId);
|
|
867
893
|
payment.setAttribute('environment', this.config.environment);
|
|
868
894
|
payment.setAttribute('language', options.language ?? DEFAULT_CHECKOUT_CONFIG.language);
|
|
895
|
+
payment.setAttribute('api-host', this.config.apiHost);
|
|
869
896
|
// 设置可选属性
|
|
870
897
|
if (options.userName) {
|
|
871
898
|
payment.setAttribute('user-name', options.userName);
|
|
@@ -17989,9 +18016,20 @@ if (typeof window !== "undefined" && !customElements.get("seaart-payment")) {
|
|
|
17989
18016
|
customElements.define("seaart-payment", SeaArtPayment);
|
|
17990
18017
|
}
|
|
17991
18018
|
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
18019
|
+
/**
|
|
18020
|
+
* Internal module: SeaArt Payment Component Bundle
|
|
18021
|
+
*
|
|
18022
|
+
* This module re-exports @seaart/payment-component for internal bundling.
|
|
18023
|
+
* End users don't need to install @seaart/payment-component separately -
|
|
18024
|
+
* it's bundled into the SDK during the build process.
|
|
18025
|
+
*
|
|
18026
|
+
* @internal
|
|
18027
|
+
*/
|
|
18028
|
+
// Import and register the Web Component
|
|
18029
|
+
// This side-effect will register <seaart-payment> custom element
|
|
18030
|
+
|
|
18031
|
+
var componentBundle = /*#__PURE__*/Object.freeze({
|
|
18032
|
+
__proto__: null
|
|
17995
18033
|
});
|
|
17996
18034
|
|
|
17997
18035
|
var __defProp = Object.defineProperty;
|