@seaverse/payment-sdk 0.4.0 → 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/dist/index.d.ts CHANGED
@@ -571,6 +571,8 @@ interface CheckoutPaymentError {
571
571
  code: CheckoutPaymentErrorCode;
572
572
  /** 错误消息 */
573
573
  message: string;
574
+ /** 业务错误码(来自后端 API) */
575
+ bizCode?: number;
574
576
  /** 原始错误 */
575
577
  cause?: unknown;
576
578
  }
@@ -1036,6 +1038,12 @@ declare const BIZ_CODE: {
1036
1038
  readonly BAD_REQUEST: 400;
1037
1039
  readonly UNAUTHORIZED: 401;
1038
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;
1039
1047
  };
1040
1048
 
1041
1049
  /**
package/dist/index.js CHANGED
@@ -292,6 +292,13 @@ const BIZ_CODE = {
292
292
  BAD_REQUEST: 400,
293
293
  UNAUTHORIZED: 401,
294
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,
295
302
  };
296
303
 
297
304
  /**
@@ -402,19 +409,17 @@ class SeaArtPayLoader {
402
409
  */
403
410
  async loadComponent() {
404
411
  try {
405
- // 动态导入 @seaart/payment-component
406
- // 注意:消费方需要在项目中安装此依赖
407
- await Promise.resolve().then(function () { return seaartPayment; });
412
+ // 动态导入内部打包的 Web Component
413
+ // Web Component 已经打包在 SDK 中,用户无需单独安装
414
+ await Promise.resolve().then(function () { return componentBundle; });
408
415
  this.log('模块导入成功');
409
416
  // 等待自定义元素注册完成
410
417
  await this.waitForElementDefined();
411
418
  this.log('自定义元素注册完成');
412
419
  }
413
420
  catch (error) {
414
- // 如果动态导入失败,可能是消费方没有安装依赖
415
421
  const errorMessage = error instanceof Error ? error.message : String(error);
416
- throw new Error(`无法加载 @seaart/payment-component: ${errorMessage}\n` +
417
- '请确保已安装依赖: npm install @seaart/payment-component');
422
+ throw new Error(`无法加载 Web Component: ${errorMessage}`);
418
423
  }
419
424
  }
420
425
  /**
@@ -534,7 +539,8 @@ class CheckoutAPI {
534
539
  const data = await response.json();
535
540
  this.log('结账响应:', data);
536
541
  if (data.code !== BIZ_CODE.SUCCESS) {
537
- throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败');
542
+ throw this.createError(this.mapErrorCode(data.code), data.msg || '结账失败', undefined, data.code // 传递原始业务错误码
543
+ );
538
544
  }
539
545
  if (!data.data) {
540
546
  throw this.createError('CHECKOUT_FAILED', '结账响应数据为空');
@@ -603,6 +609,14 @@ class CheckoutAPI {
603
609
  return 'UNAUTHORIZED';
604
610
  case BIZ_CODE.SERVER_ERROR:
605
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';
606
620
  default:
607
621
  return 'CHECKOUT_FAILED';
608
622
  }
@@ -610,8 +624,8 @@ class CheckoutAPI {
610
624
  /**
611
625
  * 创建支付错误
612
626
  */
613
- createError(code, message, cause) {
614
- return { code, message, cause };
627
+ createError(code, message, cause, bizCode) {
628
+ return { code, message, cause, bizCode };
615
629
  }
616
630
  /**
617
631
  * 检查是否是支付错误
@@ -878,6 +892,7 @@ class PaymentCheckoutClient {
878
892
  payment.setAttribute('transaction-id', options.transactionId);
879
893
  payment.setAttribute('environment', this.config.environment);
880
894
  payment.setAttribute('language', options.language ?? DEFAULT_CHECKOUT_CONFIG.language);
895
+ payment.setAttribute('api-host', this.config.apiHost);
881
896
  // 设置可选属性
882
897
  if (options.userName) {
883
898
  payment.setAttribute('user-name', options.userName);
@@ -18001,9 +18016,20 @@ if (typeof window !== "undefined" && !customElements.get("seaart-payment")) {
18001
18016
  customElements.define("seaart-payment", SeaArtPayment);
18002
18017
  }
18003
18018
 
18004
- var seaartPayment = /*#__PURE__*/Object.freeze({
18005
- __proto__: null,
18006
- default: SeaArtPayment
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
18007
18033
  });
18008
18034
 
18009
18035
  var __defProp = Object.defineProperty;